Global Variables for presense detection


#1

With a lot of help from this community, I think I have the simplest piston to determine is someone is home. My main goal for this when I started, is I have some pistons that I want to behave differently if someone is home vs for the 1st person arriving home. Simplest example is: I want my lights to turn on after dark when I arrive home, but is someone is already home I don’t want to run to change the lights. I wanted a simple boolean value, but another member used a count. Anything above 0 meant someone home. I can see the value in both, so I added both to the Piston. Additionally, I wanted to make is as generic as possible, so it would not require me to modify it if I added more people in to the mix.

If you dont need the count, just remove that line


#2

Or:

IF
Any of @presenceSensors are present
Save matching devices to {@presentPersons}
THEN
set variable {@countPresent} = count(presentPersons)

The @presentPersons variable will store the device names for who is present which is handy for notifications etc. If you quote the variable in a notification or SMS it will position the commas & an ‘and’ in the correct sentance format i.e x, y and z

The @countPresent variable will store the number of devices present as an integer.


#3

I like that. I dont know how to save matching devices though. Would you mind sharing the steps. Thanks


#4

When you’re building an IF statement, just click on the cog symbol for the advanced options.


#5

Great. 1/2 way there. I see the option, but no variables are available. I created a global called presentPersons, even tried different variable types. I chose string at first, but regardless of choice, there were no options available


#6

I was able to add items to a local variable list, but trouble with a global variable list


#7

Interesting… I’ll give it a go.


#8

Yup… can’t select global variables via the ‘add matching devices to variable’ function… we’ll see if we can get that fixed.

For now, just bounce it through a local variable, before saving it to the global one.


#10

@Robin copycat!


#11

???


#12

i did this. you’re copying me :stuck_out_tongue_closed_eyes:


#13

Liar lol… I’m always first :joy:


#14

Complete noob here. How and where do I set up the variables quoted?


#15

Global Variables

When editing a piston (on PC / Mac / Desktop), there is a ‘Global Variables’ bar to the right. You will see ‘+ add a new global variable’. The’@’ symbol is required, it helps pistons identify global variables.

If you make the global variable type ‘device’ instead of the default ‘dynamic’, it will appear as an option for selecting when choosing a device in the piston editor.

Local Variables

When editing a piston (on PC / Mac / Desktop), click the image symbol at the top of the page.

The option to add local variables then appears at the top of the piston editor.


#16

Hello…did this ever get changed so we could save matching devices to a Global variable. I still cannot.

Thanks.