Enter zone trigger if I come back later than 45 minutes

I have a trigger state node that says if my current state is ‘home’, and the previous state was not ‘home’ it will do my automations.

How do I add another condition that says trigger if i was not ‘home’ for more than 45 minutes?

Perhaps this?


I currently have it using the trigger: state node due to other conditions I want running (sometimes if my tracker goes offline while I’m home, it will run upon reconnection, so I set a condition where the last state has to be ‘not_home’).

How do I set a time condition using trigger:state?

I do not know how you could add a third condition in the trigger state node to check a not home for time. It is expecting an entity state to change.

But you could add an events node to check the last time the state changed. See here:

You could set the events: state node to trigger after 45 minutes, then use a ‘wait until’ node. Or the ‘get history’ node will tell you the recent states with timestamps.

This is a bit tricky but entirely possible.

Every time a state changes, the HA event bus has both the new (ie now current) state and the previous (ie old) state together, and importantly it also has the timestamps for both.

This information is picked up by the Home Assistant WebSocket nodes at each state-change, and can be used to add the condition I think you are looking for. Based on the idea that we are looking to say

  • current state is now ‘home’
  • previous state was not ‘home’
  • timestamp for previous state change is more than 45 minutes ago

then we can add a condition to test for the timestamp of the old state, when it was last changed, being earlier in time than 45 minutes ago.

I tested the following using a switch entity, and a simple test for 3 minutes as follows. It works.

I am testing a switch, and for being ‘off’ more than 3 minutes. The first two debug outputs are ‘off’ and then ‘on’ just 2 minutes later, and the test fails on 1 comparator (which is the time test).
Then ‘on’ - clearly fails on all three.
Then ‘off’ 5 minutes later, and it passes so message output to the top.

The JSONata in the test uses $millis() to get now in Unix milliseconds, and I subtract 3 minutes (I use 3*60000 as it makes it easy for me to adjust and work in minutes rather than milliseconds). Then $fromMillis() turns it back to a string timestamp, which can be compared against the property ‘old_state.last_changed’.

I have no idea how the node gets the property list, but in trying to process the auto-complete dropdown there must be so much going on that my Node-RED freezes when I try to type into this UI field, so I suggest copy-paste in one go.

Just change the ‘3’ to ‘45’ and this should work.

I created a node with a switch with time since last changed checking on a state status. Which works, but I just had to make a subflow with it.
Screenshot 2023-12-30 002341