Help with setting global variable for presence with multiple presence sensors


#1

1) Give a description of the problem
i have two people living in my apartment. I want to have a variable keep of presence. I have pistons that only need to run when at least one person is home or execute only when both people are away

2) What is the expected behavior?
when 1 or more devices are presence add and load into the variable

3) What is happening/not happening?
my global variable is not populating with data, but i am really not sure i am doing this right. I copied this code from somewhere on here and i have been trying to get it to work. Any help woould be greatly appreciated

4) Post a Green Snapshot of the pistonimage

5) Attach any logs (From ST IDE and by turning logging level to Full)
11/17/2018, 11:16:54 PM +944ms
+1ms ╔Received event [My Apt].test = 1542525414943 with a delay of 0ms
+102ms ║RunTime Analysis CS > 13ms > PS > 68ms > PE > 21ms > CE
+105ms ║Runtime (39031 bytes) successfully initialized in 68ms (v0.3.108.20180906) (102ms)
+106ms ║╔Execution stage started
+123ms ║║Condition #82 evaluated false (10ms)
+125ms ║║Condition group #81 evaluated false (state did not change) (12ms)
+130ms ║╚Execution stage complete. (25ms)
+132ms ╚Event processed successfully (132ms)


#2

edit:
Also, to test, the presence of your device needs to change. This can be forced if you are using the webcore mobile app with presence setup. Otherwise the piston wont see anything has changed, and not do anything, as it reads in your log.

Take a look at my occupancy piston:
import code: 5neh

It uses 2 global variables:
device @presenceDevices = all phones/presence devices
integer @occupancy = 0

And note, both if statements are set to “if any of @presenceDevices’ presence changes to…”


#3

Why do you have to use a global variable? Just select your presence devices as conditions. When both should be away make sure you have all. And if only one home, use any.
If you’re dead set in using a global variable I would simplify if

IF presence of either device changes
THEN
IF Either device is present
THEN set variable to true
ELSE set variable to false.

Much simpler.


#4

Global variable is a design choice I made as it allows me to use the same device group in other pistons, and only needs to be edited in 1 place if anything changes.

Yes, the ‘if’ structure could be collapsed, im not sure if there is a performance hit with my setup.


#5

That’s why I would use a boolean global variable. I don’t have any presence sensors, so you can’t copy this directly but if you substitute presence as the capability (instead of switch) and present as the attribute (instead of on) then this is how I would do it.
First create the boolean (true false) global variable “@present

This is much simpler. If you are only trying to see if someone is present or not, then this is the way to do it. There’s no reason for you to keep track of who’s home since you can’t access that info except from the webCoRE dashboard. And then, why not just look at the status of the presence sensor.

Then you can use the global variable @present as true when someone is home or false if someone isn’t.


#6

I’m late to this, but that piston should work reliably. Did you define the @Occupancy variable somewhere? If not, just edit your piston by clicking in the Define section, and add an Integer Variable named @Occupancy.

Once you do, you’ll see this variable populated in every piston you view:

image