Turn on lights just once daily when I'm not home


#1

1) Give a description of the problem
I am trying to create a piston that will trigger every night when I’m not at home, running just once per night.

2) What is the expected behaviour?
At night, turn on my entrance if I’m not at home. This should happen only the first time in the night (aka if I turn that light off, it should not turn itself on if I leave).

3) What is happening/not happening?
By moving the verification of “Location mode” from a restriction to a triggered condition, my piston was able to subscribe to an event on Location. But that causes the piston to only turn on the light if it is night and THEN I go out (because it needs the location to trigger). I want it to work the other way around too – if I’m not at home and it gets into my target time window, also turn on the lights.

Also, I don’t understand why the logs show “subscribing” to each of my dimmers/switches. I explicitly marked on the code to never subscribe to those (line 32). On webCORE interface, it shows correctly: Subscriptions: 1 event, 9 controls (the event being my location).

4) Post a Green Snapshot of the pistonimage

5) Attach logs after turning logging level to Full
(PASTE YOUR LOGS HERE THEN HIGHLIGHT ALL OF THE LOGS AND CLICK ON THE </> ICON TO FORMAT THEM CORRECTLY)

12/8/2019, 1:14:11 PM +480ms
+1ms	╔Starting piston... (v0.3.110.20191009)
+264ms	║╔Subscribing to devices...
+279ms	║║Subscribing to Home.mode...
+378ms	║║Subscribing to Switch 1...
+380ms	║║Subscribing to Dimmer 1...
+381ms	║║Subscribing to Dimmer 2...
+382ms	║║Subscribing to Dimmer 3...
+383ms	║║Subscribing to Dimmer 4...
+384ms	║║Subscribing to Dimmer 5...
+385ms	║║Subscribing to Switch 2...
+386ms	║║Subscribing to Keypad 2...
+387ms	║║Subscribing to Outlet 1...
+388ms	║╚Finished subscribing (141ms)
+427ms	║Comparison (time) 47651890 is_between (time) 1575824400000 .. (time) 1575781200000 = true (11ms)
+428ms	║Time restriction check passed
+434ms	║Comparison (datetime) 1575828851910 is_after (datetime) 1575741846469 = true (2ms)
+435ms	║Time restriction check passed
+442ms	║Comparison (string) :xxxxxxx: changes_to (string) :xxxxxxx: = false (1ms)
+484ms	║Comparison (enum) off is (string) off = true (2ms)
+487ms	║Comparison (enum) off is (string) off = true (2ms)
+490ms	║Comparison (enum) off is (string) off = true (2ms)
+493ms	║Comparison (enum) off is (string) off = true (1ms)
+496ms	║Comparison (enum) off is (string) off = true (1ms)
+498ms	║Comparison (enum) off is (string) off = true (1ms)
+501ms	║Comparison (enum) off is (string) off = true (2ms)
+504ms	║Comparison (enum) off is (string) off = true (1ms)
+506ms	║Comparison (enum) off is (string) off = true (1ms)
+517ms	╚Piston successfully started (517ms)

#2

I would create two blocks to account for both scenarios… Something like this:

IF Location changes to away   <-- Trigger
Then
    IF Time is after sunset   <-- Condition
       and
       All switches are off   <-- Condition
    Then
        Turn on Switch 1
    END IF
END IF

Every day at sunset           <-- Trigger
do
    IF Location mode is away  <-- Condition
    Then
        Turn on Switch 1
    END IF
END EVERY

Although, I usually place that last block in my dedicated “Sunset Piston”…


Pro Tip:

I usually would not recommend placing Switch 1 on both line 32 AND 35… but I guess as long as line 32 stays unsubscribed, it should be OK


#3

I had something like this and instead put a boolean in to state if the piston had run yet or not, as well as place that state as a condition. At the bottom of the piston I then also added a random (315AM) time where it would reset that boolean and set this up for the next day.

Might work for you, maybe not, just a thought :slight_smile:


#4

Thank you for the replies.

@WCmore this is a clever solution. You’re basically using analysis on A and B, first using A as trigger then checking B as condition, and further using B as trigger and A as condition. This is probably a better solution for performance than what I ended up doing.
My temporary solution was 1 piston to manage the lights when away and another just to trigger this piston every 15 minutes:

#1


#2

@SergL thanks for sharing. This portion is working fine with my current solution. Everytime I reach the block that I want to run just once, I set my variable to the nextNoon (line 39 on image 1). Then on the beginning, I check if the current run time is after what I set on my variable.


#5

Just to keep here for the records. I ended up going with a slightly modified version, incorporating the idea from @WCmore, but still using 1 piston just as a trigger.
Based on WCmore’s idea, I needed a trigger on the location and another on the timer.

After giving some thought, as I didn’t want to keep my logic in 2 places/blocks, I decided to keep an external caller (almost as making it a function). The idea that I could trigger only at sunset instead of every 15 minutes was well observed and probably gives a better performance.

Why? Details on the logic (for beginners).

If I’m at home before the sunset, my location is Home. Then at sunset, it will trigger the function, but nothing will be done since my location is still Home. If I leave home afterwards, the trigger on Location Mode changed will cause the function’s execution.

Similarly, if I’m not at home before sunset, my location is already Away. Lights would not be changed before sunset. At sunset, the time trigger will cause the function to run.

1st piston, with the logic:

2nd piston, just trigger at sunset: