allterco / shelly-script-examples Goto Github PK
View Code? Open in Web Editor NEWShelly Scripts for Gen2 Shelly devices
License: Apache License 2.0
Shelly Scripts for Gen2 Shelly devices
License: Apache License 2.0
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
To ensure consistent coding style. I suppose some JS formatting tool can also be applied.
Could you modify the script to support password protected devices?
thnx
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);
}
shelly-script-examples/ble-ruuvi.js
Line 117 in 5a7ab80
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! 😊
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.
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?
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});
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 :
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
) {
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.
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!
Hi, im trying to use the script with a Plug Plus S. But it does not switch the relay. The Diagnostic Debug Log just shows "Disconnected"
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.
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);
Maybe I am missing something here, but when playing around with Shelly scripting on my Shelly Plus 1PM I cannot find a function to convert the unix timestamp from Sys.getStatus
to a date in the YYYYMMDD
format.
We have the time
already, I think we should have a date
too. Or alternatively the Date class from Javascript.
Need this to send Solar data to the PVOutput API.
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.
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?
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
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?
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
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):
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
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? 😊 🙏 🤞
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:
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):
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
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?
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.
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?
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
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
shelly-script-examples/wifi-provision.js
Line 31 in 297358e
This code seems not to cover Shelly Mini devices. The SSID is e.g. Shelly1Mini-xxxxxxx.
My solutuion was to add shelly mini here:
apn: [„ShellyPlus“, „ Shelly1Mini“]
Do you might adding some very very simple examples? IE turn light on / Turn light off / Timer on / timer off?
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.
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 },
};
I am struggling to get my head around the use of UserData in for example Timer.set(period, repeat, callback, userdata)
and Shelly.call(method, params, callback, userdata)
.
It would be really nice to see a script example where that is used.
Kind regards
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):
shelly-script-examples/ble-shelly-dw.js
Lines 43 to 46 in f79740a
wtf??
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)
On my Shelly 1 PM Plus Web frontend, I get an error when navigating to Scripts->Library:
Firmware versions teste: 0.12 and 0.13
URL used in the library dialog is the default one:
https://raw.githubusercontent.com/ALLTERCO/shelly-script-examples/main/SHELLY_MJS.md
Error message I get:
TypeError: r.split(...)[1] is undefined
Couldn't load library. Please try again or reset the library to default.
Seems to be related to yesterdays commit, as it was working before.
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
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
Is your feature request related to a problem? Please describe.
Script https://github.com/ALLTERCO/shelly-script-examples/blob/main/ble-ruuvi.js does not give an error if bluetooth is off. It runs but without any results.
Describe the solution you'd like
Give an error and stop script execution if bluetooth is off.
Additional context
Add any other context or screenshots about the feature request here.
My blu has not local name so all scripts are not working....
Whats the way to rename the local_name of blu device?
Regards
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.
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.
I've tried this example using a Shelly plus plug, with a threshold of 20mw/h but it didn't work.
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);
}
});
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.