X time before sensor in template

Hi, I have an automation triggered by time matchine a time sensor, which works:
trigger:
- platform: time
minutes: ‘/1’
seconds: 0
condition:
- condition: template
value_template: ‘{{ now().strftime("%H:%M") == states.sensor.curtain_timewe.state }}’

However I can’t figure out how to make this trigger activate for example 5 minutes beforehand.
I’ve tried this, which isn’t working:

  value_template: '{{ (as_timestamp(now().strftime("%H:%M") + 60)) == states.sensor.curtain_timewe.state }}'

Could anyone please point me the right direction? Thanks!

Try:

value_template: >
  {{ (as_timestamp(now())+300)|timestamp_custom('%H:%M') ==
     states('sensor.curtain_timewe') }}

Thanks for the help :slight_smile: however this:
value_template: ‘{{ (as_timestamp(now())+60)|timestamp_custom(’%H:%M’) == states.sensor.curtain_timewe.state }}’

Is giving me:
ERROR:homeassistant.util.yaml:while scanning for the next token
found character ‘%’ that cannot start any token
in “/home/homeassistant/.homeassistant/configuration.yaml”, line 1090, column 70

error

EDIT: AH! I needed to use double not single quotes in the custom timestamp. Thanks for getting me there :slight_smile:

1 Like