Coder Social home page Coder Social logo

shelly-script-examples's People

Contributors

cyberline avatar dzhuneyt avatar enesbcs avatar eurich avatar fiws avatar frspp avatar jpettitt avatar kzyapkov avatar letreguilly avatar lpetrov avatar mircho avatar paulomorgado avatar pytekmobile avatar ricksbrown avatar sdrsdr avatar taulfsime avatar tscofield avatar ztec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shelly-script-examples's Issues

Domoticz out mqtt from switch

Hi,

domoticz send mqtt message:

{
"Battery" : 255,
"LastUpdate" : "2024-01-07 15:39:07",
"RSSI" : 12,
"description" : "",
"dtype" : "Light/Switch",
"hwid" : "28",
"id" : "000144F4",
"idx" : 69,
"name" : "SHPLG-S Ventilator - SW",
"nvalue" : 0,
"org_hwid" : "28",
"stype" : "Switch",
"switchType" : "On/Off",
"unit" : 1
}

and Shelly receive error:

ControlHandler - error: "Invalid UTF-8 string"

in function:

MQTT.subscribe("shellies/out_Shelly/" + JSON.stringify(deviceDomoticzSW), switchDomoticzControlHandler_shellies);

console.log("ControlHandler_shellies: ", JSON.stringify(message));

after error shelly restarts.

I run in latest fw domoticz and shelies.

thx

Outbound websocket example: publisher/subscriber to provide a working starting point?

https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Ws shows it's possible to create outbound websockets from scripts. Cool.

But all it provides in terms of showing how to communicate is this:

The Outbound Websocket component uses ws as RPC namespace and provides the methods:

There's only one very vague example in this repo:

function emitOverWs(measurement) {
  Shelly.emitEvent(CONFIG.event_name, measurement);
}

function emitOverWs(measurement) {

Can I just start listening for incoming data using Shelly.addEventHandler()?

Why not create a typical "publisher/subscriber" example, combined with a HTTPServer? The publisher sends an event over the websocket to the subscriber, and the subscriber sets the received value in KVS. That way, there's no dependency on external components and it'd provide a great starting point to connect other devices.

Thanks for considering! 😊

Script Request: iBeacon Scanner

Hi, I really appreciate new script and BLE features. I spent many hours to scan / recognize my iBeacon via Shelly. I was not able to find / recognize my iBeacon in scan result. Scan process is running well, I receive many advertisements, but no one seems to match my iBeacon.

Please, could you add an example, where the uuid from iBeacon is readable in clear text? Usually, the uuid is hex coded, therefore the missing String part in mJS should not influence this task.

Thank you, in any case for your work.

Router_watchdog only execute one cycle

Trying the script on a Plus 1 with firmware 20230308-091529/0.14.1-g22a4cb7.
For test purposes I entered two addresses, that fails when doing the GET....
I left the CONFIG.numberOfFails as the example: 3
After third failed GET, the relay toggles alright but it seems the eventhandler is not working, because the function pingEndpoints isn't executed again.
This is the log:

Failed to fetch https://youseee.dk
Rotating through endpoints
Too many fails, resetting...
shelly_timer_script_:73 JS_Timer 0x3ffd9360 is gone
mg_rpc.c:314 Switch.Set via loopback
shelly_notification:161 Status change of switch:0: {"id":0,"output":false,"source":"loopback","timer_duration":30.00,"timer_started_at":1680713946.03}
shelly_notification:161 Status change of switch:0: {"id":0,"output":true,"source":"timer","timer_duration":null,"timer_started_at":null}

Btw: Although the description says the script relies on ping'ing, the GET is successful also when the server does not respond to pings. Is the functionality rather depending on successful name server lookup?

ble-shelly-btn.js missing Shelly.call

Don't know if it's just me, but couldn't get the script to toggle the relay.

I had to add the following to get it to work.

Shelly.call("Switch.toggle", { id: 0});

ble-pasv-mqtt-gw.js - Add other measures of XIAOMI MIFLORA

Is your feature request related to a problem? Please describe.

I use ble-pasv-mqtt-gw.js for Xiaomi device like Xiaomi Lywsd03 and I was surprise me when show me up other equipment . The script show me a temperature of my Xiaomi MIFLora with this payload on path :

shellies/blegateway/c99c9d9999ca/temperature
with json
{"temperature":18.4,"rssi":-78}

Describe the solution you'd like
How can help you to integrate other attributes of this device, like :

  • battery
  • moisture
  • sunlight
  • fertility
  • firmware

router-watchdog.js not working

Hello,
I am trying to use router-watchdog to ping local web server (Home Assistant in this case). My knowledge of js/C/C++ is very limited...

First issue:
Error code of unresponding server I am getting is -104, not -114 as in example from library. Wouldn't be better to check if response is anything but 0?
Edit: It looks like -114 is for connection refused, -104 is for regular timeout/no response.

Second issue:
Watchdog is not restarted after switch is toggled off and on. I'm trying to figure this one out, but so far no luck.
This condition is never true in my testing:

  if (
    event.name === "switch" &&
    event.info.source === "timer" &&
    event.info.output === false
  ) {

mqtt-discovery update never arrives

With Shelly1 Plus firmware 0.10.3, using mqtt-discovery.js and commands works through mqtt, but status never arrives about changed state.

Replaced

Shelly.addEventHandler(function (ev_data) { ...

block to

Shelly.addStatusHandler(function (notification) { ...

from mqtt-switch-status.js and now status reporting works finally.

Script request: HTTPServer

I am struggling with how to use the HTTPServer and would love to see your take on it. Could you maybe add a script using the HTTPServer? So far it seems the only feature not represented in this extensive and helpful script collection.

Anyway, thanks for the awesome work so far, its a lot of fun to check it out!

Shelly WiFi Button gateway example

I have a Shelly Plus Plug US and a Shelly WiFi Button, and the ble Shelly button gateway example looks like almost exactly what I want but for a bluetooth button.

Essentially my goal is for my WiFi button to hit an endpoint that's https but I see that thw WiFi button doesn't really support encrypted web traffic.

So Using the plug as a gateway sounds like the next best thing, but the ble example is quite specifically ble and I don't know how I'd do the same for a WiFi button.

Pass user data for Script.Start

Is your feature request related to a problem? Please describe.
I want to create a script for various ways to start "Shelly Plug S," and in the code, I use a switch/case that sets these different startup modes. Then, I want to trigger these modes using RPC from "Shelly Button," but I don't know how to add a parameter that the script would read as an input parameter.

Describe the solution you'd like
I want to be able to add "data" to the RPC call "Script.Start." For example: http://ip/rpc/Script.Start?id=2&data={"key":"value"}.

My code:

function start(mode) {
  try {
    switch(mode) {
      case 'tap1': {
        function fn_1() {
          Shelly.call('Switch.SetConfig', {
            'id':0,
            'config':{
              'auto_on':false,
              'auto_off':true,
              'auto_on_delay':60,
              'auto_off_delay':3600
            }
          }, fn_2);
        }

        function fn_2() {
          Shelly.call('PLUGS_UI.SetConfig', {
            'config':{
              'leds':{
                'colors':{
                  'power':{
                    'brightness':100
                  },
                  'switch:0':{
                    'on':{
                      'rgb':[0, 100, 0],
                      'brightness':100
                    },
                    'off':{
                      'rgb':[0, 0, 0],
                      'brightness':0
                    }
                  }
                }
              }
            }
          }, fn_3);
        }

        function fn_3() {
          Shelly.call('Switch.Toggle', {
            'id':0
          }, stop);
        }

        fn_1();
        break;
      }
      case 'tap2': {
        function fn_1() {
          Shelly.call('Switch.SetConfig', {
            'id':0,
            'config':{
              'auto_on':false,
              'auto_off':true,
              'auto_on_delay':60,
              'auto_off_delay':5400
            }
          }, fn_2);
        }

        function fn_2() {
          Shelly.call('PLUGS_UI.SetConfig', {
            'config':{
              'leds':{
                'colors':{
                  'power':{
                    'brightness':100
                  },
                  'switch:0':{
                    'on':{
                      'rgb':[100, 100, 0],
                      'brightness':100
                    },
                    'off':{
                      'rgb':[0, 0, 0],
                      'brightness':0
                    }
                  }
                }
              }
            }
          }, fn_3);
        }

        function fn_3() {
          Shelly.call('Switch.Set', {
            'id':0,
            'on':true
          }, stop);
        }

        fn_1();
        break;
      }
      case 'tap3': {
        function fn_1() {
          Shelly.call('Switch.SetConfig', {
            'id':0,
            'config':{
              'auto_on':false,
              'auto_off':true,
              'auto_on_delay':60,
              'auto_off_delay':7200
            }
          }, fn_2);
        }

        function fn_2() {
          Shelly.call('PLUGS_UI.SetConfig', {
            'config':{
              'leds':{
                'colors':{
                  'power':{
                    'brightness':100
                  },
                  'switch:0':{
                    'on':{
                      'rgb':[100, 0, 0],
                      'brightness':100
                    },
                    'off':{
                      'rgb':[0, 0, 0],
                      'brightness':0
                    }
                  }
                }
              }
            }
          }, fn_3);
        }

        function fn_3() {
          Shelly.call('Switch.Set', {
            'id':0,
            'on':true
          }, stop);
        }

        fn_1();
        break;
      }
      case 'hold': {
        function fn_1() {
          Shelly.call('Switch.SetConfig', {
            'id':0,
            'config':{
              'auto_on':false,
              'auto_off':false,
              'auto_on_delay':60,
              'auto_off_delay':60
            }
          }, fn_2);
        }

        function fn_2() {
          Shelly.call('PLUGS_UI.SetConfig', {
            'config':{
              'leds':{
                'colors':{
                  'power':{
                    'brightness':100
                  },
                  'switch:0':{
                    'on':{
                      'rgb':[0, 0, 100],
                      'brightness':100
                    },
                    'off':{
                      'rgb':[0, 0, 0],
                      'brightness':0
                    }
                  }
                }
              }
            }
          }, fn_3);
        }

        function fn_3() {
          Shelly.call('Switch.Set', {
            'id':0,
            'on':true
          }, stop);
        }

        fn_1();
        break;
      }
      default: {
        function fn_1() {
          Shelly.call('Switch.SetConfig', {
            'id':0,
            'config':{
              'auto_on':false,
              'auto_off':false,
              'auto_on_delay':60,
              'auto_off_delay':60
            }
          }, fn_2);
        }

        function fn_2() {
          Shelly.call('PLUGS_UI.SetConfig', {
            'config':{
              'leds':{
                'colors':{
                  'power':{
                    'brightness':100
                  },
                  'switch:0':{
                    'on':{
                      'rgb':[0, 0, 100],
                      'brightness':100
                    },
                    'off':{
                      'rgb':[0, 0, 0],
                      'brightness':0
                    }
                  }
                }
              }
            }
          }, fn_3);
        }

        function fn_3() {
          Shelly.call('Switch.Set', {
            'id':0,
            'on':false
          }, stop);
        }

        fn_1();
        break;
      }
    }
  } catch(e) {
    stop();
  }
}

function stop() {
  Shelly.call('Script.Stop', {
    'id':Shelly.getCurrentScriptId()
  });
}

start('tap1'); //for example with user data for Script.Start: start(data.mode);

Sorting devices in power meter

For energy saving consumption using ai and other power meters get analysis of energy usage by device .

Describe the solution you'd like.

using ai or manual labeling sorting device consumption and substation power meters integration to main power meter.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Delay switching off

On the Shelly 1 plus, a script to switch on relay at the first push of the button and at the second push of the button delay the switching off of the relay after 60 seconds. How to do that?

ble-pasv-mqtt-gw.js : Add interval send message mqtt

Is your feature request related to a problem? Please describe.
In script ble-pasv-mqtt-gw.js, I would decrease the number of sending mqtt message in hour.
I try to implement interval_ms in BLE.Scanner.Start but no effect on send mqtt message frequency.

Describe the solution you'd like
Can you add config parameter for set interval mqtt send message, please ?

Describe alternatives you've considered
N/A

Additional context
N/A

Minor error in example remoterpc.js

I think that in line 54 the parameter error_message should be error_code to reflect the argument in the declaration of the function in line 53.
...and similarly for line 62 and 61.

Another matter - just a suggestion:
Regarding lines 23-25: These lines rely on the variable result being an object with certain properties. However, if Shelly.call, which is executing the callback code fails - e.g. because the remote Shelly device is temporarily unavailable (e.g. WiFi being down) - result is null or undefined and the script will stall.
The example code works for illustration of certain aspects, but perhaps a note/comment to add error handling in a "production environment" would be an idea?

ble-shelly-dw.js does not do anything

Hello!

I've got an issue with the script of: ble-shelly-dw.js

I got a Shelly BLU DoorWindow. As you can see in the screenshot, I copied the address inserted and run the script. Nothing happens. Where is my error?

image

Thank you for your help!

Scripting current state based on transition of multiple input states?

Is it possible to add a script to the library that reports a garage door state other than just Closed/Open by using multiple inputs?
The scenario I'm looking at would be a Shelly Plus 1 with Addon presenting "input:0" and input:100:

The desired outcome would be a custom MQTT topic being published that would report state as "Closed", "Opening", "Open", Closing", or "Stopped".

I was thinking that the state could be determined based on the initial state and subsequent input state changes.

ie. Closed (input:100 = true, input:0 = false) transitions to Opening (input:100 = false, input:0 =false) transitions to Open (input:100 = false, input:0 = true) transitions to Closing (input:100 = false, input:0 = false) transitions to Closed (input:100 = true, input:0 = false).

For Stopped it would be a timeout reached with (input:100 = false, input:0 = false) and neither reaching a true within a specified timeout

At each transition the state would be published

ble-shelly-btn-gateway-for-other-devices.js not working

Describe the bug
The script doesn't work and get the following log after start:

shos_rpc_inst.c:230 script.list via WS_in 192.168.2.34:54862 13:14:14
shos_rpc_inst.c:230 script.start via WS_in 192.168.2.34:54862 13:14:16
shelly_user_script.:328 JS RAM stat: initial: 113892 after: 113864, used: 28 13:14:16
shelly_user_script.:367 Running 'script_1.js'...13:14:16
shelly_bluetooth_sca:69 bluetoth scanner already taken 13:14:16
BLE is successfully started 13:14:16
shelly_user_script.:338 JS RAM stat: after user code: 113892 after: 112140, used: 1752 13:14:16
shelly_notification:163 Status change of script:1: {"id":1,"running":true} 13:14:16

stopping the script will resolve in:
shelly_bluetooth_sca:88 bluetooth scanner cannot stop non owned scan 13:12:49
shelly_notification:163 Status change of script:1: {"id":1,"running":false} 13:12:49

Device and script details (please complete the following information):

  • Shelly PlusI4 FCB467BAC924 | 1.0.8 | 58706c2c|
  • Shelly BLU Button 1: 20230725-152141/v1.0.8@0ba28b97

UPDATE:
_It turns out that I had the option "Enable Bluetooth gateway" ON in the settings what was the reason the script didn't worked. By disabling the gateway function now the script works. Can someone explain this?

NOTE: in previous firmware this used to work when the gateway is enabled:
https://youtu.be/ULZ0QfIfgdc?t=532

mDNS support

Per https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Mqtt/#step-3-set-a-new-mqtt-configuration, it's possible to configure one's Shelly to use host:port, with host a DNS-resolved hostname:

broker.hivemq.com:1883

This suggests that foo.local:1883 should also work. But it does not. It appears only the default DNS server in the LAN is used (for my ISP telenet.be that's 195.130.130.2) — quoting the websocket debug log:

{"ts":1689279084.923, "level":2, "data":"mgos_mqtt_conn.c:442    MQTT0 connecting to mist.local:1883\n}
{"ts":1689279084.948, "level":0, "data":"mongoose.c:12127        Failed to resolve 'mist.local', server 195.130.130.2\n"}
{"ts":1689279084.953, "level":2, "data":"mgos_mqtt_conn.c:189    MQTT0 TCP connected error (-1)\n"}
{"ts":1689279084.958, "level":2, "data":"mgos_mqtt_conn.c:221    MQTT0 disconnected\n"}
{"ts":1689279084.963, "level":2, "data":"mgos_mqtt_conn.c:527    MQTT0 connecting after 65028 ms\n"}

Surely mDNS support makes a ton of sense in the typical LAN context where Shelly devices are used? 😊 🙏 🤞

Cover.stop is not working when invoked from a BT event

Hey,
I have a problem using a script in shellyPlus25PM with Shelly DW BLU.
I'm trying to write a script that will stops the cover in case there is something blocking it. The way I did it is by putting the door sensor between the cover lowest shutter steps and when an event from the sensor detected by the shelly2PM it will check the position and stop if the cover is not near the bottom.
I used this script to decode the events
https://github.com/.../shelly.../blob/main/ble-shelly-dw.js
and added this function to invoke when close happens.
I have two problems:

  1. state is stopped although cover is not stopped.
  2. the cover doesn't stop
    while checking this code many times it only stopped twice!!
    full logs here
    https://pastebin.com/aXjXk8Mj
    https://pastebin.com/zAVXhRvk
    device data
    https://pastebin.com/fx9e8bvX

also tried using Shelly.call("HTTP.GET",...) calling stop, but it also didn't respond

this is the function I wrote

var STOP_POSITION = 35;
function triggerClose() {
  var should_touch_ground = 42;
  var state = Shelly.getComponentStatus("cover:0").state
  if (Shelly.getComponentConfig("sys").device.profile !== "cover" ||
	  state === "stopped") {
	  //return;  BUG state is "stopped" although it's moving;
  }

  var current_pos = Shelly.getComponentStatus("cover:0").current_pos;
  console.log("current pos:"+ current_pos+" should:" + should_touch_ground);
  if (current_pos !== undefined && current_pos !== null && current_pos > STOP_POSITION) {
	  Shelly.call("Cover.Stop", {'id': 0});
  }
}

To Reproduce
Steps to reproduce the behavior:
get a shelly2plus and shelly DW sensor.
add the script attached below.
while the cover moved down stop in with you hand to trigger an event.

Expected behavior
I expect the cover to stop but it doesn't. also I expect the state not to be stopped while the function runs.

Screenshots
here is how I put the sensor in the cover
https://ibb.co/jVgztkT

Device and script details (please complete the following information):

  • Firmware version 20231018-132958/1.0.7-beta2-g5d80465
  • Link to the script you were running https://pastebin.com/uZcKY3GL
  • If any external dependencies are necessary No

call HTTPServer (script) with web password on from a shelly Gen1

Hi, I set a web password for my shelly plus 2pm

With that web password set, I cannot call the script (that I created) from another shelly.

Is there any way to pass the password via the URL like the Gen1 do?
... or to disable the password protection for my script (but not for the shelly)?

with the old shelly you could add &user=admin&password=xyz to the url and you are done...

Thx for any hints,

Sebastian

shelly rgbw2 cycle switch request

is it possible to create a script to make that with the shelly rgbw with 4 white led strips you can have the cycle switch with the momentary button?

ble-pasv-mqtt-gw.js not correctly reporting negative temperatures for xiaomi devices

Negative temperatures are not reported correctly. -8.8c (might not be exact as the temperature fluctuates a bit) is reported as 6544.8c

To Reproduce
Simply place the xiaomi sensor in an environment with negative temperatures (in celcius) and check the mqqt output

Expected behavior
Expected to see negative temperatures reported in MQTT. Both mqqt reports (the one with only temperature and the one with temperature & humidity) are incorrect.

As long as it's still cold enough here I can easily test any fixes.

Unable to find scripts/webhooks to control Philips Hue with shelly i4 plus

The shell i4 plus order page states:

Whether you use Shelly Wi-Fi bulbs, Philips Hue, or even different brands smart bulbs, Shelly Plus i4 is highly compatible and can control them all!

 

Furthermore, you can use Shelly Plus i4 to set the light color you want or for dimming of your smart bulbs. All you have to do is add and configure one of our scripts or webhooks created specifically for Shelly Plus i4.

And then the learn more link directs me here, however I can not seem to find the scrips or web hooks that are created specifically for the shelly plus i4 that can control my Philips hue bridge?

Need example for BLU motion triggering switch without cloud

Is your feature request related to a problem? Please describe.
Need to replace Shelly cloud scene solution with script because deployment does not have Internet.

Describe the solution you'd like
Provide same functionality without cloud, that scene allows to do with cloud.

Describe alternatives you've considered
Existing scripts in https://github.com/ALLTERCO/shelly-script-examples, e.g.: ble-shelly-motion.js do not suffice.

Additional context

  1. Need for script to trigger gen2 switch on based on motion, and off based on nomotion.
  2. Need for script to support time-range when triggering is effective.
    I tried to understand how to add time condition to ble-shelly-motion.js,
    but and got frustrated by js complexity of Sys.GetStatus() to use callback only (not a js expert).
  3. Need for script to be reliable in case of BLE messages being lost.
    If nomotion BLE message is lost, switch will stay on for a long time. Unacceptable.
    Could add code to switch off after some timeout, but need to be js expert to do that.
    And if switching off after some timeout, then BLE motion would need to periodically send motion events
    But only when there is motion, not when there is not (save battery).
    but it is unclear to me how to set up BLE motion to periodically send motion event when there is ongoing motion.
    and then how to program script on switch to reset nomotion timeout event.

Script to make gen2 shelly accept GET /status like gen1

I have a controller which calls gen1 shelly with rest api GET /status. gen2 does not have /status but I cannot change controller.

Is there a script for gen2 (Pro 3EM) which would make gen2 respond to /status call?

Thank you

Solar gains and Heat pump yearly consumption

Is your feature request related to a problem? Please describe.
There are situation when we have solar power and heat pump but we must have consumption greater than yearly solar production ( because power company limitation and tax limitation) . Year start in first month so there is little solar production but big heat pump production , but in summer we will not use solar heat pump and gain extra solar production , is possible to have prediction based on previous year so solar gain and put limiter on heat pump solar energy monitor.

[...]

*Describe the solution you'd like

Possibility to get two variables from main Shelly power meter , yearly solar gain ( first year we put assumptions second year use previous years averages) , and second parameter after ten months get real total production .

Describe alternatives you've considered
Or get two variables from main power meter yearly average consumption and total production and current consumption from year start to this date.

Additional context
Add any other context or screenshots about the feature request here.

ble-shelly-blu missing data types for humidity and temperature for the new BLU H&T device

The temperature and humidity values are reported as 0x45 and 0X2E so the payload fails and the emit data is missing the humidity and the temperature values

the BTH const must be extended to look like:
const BTH = {
0x00: { n: "pid", t: uint8 },
0x01: { n: "battery", t: uint8, u: "%" },
0x02: { n: "temperature", t: int16, f: 0.01, u: "tC" },
0x45: { n: "temperature", t: int16, f: 0.1, u: "tC" },
0x03: { n: "humidity", t: uint16, f: 0.01, u: "%" },
0x2E: { n: "humidity", t: uint8, f: 1, u: "%" },
0x05: { n: "illuminance", t: uint24, f: 0.01 },
0x21: { n: "motion", t: uint8 },
0x2d: { n: "window", t: uint8 },
0x3a: { n: "button", t: uint8 },
0x3f: { n: "rotation", t: int16, f: 0.1 },
};

sendMessage doesn't retry

Describe the bug

Function sendMessage doesn't retry if it gets a timeout

Expected behavior

Retry mechanism if the request was a timeout.

Screenshots
If applicable, add screenshots to help explain your problem.

Device and script details (please complete the following information):

Idea: Include a BLE script that support ESPresence functionality for Home Assistant

Dear Allterco,

Next to the 'normal switching function' (which I much appreciate) the Shelly 1PM devices (and product family) also seem ideally suited to detect BLE sensors (phones, tags etc) !

Would your (Allterco's) new example script makes that the Shelly 1PM also sends MQTT BLE messages or would the new shelly integration also include the BLE beacon information, then (for sure !) many Home Assistant users would be most pleased with the new Person_Presence detection functionality.
To further explain: With several Shelly devices installed in the house, then lights and other devices in each room can be automated, pending the presence of the mobile beacon (e.g. phone, smart watch etc.) of the person wearing that device. All without additional hardware !

A simular software function is outlined at https://github.com/ESPresense/ESPresense.
ESPresence recommends acquiring a seperate ESP32 which needs a power supply, housing etc.
It pleasantly struck me to also note that this type of required hardware is already in abundancy at my house: All my electric light switches have Shelly 1PM devices, so I guess (as I am not a software expert) that the following is required:
A1. new Shelly BLE script sending MQTT and
A2. sensor definition in Home Assistant or
B. the Shelly integration for Home Assistant also include BLE beacon detections functionality.

Is that a nice idea?
Regards, Wipnose
(an enthousiastic Shelly and Home Assistant hobbyist)

MQTT.setConnectHandler()

Hi,
Is there a way, per script, to create a new idClient, other than that of the module which houses the script, and to indicate its keepAlive, willMessage, willTopic, etc...
The MQTT.setConnectHandler(callback, callback_arg) function, can it do this job?
Can you provide an example of using this function?
Best regards

[Shelly plus 2pm] Script to prevent 2 output in the same time ( Vent control )

Hi,
A feature, implemented on the shelly 2.5 in shutter/cover mode was to disable the run timeout with 0 value
It's not possible on the shelly plus 2pm in cover mode

We need that feature since we control 2 speed fan.
Powering a motor both speed in the same time === destruction & Fire
In relay mode it's possible to switch both relay resulting in the destruction of the fan motor.

The need : a simple script that toggle the state of the two output when On
Relay 1 ===> On Relay 2 Off
Relay 2 ===> On Relay 1 Off
Relay 1 ===> Off do nothing
Relay 2 ===> Off do nothing

Thx

local_name empty

My blu has not local name so all scripts are not working....

Whats the way to rename the local_name of blu device?

Regards

example for operating 2 outputs on a multioutput device at the saem time

More of a suggestion

For e.g. a Shelly Pro 2: a script that makes both outputs on or off at the same time no matter what inputs (network, buttons, ...) are used to switch them (without creating a loop that results in a flip-flop) . Making sure there's no possibility to leave it with one output on and the other off.

Use case: Bathrooms are here are required to switch on and off both the phase and the neutral at the same time.

A foolproof script would be preferred, a script with just one used as master (and operated) and the other as slave (optionally making its controls inoperative if that could be achieved) could be acceptable as well.

WIFI provisioning script - error encountered

Received an error running this script on a ShellyPlus2PM:

this is the log:
Uncaught ReferenceError: "self" is not defined
at for (let papk in self.targetCache) {
^
in function "isInCache" called from if (self.isInCache(cSSID) === false) {
^
in function called from system

Seems like there is an issue here:
https://github.com/ALLTERCO/shelly-script-examples/blame/297358ede3b448d683a90a6c301e2c82dfd02506/wifi-provision.js#L127-L134

The self variable is used, but it is not defined within the function's scope.

debounce options for event handler

I have a magnetic reed switch that due to its mounting orientation results in the contact bouncing on activation.

How can i script a suppression for the event handler to debounce subsequent events for 2000ms so only the first (or last) event is published?

Shelly.addEventHandler(function (event) {
if (event.name === "input" && event.id === 100 && event.info.state === true) {
MQTT.publish("shellyplus1-a8032abd2900/doormoving", JSON.stringify(true), 0, false);
}
if (event.name === "input" && event.id === 0 && event.info.state === true) {
MQTT.publish("shellyplus1-a8032abd2900/doormoving", JSON.stringify(true), 0, false);
}
if (event.name === "input" && event.id === 100 && event.info.state === false) {
MQTT.publish("shellyplus1-a8032abd2900/doormoving", JSON.stringify(false), 0, false);
}
if (event.name === "input" && event.id === 0 && event.info.state === false) {
MQTT.publish("shellyplus1-a8032abd2900/doormoving", JSON.stringify(false), 0, false);
}
});

Script for delaying relay on

Hi,
I'm looking for a script following the uptime, and at given value activate the device with an auto on delay.

This would enable me to plug my Shelly Plus Plug S into the socket, and the relay would be switched on only after given time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.