I have 2 things to overcome, one is to show the date like below:
How can I achieve this? as its not a string and the date updates every day I believe. So the code you gave above I cannot use like we did to find the times of certain teams playing.
Secondly, I have done the following to activate the automation according to the time of the state of the entity. However it doesn’t fire the automation for some reason.
- alias: United Time
initial_state: 'on'
trigger:
platform: template
value_template: '{{ now.time().strftime("%H:%M") == states.sensor.manutd.state }}'
action:
- service: notify.me
data:
message: 'Manutd Playing Now'
Any ideas?
Many thanks for your help buddy.
UPDATE:
Ignore the first part of the obstacle. I need the automation to work but I have a feeling that HA is not recording the time from the text file as time rather its taking it as a number.
Is there anyway I could resolve this? because my automation is testing the current time against the sensor value of ‘Manutd’ and it doesn’t trigger unfortunately.
and when I use value_template: '{{ now.time().strftime("%H:%M") == strptime(states.sensor.manutd.state , “%H:%M”) }}’ it does not work because of the date in the state of sensor.manutd
I should work, does states.sensor.manutd.state give you a text with only ##:## ? I highlighted were the quotes might be wrong as it appear wrong in your last post.
yeah I realised what you were saying but in my config I have got the correct quotes and the automation still does not fire. Did you try it in your dev template ?
I added a time sensor component and got my automation working. This is my automation:
This works but like I mentioned there is a lag of 4-5 seconds before the action is triggered. I cannot work it out why.
But this : '{{ now.time().strftime("%H:%M") == strptime(states.sensor.manutd.state) , "%H:%M") }}' does not work I think its because of the date i.e. 1900-01-01 as the trigger does not match with the now time.
I run the script using cron independent from HA…the output of the script is then saved as a text file and integrated with HA using the file sensor component.