I’m changing the way I schedule my pool heater start time, mainly because the date & time chooser in the UI is so bad.
My planned approach will be to select either “today” or “tomorrow” via an input_select entity, then a time of day via time-picker-card. I have a few lines of Jinja to get the day and time, then combine them… but it’s giving me issues, and I’ve traced it down to one line.
Why would the value of the swim_time variable be 0 here if input_datetime.pool_target_temp_time2 = 20:00:00?
Because you’re trying to force a datetime object to look like a number. The float filter does not recognise the state of the input_datetime as a number, because it isn’t, so it returns zero.
Have a look at the two helpful links on the template editor page, particularly the TIME section of the HA link.
The replacement of date() in place of the strftime function worked, as did the elimination of the float filter… but the if-else statement changed the resulting timestamp from tomorrow afternoon to sometime in the 1970s
Well, yes. I turn here as a last resort. I’d much rather know enough to get it right the first time than struggle with it and have to ask why it’s not working. I want at least to try a few things and say, “I tried this and this and I’m not getting the result I expect,” instead of just, “how do I do this?”
In this case, the template was intended to do this:
today plus (0 if we want today, otherwise 86400)
…which would give midnight at the beginning of today, or midnight at the beginning of tomorrow — 86400s is the length of most days, leap seconds/years ignored.
With the originally-missing parentheses, it was being calculated as this:
(today plus 0 if we want today), otherwise 86400
UNIX timestamps are seconds since the start of 1-Jan-1970, so a timestamp of 86400 is midnight at the start of 2-Jan-1970.