X2 save matching devices problem


#1

1) Give a description of the problem
I’m trying to save devices to a variable based on presence. This snip is from a piston I built from scratch that almost works well. Any help would be appreciated.

2) What is the expected behavior?
Store the names of vehicles when presence changes and then use them in notifications,
ie “Joe’s Car has left. Location mode is X. Themostat is Y, etc”

3) What is happening/not happening?
When true, the second IF stores the device name as expected (Joe’s Car),
snip%20b

BUT, when the first IF becomes true, the device ends up being (not set), instead of (Joe’s Car).

snip%20c

I have changed the order of the IF’s and the behavior always works for the second IF but not the first. That should tell me something, but at this point, I’m at a loss.

Log from “Not Present”:

|+1ms|╔Received event [Joe's Car].presence = not present with a delay of 100ms|
|---|---|
|+58ms|║RunTime Analysis CS > 18ms > PS > 28ms > PE > 13ms > CE|
|+61ms|║Runtime (38583 bytes) successfully initialized in 28ms (v0.2.102.20180116) (58ms)|
|+62ms|║╔Execution stage started|
|+71ms|║║Comparison (enum) not present changes_to (string) not present = true (1ms)|
|+76ms|║║Cancelling condition #29's schedules...|
|+77ms|║║Condition #29 evaluated true (9ms)|
|+78ms|║║Cancelling condition #16's schedules...|
|+78ms|║║Condition group #16 evaluated true (state changed) (11ms)|
|+84ms|║║Comparison (enum) not present changes_to (string) present = false (0ms)|
|+88ms|║║Cancelling condition #17's schedules...|
|+89ms|║║Condition #17 evaluated false (8ms)|
|+91ms|║║Cancelling condition #28's schedules...|
|+92ms|║║Condition group #28 evaluated false (state changed) (11ms)|
|+94ms|║╚Execution stage complete. (33ms)|
|+96ms|╚Event processed successfully (95ms)|

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

I don’t believe that presence sensors are a good fit for using the Matching devices functions.

You’re probably better off using $currentEventDevice instead.

You’ll be able to do everything you’ve stated you want to do with that system variable.


#3

Each time your piston run, it executes both IF statements.

When your car is NOT PRESENT, the first condition evaluates TRUE and saves “Joe’s Car” to the variable. Then your second condition evaluates FALSE, and saves its matching devices (none) to the same variable.

When you car is PRESENT, the inverse is true and the 2nd statement saves “Joe’s Car” to the variable.

In reality, you’re only ever going to see the result of the 2nd IF statement in this piston.

Without understanding the bigger picture you’re trying to accomplish, it’s hard to provide any advice on where to go with this next.


#4

Did you get this sorted out?


#5

Thanks for the followup. I’ve been fighting this for 8 days :slight_smile:
I know what you’re saying is true, but to my mind, since only one trigger became true, only one trigger should apply.
ie- if Joe’s car changes to “not present” only the first trigger actions should happen.

I have a total of 3 physical sensors that I’m trying to integrate. Sensor 3 is a virtual switch.
Sensor 4 is a sensor on a fob that one of us will grab when we’re getting in the others car (or we’re both going for a walk) that overrides what #1 and #2 do.
The first “if” is the original piston. The second “if”, which seems to be now working, is what I’m trying to add to the piston. I’m going to roll up my sleeves and try to integrate the two “if”'s together. Any additional input is greatly appreciated.


#6

The easiest way to think about it is this way:

Triggers start your piston. ALL triggers cause your piston to run from the top all the way through the code, regardless of where said trigger is within your piston.

There are no subroutines or executing specific blocks of code.

Once you know that, it’s quite easy to program around it. Before you figure it out, it’ll drive you mad. Lol


#7

I thought I understood the part that a trigger will run the whole piston.

If a sensor changes,
If sensor changes to true, then do A.
If sensor changes to false, then do B.

Is this a matter of “save matching devices” must be used like this?:
If sensor changes to true
Then
Using Location
save matching devices

I guess I should go and try this…

Anyway, thank you very much for spending time on this .