I am just a few days into HA on a new install (2020.12 then) and I need some pointers on how to make a template that takes 2 hours from a time (input_datetime) entity and sets a different entity to the result of the computation.
Error executing script. Unexpected error for call_service at pos 1: Error rendering data template:
UndefinedError: ‘input_datetime’ is undefined. While executing automation automation.ny_automation
I appreciate all the help I could get on this (probably something silly is wrong,.,)
This subtracts 2 hours (7200 seconds) from the input_datetime’s timestamp then converts it back to a time string and (displays only the last 8 characters)
Is datetime objects always assumed to be set in UTC? Will that be a problem if I assign the new computed time to a new helper datetime object and use it to define a time trigger?
using the template above, will it then trigger the event at the correct time, or be one hour too late?
(that is 06:00 in UTC which is then 07:00 in local time, if daylight savings is the same, which it may not be)?
When you assign 06:00 to the input_datetime, that’s the time that it will store and the time that will be used by a Time Trigger.
For example, if the input_datetime is to be used as an alarm time for 06:00, simply set it to 06:00 (and don’t concern yourself with time conversions).
Paste the template I provided into the Template Editor and experiment with it. Change the value of input_datetime.nar_ska_bilen_vara_uppvarmd_imorgon and you will see the template produces a time that’s always 2 hours earlier than the input_datetime’s value.