I have a template that outputs time as 06:11. I would like to convert it to timestamp so I can use it as a trigger.
TIA
In that case, you will need to create a Template Sensor that reports a datetime string in ISO 8601 format and has a device_class
set to timestamp
. That’s what a Time Trigger expects if you want to use it with a sensor
entity.
Reference
If you want my help, I need to see the template you created.
I am making an API call and using this template to extract the time.
{{ state_attr('sensor.prayer_times', 'data' )['timings']['Fajr'] }}
And output of the template is just a string like 06:01
. And I would like to change to a timestamp.
I recommend you use a Template Trigger in your automation. It’s as simple as this:
alias: example
trigger:
- platform: template
value_template: >
{{ now().strftime('%H:%M') == state_attr('sensor.prayer_times', 'data' )['timings']['Fajr'] }}
condition: []
action:
... your actions go here ...
This should work fine. Thank you so much for pointing me in the right direction
1 Like