Simplifying my piston


#1

1) Give a description of the problem
Having to run multiple IFs, one for each sensor,

2) What is the expected behavior?
I’m sure there must be a simpler way to do this than adding a new section to my code each time i add a sensor
3) What is happening/not happening?
I need to announce the names of the open sensors, plus add the sensor names to a text string for a push notification

**4) Post a Green Snapshot of the piston![image|45x37]

5) Attach any logs (From ST IDE and by turning logging level to Full)
N/A


#2

If you’re wondering what triggers the piston, it’s triggered by a virtual switch that’s set by Alexa, so I can ask alexa “Check the house”, I then get a spoken report (via lannouncer) of which doors and windows are open. The image is a clipping of one sensor. I currently have a block like this for every sensor in the house, which seems a stupid way to code things, but I don’t have the experience in Webcore to know how to do it better. If I were doing this in a more normal script, I’d probably use an array and a foreach loop.


#3

Here is something I use for checking for INACTIVE devices.
It saves the INACTIVE device to a variable.
Is this the sort of thing you are after?


#4

Thanks for the help.

I eventually sorted it. Turns out the missing piece of the puzzle is that it’s possible to create a variable of type device, into which you can place multiple devices and select “all of the devices” - then it becomes possible to use a foreach loop with another device variable as a placeholder to loop through each device in the original variable.

Neat.


#5

for anyone with a similar question who wants the whole thing, enjoy!

Edit: ignore the bit about ifttt and askalexa in the top comment - i no longer use these to run the script so the comment is just out of date - old news :smiley: