I am trying to create an automation to trigger ahead of a certain time that I set. I have the following config, but the automation won’t trigger even though I have verified that {{ (as_timestamp(now()) + states.sensor.seconds_in_advance.state | int) | timestamp_custom("%H:%M") == states.sensor.warm_time.state }}
does in fact return ‘True’ or ‘False’.
This will never be true. Now is always right now and you are adding to it. If you add to now, it will always be moving the amount you have in the future, thus never reaching it.
A simple solution to this is to subtract your seconds_in_advance from your warm_time. Then, you just check to see if now is equal to warm_time. This of course, assumes warm_time is in the future.
Thanks for the feedback. I did try input_datetime a while ago, but found it difficult to use because it also includes date when I only need the time. Omitting the date part of it never worked for me, so I stuck with my previous time/string setup which works well in other automations.
This will never be true. Now is always right now and you are adding to it. If you add to now, it will always be moving the amount you have in the future, thus never reaching it.
I can’t really see why not. As I am dealing with only hours and minutes, this should be true when now() + e.g. 600 seconds formatted into HH:MM is equal to my warm_time (also expressed as HH:MM). When I try it out manually in the UI templates section of HA, I get the value ‘True’ when I add the number of seconds that is equivalent to the delta between now() and the future time (warm_time). It should be true until now() skips to the following minute. If it was comparing the whole time value, I could understand that it could only be true at a very small fraction of a second.
I wanted to do it the other way around at first, but I couldn’t find out how to convert my warm_time (HH:MM) into a time value, from which I could subtract the required amount of seconds to arrive at the trigger time.
Ah ok, I miss understood what you were doing. You may need to trigger this every minute with the value_template in the condition.
I don’t know if the trigger will actually evaluate periodically with the value_template in the trigger. It may be looking for a state change, and if the only object that you have that ‘updates’ in your value_template is states.sensor.warm_time.state. So I could see this only evaluating when that state changes.
Right, but you have 2 sensors that are updating states. state updates initiate the trigger. now() is a datetime object that does not contain the required home assistant properties to make a trigger. datetime is inherit in python. So the trigger is going to ignore that and look at the only thing that changes state, states.sensor.warm_time.state.
That could be the case, but I doubt that it’s anything significant if you have a rpi3. Seeing that all of your seconds_in_advance are in increments of 10 minutes, you could just run it every 10 minutes. That would only be 144 checks a day.