Automation with time trigger from sensor

Hi All,

Finally have my HA up and running and am getting going with automations… and hit a snag-
I have a sensor that has timestamp that changes once a week as its state. I can read it and use it’s state in a notification - {{ states.sensor.incoming_time.state } - but how would I use this as a trigger in an automation?


You’ll need to be a bit more explicit about when you want the automation to trigger. When sensor.incoming_time changes? When it’s value is compared to something else? …?

The sensor is updated once a week on Saturday from an external api in a python script. I want to trigger the automation one hour before the time that appears in the sensor, say on Tues… If that makes sense.
So, in theory, what I think I’m looking to create is
platform: template
data: ((when current time is equal to the sensor’s time with offset of - 1:00:00))

Yes, that makes sense.

First you’ll need to enable sensor.date__time (which is the 'date_time' option.)

Next your trigger should look like this:

  platform: template
  value_template: >
    {% set s = states('sensor.incoming_time')|float - 60*60 %}
    {{ (s|timestamp_local).rsplit(':',1)[0].replace(' ', ', ') ==
       states('sensor.date__time') }}

Assuming sensor.incoming_time is a “normal” Unix Epoch timestamp, this should work.

EDIT: Oops, forgot the “one hour before” requirement. Updated trigger above accordingly.

1 Like

works like a charm. thanks @pnbruckner!