Use "x minutes ago" value in condition

I was thinking if it would be possible to use the value “x minutes ago” to trigger automations. For instance, I want to set an automatic vacation mode, where the light would simulate my presence in case I’m on vacation, such as turning on lights at sunset. But I might come home after sunset (especially during the winter) so I don’t want to be wasting electricity for 1h before I come home. However, if I haven’t been home in 24 hours, chances are that I’m actually away. So on my 2nd day being away, I would like the “vacation” automation to kick in.

Any possible service to user this value?

Thank you for your inputs!

You can do calculations with with templates, like

'{{(as_timestamp(now()) - as_timestamp(states.binary_sensor.bedroom_motion.last_changed) < 1800)}}'
2 Likes

@fabaff - I see how to use calculations to solve @pbocsak issue but could you show this in a sample config?

Just put it as value_template: in a template sensor.

This thread might help…

I know that you can use ‘for’ as a condition which would work in your case I believe.

platform: state
      entity_id: sensor.motion_sensor
      to: 'on'
      for: 
         hours: 24