Piston that triggers night mode


#1

Hi everyone

For a while now I have been trying to find an elegant way to program a piston that starts night mode.
I have tampered a bit, but have not found a pleasant solution.

What I want to accomplish is the following:
Every day starting at 11pm I want the system to switch into night mode, AS SOON as there has been 15 minutes of inactivity.

My latest attempt is this:

Any suggestions on how to improve on this piston?


#2

I would try something like this:

IF 
    Motion STAYS inactive for 15 minutes
Then 
    IF
        $hour24 is not between 3-22
    Then
        Set location mode to Night
    END IF
END IF

This way anytime between 11:00PM and 2:59AM when the motions are inactive for 15 minutes, it will switch to Night mode. No looping required.

(Don’t use this method though if you have another Mode you use for Sleeping)


#3

I had something similar initially and correct me if im wrong, but it didnt quite work for the following reason:

Say people go to bed really early on a given evening and the last movement happens at 10.20pm. Then at 10.35pm the piston will trigger, however since its not past 11pm yet the piston will not fire and night mode will not be enabled unless someone goes to the bathroom at night and triggers motion again.


#4

That is correct - always a corner case waiting to get you, and that’s one of them. A simple workaround would be to have two conditions to trigger the actions, by inserting the bold text below:


#5

That looks good.
I have implemented it accordingly and will be looking forward to trying it out.

Thanks so much!

Edit: Your suggestion said “Time happens daily at” - thats different to my line 22, isn´t it? Action vs Condition?


#6

Yes, “time happens daily” is a Trigger and will force your piston to run every day at the time selected. Your time statement in line 22 is a Condition - meaning it’s evaluated when something else in the piston causes it to run.


#7

I am at a loss as to how to implement the above part then. “IF” requires a condition, not a trigger, doesnt it?


#8

Try importing this code and starting with it? Just change the bulb switch to your motion sensor’s motion - I didn’t have one available to select.


#9

Oh now I see how you did it! :slight_smile:
Ok I got it now, thanks for helping me implementing it. I will report back incase there are hiccups, but it looks like it should work perfectly now!