String together devices into variable


#1

Hello all, I am looking for a little assistance with a piston. I am trying to create a piston tile where the piston state lists all the contact sensors that are open.

I stole most of that code from other pistons and tweaked a little here and there. Note switch 8 at the bottom is a virtual switch that is already tracking if they are all closed, and if so - it is off, else if they are open, the switch is on. I am trying to null the variable printing in the piston state by tracking this.

The current problem is that the piston state is repeating the same contacts over and over now that the windows are open with the nice weather today.

image


#2

Use the ‘save matching devices to variable’ function.

IF
any of {contactSensors} are open
x2 Save matching devices to {openSensors}

When writing the above IF statement, click the cog symbol to access the save to variable settings.


#3

And then use a ternary operator to output the variable in a nice format (i.e. all closed, is open, are open).

(count(openSensors)==0 ? ”All doors and windows are closed” : (count(openSensors)==1 ? OpenSensors “ is open” : openSensors “ are open” ))


#4

Odd, {Opensensors} variable is not available to me in the matching device option. Only {contactSensors}


#5

That’s what I am attempting to do in row 31 :slight_smile:

There is actually only 1 sensor open, so it is right. I’m the user, if you recall, that has one sensor that is faulty - I was trying to set notifications to SMS if contact sensors are open and it is cold out, and no matter what we did, the SMS would not cancel when everything was closed.

That P D3 is faulty I think. I replaced the battery, but might need to replace the sensor completely.

Curious could webCore and tile dashboards be causing a problem here? That specific device might be in 4-5 different dashboard (tile) pistons (plus a few more ‘worker’ pistons).


#6

That’s because you have that variable defined as an integer… change it to a device variable.


#7

ah good screen shot provides the evidence. :slight_smile:

many thanks for ALL your help!


#8

Just throw that sensor in the bin and get one that actually works… so much hassle trying to work around a buggy device lol :joy:

If that piston I helped you with the other day is sending messages when al is ok… post that comment in the original thread (So I get a notification to help me find it again) and I’ll help you debug


#9

Nope… you just have a crappy device.


#10

excellent, glad for the confirmation. in case anyone else is watching, final state of piston - now working.

PS: Adrian writes such good code. That matching device thing… added the ‘and’ in the string. Very cool.

image


#11

You shouldn’t be using ‘for each’ anymore… you can look at all the contact sensors at the same time and save them to the variable in one hit.


#12

Slightly related…I’m trying to create a piston with a device variable to contain a number presence sensors, but i don’t seem to be able to get the ‘any of’ logic when setting up the if statement in the piston…

If i substitute two or more devices directly in the if statement and choose ‘any of’ it appears, but when i replace with the variable name and choose any of it appears to treat as a single device in the resulting code.


Am I doing something wrong?


#13

it’s just an old display issue… it does not say ‘any of’ or ‘all of’ but when you go in to edit that line the option is there in the orange bar, and it works regardless of what it says (or does not say) in the main view.

image


#14

Ahh, OK cool thanks.

I have this virtualPresence sensor to combine a st presence fob and the webcore presence sensor.

I’m using the Device Tiles - Presence Sensor Status Tiles (tymkb) from https://wiki.webcore.co/Device_Tiles#Presence_Sensor_Status_Tiles to show home away status for 4 of us in the house.
My two kids have both webcore sensors configured on their phone and have the st presence fobs.
Weirdly, just my eldest son’s webcore presence tile doesn’t update - i see a bunch ‘piston waited at semaphore’ messages in the log for the status tile an it just shows ‘No event yet’ for him - although the webcore presence sensor in st classic app is showing his whereabouts. I wondered if somehow the virtual presence sensor code was clashing…although i’m using the same for my other son’s and thats working just fine

I’m just using the ST presence for my wife as she has an iPhone 5 and the webcore sensor doesn’t seem to work on her version of ios