Thought this rule makes sense and should work but does not turn off a switch. Can anyone see what i am missing? The idea being that if a motion sensor has not been triggered between set times it turns off a switch (that was previously turned on)
When Kitchen_PIR motion stops and stays inactive for 55 minutes ...
Turn off switch_X
Rule and pending actions can run ...
Only between 03:00 and 04:00
I wonder if it needs motion to have occured then enter the stopped (inactive) state, i.e. being inactive at 3am and remaining that way would not include a transition to the inactive state.
You might need to think / explain a little more about how you need it to work in each of these situations:
No motion at 3am and no motion ever triggered between 3am - 4am
No motion at 3am, motion triggered and deactivated between 3am and 4am
Motion active at 3am and becomes inactive between 3am and 4am
There's be a few more permutations, but hopefully you get the idea.
i did wonder if it needs a "motion sense" before hand to initiate the rule.
The requirement is: if there is no human-presence (motion) within a time window (example = 3am -4am) a switch (will be the heating system once rules/code proved ok) gets deactivated.
The end goal being, if no-one is about during a particular time the heating gets turned off (to save energy)
hopefully that clarifies a valid practical scenario.
I'm sure there's other methods i have not thought of that you guys can suggest, so thanks in advance.
If you use Rule Machine you can use Wait for Expression which looks at the state rather then waiting for an event. So, if motion is inactive at 3:00 (or goes inactive between 3 & 4) and stays inactive for the 55 minute duration then it'll work as intended.
would my time window only need to operate for a few seconds as the conditions of "no motion for 55 minutes" would have been met before the time of which i want this to switch my device off?
Or does the rule get executed after 55 minutes in which case i want it to RUN during a chosen period rather than run after 55mins otherwise it will attempt to execute outside of my time-window?
I don't believe your rule is structured correctly. First, Managed Conditions is a repository where you can create and edit conditions. They do noting unless they are incorporated into one of the Actions to Run. Second, triggers are events and you need to guarantee an event at 3:00 to check the state of the motion sensor. You don't say how the light turns on so I'm assuming there is another rule or it's turned on manually. Here a rule to try.
Define Required Expression
Time between 3:00 AM and 4:00 AM
Select Trigger Events
Kitchen_PIR motion active
OR
When time is 3:00 AM
Select Actions to Run
IF (Kitchen_PIR motion active) Wait for Expression: Kitchen_PIR motion inactive --> duration: 0:55:00
Off: human presence TEST switch
Note that the IF is a simple conditional action and therefore no THEN and END-IF isn't needed.
@pseudonym you are right.
my code didnt work- it executes 55 mins after last motion and not between the set time window.
thinking about it and understanding how HE works kinda see why.
still learning....
the output switch will ultimately be the heating system. The aim being if it detects no-one home (no motion within a time-frame) it turns off the heating (substituted here as "human presence test switch whilst in development) which is usually turned on/off via a timer.
Still new to the game, i am starting to see how the first part of this code may be the answer, thanks to you guys. (i have not yet used "define required expression" in any of my rules before)
The systems won't detect no one being home. It only responds to events. If there isn't a motion active event (no one home) then there won't be a motion inactive event within your time window and your rule won't trigger. Additionally, I believe your "stays that way for 55 minutes" trigger effectively makes your time window 5 minutes. For example, if the motion sensor goes inactive at 3:06 it needs to stay inactive until 4:01. This is outside the Required Expression and will not trigger the rule. In this case, I believe it's better to have to have a Wait with the actions and not the trigger. Please reconsider the rule I suggested to try.
Thanks, @pseudonym for baring with me and helping on this one.
interesting. So the wait command is an option or the solution?
Where would i find "wait with actions"? (another new function i have yet to discover/use)
The initial trigger event is "motion last triggered" + time.
I can get the system to "assume" no one is home by way of having not detected motion for some time. This could initiate a function that i only want to run at a predetermined time of day and check a "no motion" flag. But then i will have to check this at a preset time which may be minutes or hours after the last detected motion.
perhaps i should explain it another way...
Imagine a typical day- the occupants get home from around the same time every evening and the heating is timed to come on a few hours before this time. However, if they do not come home the system turns off the heating (to save energy) assuming no one will be home for the rest of that day.
There is the option of geo-fencing but not everyone carries a device that can trigger this.
Perhaps looking into an actionable notification that will essentially ask the question "Is anyone going to come home....?", allowing for people to choose to turn off the heating / cooling.
Perhaps you should review this documentation. At the end there is a List of Actions that you'll find within Rule Machine.
It's starting to sound like you don't necessarily want to restrict when the rule can trigger but to use a Conditional Action within the rule to turn the switch (heat) off within a certain time window. Either way, I think you need someway to trigger the rule when no one is home. To me that means triggering at a certain time. Additionally, you could use a variable to track whether a door opens or motion is detected within a certain time period and adjust the heat accordingly.
engage a "presence flag" (virtual switch) upon triggering a motion sensor
this flag is switched off after motion has stopped and stayed stopped for 60min
If flag is OFF (required expression), at chosen time (the trigger) deactivate heating system
this will therefore, at the chosen time(s) recognise there has been no presence/motion for at least an hour and then take the required action- in this case shut off the heating.
Thinking about it again.... You could setup a Zone Motion Controller with a long deactivation time. This could take the place of you virtual switch and the need for the first two rules. This zone motion controller device could then be part of the required expression, i.e. it has to be inactive.