jsurpless Posted July 27 Posted July 27 I'm hoping that someone can offer some assistance on this. I've got a Plus 1PM that has a lamp in it which I would like to turn ON to indicate that one of the gates in my fence is open. I am monitoring their OPEN status via (3) Door/Window sensors (inside weatherproof enclosures). A while ago, I put together the following script in an effort to capture the Action URL commands from each of the sensors. Basically, I want to latch each sensors open status (and then reset via its closed status). As long as any sensor is open, keep the lamp ON. Unfortunately, it doesn't seem to be working any more - my EVENT doesn't even seem to fire (I don't see the messages if I remove the comment out prefixes). Thoughts? Is there a better way to do this? let Gate_Name = ["N/A", "N/A", "Fence Gate (South Left)", "Fence Gate (South Right)", "Fence Gate (North)"]; let Gate_Status = ["N/A", "N/A", "Closed", "Closed", "Closed"]; let NumberOfGates = 3; function CheckGates (userdata) { /* Assume All Gates Closed */ let AnyGateOpen = "No"; for (let GateIndex = 2; GateIndex <= NumberOfGates + 1; GateIndex++) { print("Checking ", Gate_Name[GateIndex]); if (Gate_Status[GateIndex] === "Open") { print(Gate_Name[GateIndex], " Open"); AnyGateOpen = "Yes"; } else { print(Gate_Name[GateIndex], " Closed"); } } if (AnyGateOpen === "Yes") { Shelly.call ("Switch.Set", "{ id:0, on:true }", null, null); } else { Shelly.call ("Switch.Set", "{ id:0, on:false }", null, null); } } Shelly.addEventHandler( function (event) { //print (JSON.stringify(event)); //print("EVENT NAME = ", event.name); if (event.name === "script") { if (Gate_Name[event.id] !== "N/A") { print (event.info.running); //Gate Open if (event.info.running) { print(Gate_Name[event.id], " Open"); Gate_Status[event.id] = "Open"; //Gate Closed } else { print(Gate_Name[event.id], " Closed"); Gate_Status[event.id] = "Closed"; } //Check Which Gate Are Open And Set Lamp On/Off Accordingly CheckGates(null); } } } ); Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish
jsurpless Posted July 27 Author Posted July 27 I realized that I forgot to mention that I'm latching each sensor's open status via a dummy script that is started/stopped, based on open/closed. It's the only way that I could figure out how to store the status. That's why the above script is watching scripts. This script is ID 1, the others are ID2-4 Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish
jsurpless Posted July 27 Author Posted July 27 It seems that the Shelly.addEventHandler doesn't trigger on scripts being started/stopped but for some reason, it triggers when I toggle 'Run On Startup'. Pretty sure that this used to work differently. Also, it doesn't seem like you can have more than 3 scripts running at any given time? Again, pretty sure that I was using script running state as the latch and so I would have been able to have (4) scripts (Monitor plus (3) gate scripts). Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.