Can't make custom device count trigger


#1

1) Give a description of the problem
I’ve created a piston that will count the number of active motion sensors. I want to trigger actions based on the count. The trigger that I’m setting doesn’t have a “lightening bolt” next to it so it’s not going to trigger. Is there a way to do this?

2) What is the expected behaviour?
Make the piston trigger when the count of active motion sensors is at 0 or rises to 2 or more.

3) What is happening/not happening?
It’s not showing a trigger.

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

5) Attach logs after turning logging level to Full
will upload if requested.


#2

I am on my way out the door, but a quick observation:

Your trigger on line 23 monitors the moment one of those sensors changes to active. This means that your count should be “0” 99.8% of the time, and “1” the remaining 0.2%.

There may be a few rare occasions where you may get 2 (if two sensors report within a second of each other) but I would not rely on that, or expect that often…


Side Note:
I would also do away with the ELSE block, and move that IF block into it’s own statement


#3

Thanks for the reply! I have some motion sensors that once they motion is triggered, it stays in an active state for 1 minute. So that means if there is another motion alert activated, then it will increase by one. This particular piston works as expected.

I’ll also go ahead and adjust to put it in its own IF statement as you recommend. I just figured it would default to ELSE if that IF isn’t matched.


#4

Switching line 23 to “IS ACTIVE” should allow the count to go above 1.
(since “changes to active” is only true for a brief moment)


For furthur assistance, please turn on Trace and set logging to Full during an error.


#5

I’ve changed it to “active” on line 23. I will see tonight if there is a trigger that happens when the count goes to 2 or 0. I don’t see a trigger bolt next to it so I’m not sure if this is going to cause it to trigger.


#6

Hi @WCmore, unfortunately, that change didn’t do anything. Nothing is triggering a countdown to turn off the lights. Attached is the log files. It looks like it’s returning the comparison when the door shuts but I’m attempting it to evaluate and trigger when the comparison of 0 = true.

Comparison (integer) 1 changes_to (integer) 0 = false (0ms)

10/14/2019, 8:36:37 PM +263ms
+1ms ╔Received event [Door - Back/Rear].contact = closed with a delay of 83ms
+128ms ║RunTime Analysis CS > 22ms > PS > 53ms > PE > 54ms > CE
+131ms ║Runtime (44301 bytes) successfully initialized in 53ms (v0.3.10f.20190822) (128ms)
+132ms ║╔Execution stage started
+159ms ║║Comparison (enum) active is (string) active = true (1ms)
+161ms ║║Comparison (enum) inactive is (string) active = false (2ms)
+163ms ║║Comparison (enum) inactive is (string) active = false (1ms)
+165ms ║║Comparison (enum) inactive is (string) active = false (1ms)
+170ms ║║Condition #2 evaluated true (33ms)
+171ms ║║Condition group #1 evaluated true (state did not change) (35ms)
+225ms ║║Comparison (time) 74197436 is_between (time) 1571094420000 … (time) 1571053800000 = true (8ms)
+226ms ║║Time restriction check passed
+227ms ║║Condition #19 evaluated true (54ms)
+228ms ║║Condition group #3 evaluated true (state did not change) (55ms)
+234ms ║║Comparison (integer) 1 rises_to_or_above (integer) 2 = false (1ms)
+236ms ║║Condition #5 evaluated false (5ms)
+239ms ║║Comparison (enum) closed changes_to (string) open = false (0ms)
+241ms ║║Cancelling condition #17’s schedules…
+242ms ║║Condition #17 evaluated false (5ms)
+243ms ║║Cancelling condition #4’s schedules…
+243ms ║║Condition group #4 evaluated false (state changed) (13ms)
+244ms ║║Cancelling condition #3’s schedules…
+245ms ║║Condition group #3 evaluated false (state changed) (16ms)
+252ms ║║Comparison (integer) 1 changes_to (integer) 0 = false (0ms)
+253ms ║║Condition #12 evaluated false (6ms)
+254ms ║║Condition group #10 evaluated false (state did not change) (7ms)
+256ms ║╚Execution stage complete. (125ms)
+257ms ╚Event processed successfully (257ms)
10/14/2019, 8:36:24 PM +976ms
+1ms ╔Received event [Door - Back/Rear].contact = open with a delay of 75ms
+138ms ║RunTime Analysis CS > 23ms > PS > 56ms > PE > 58ms > CE
+140ms ║Runtime (44341 bytes) successfully initialized in 56ms (v0.3.10f.20190822) (138ms)
+141ms ║╔Execution stage started
+167ms ║║Comparison (enum) active is (string) active = true (1ms)
+169ms ║║Comparison (enum) inactive is (string) active = false (1ms)
+172ms ║║Comparison (enum) inactive is (string) active = false (1ms)
+174ms ║║Comparison (enum) inactive is (string) active = false (2ms)
+178ms ║║Condition #2 evaluated true (32ms)
+179ms ║║Condition group #1 evaluated true (state did not change) (34ms)
+235ms ║║Comparison (time) 74185158 is_between (time) 1571094420000 … (time) 1571053800000 = true (9ms)
+236ms ║║Time restriction check passed
+237ms ║║Condition #19 evaluated true (56ms)
+238ms ║║Cancelling condition #3’s schedules…
+239ms ║║Condition group #3 evaluated true (state changed) (58ms)
+245ms ║║Comparison (integer) 1 rises_to_or_above (integer) 2 = false (1ms)
+247ms ║║Condition #5 evaluated false (5ms)
+250ms ║║Comparison (enum) open changes_to (string) open = true (0ms)
+252ms ║║Cancelling condition #17’s schedules…
+253ms ║║Condition #17 evaluated true (6ms)
+254ms ║║Cancelling condition #4’s schedules…
+255ms ║║Condition group #4 evaluated true (state changed) (14ms)
+256ms ║║Condition group #3 evaluated true (state did not change) (16ms)
+258ms ║║Cancelling statement #7’s schedules…
+264ms ║║Skipped execution of physical command [Driveway Flood Ring].on([]) because it would make no change to the device. (3ms)
+265ms ║║Executed [Driveway Flood Ring].on (5ms)
+269ms ║║Skipped execution of physical command [Driveway Side Ring].on([]) because it would make no change to the device. (2ms)
+270ms ║║Executed [Driveway Side Ring].on (4ms)
+276ms ║║Skipped execution of physical command [Garage Sconce Left].on([]) because it would make no change to the device. (3ms)
+277ms ║║Executed [Garage Sconce Left].on (5ms)
+283ms ║║Skipped execution of physical command [Garage Sconce Right].on([]) because it would make no change to the device. (2ms)
+283ms ║║Executed [Garage Sconce Right].on (4ms)
+290ms ║║Skipped execution of physical command [Patio Sconce Left].on([]) because it would make no change to the device. (2ms)
+290ms ║║Executed [Patio Sconce Left].on (4ms)
+296ms ║║Skipped execution of physical command [Patio Sconce Right].on([]) because it would make no change to the device. (2ms)
+297ms ║║Executed [Patio Sconce Right].on (4ms)
+300ms ║╚Execution stage complete. (158ms)
+301ms ╚Event processed successfully (301ms)


#7

We might have to combine both methods (replacing lines 22-25) Maybe something like this:

IF any of {motionSensors}'s motion CHANGES to active  <-- Trigger
Then
    IF {motionSensors}'s motion IS active             <-- Condition
    Then
        save matching devices to {activeMotionSensors}
    END ID
END IF

This should place the lightning bolt next to the trigger. Each time a sensor momentarily goes active, the inside IF should add all the sensors that are currently active.


One other element that will eventually have to be addressed is:
Line 30 & 42 can never be a trigger. Even though it is written as a trigger, math usually cannot actually trigger a piston. (math is only calculated when the piston is actually running) Meaning, that those lines will be treated as conditions, and the piston will only execute top to bottom when a “lightning bolt” line fires…


#8

Any idea why there is a trigger for the active motion sensors on the one I showed previously (agno) but no longer on this one (w56qh)?

I guess another way around this is to do a loop on the second IF statement that evaluates every 30 minutes or something?

I appreciate all your help!


#9

When there are no triggers in a piston, then all conditions are treated as triggers.
(conditions-and-triggers-the-difference)

So when you added the trigger on line 32 in “w56qh”, then line 23 is treated like a condition


I do not see any reason for a loop. This suggestion will execute when any of the sensors turns active.


If it were me, I would be tempted to change line 23 to fire on active or inactive.

Here is that slight variation:

IF any of {motionSensors}'s motion CHANGES  <-- Trigger
Then
    IF {motionSensors}'s motion IS active   <-- Condition
    Then
        save matching devices to {activeMotionSensors}
    END ID
END IF

This method recalculates the active sensors whenever any one of them changes at all.