I am trying to write a script and I need the time delta since a sensor.state has been updated. For that I need the current time in the same timezone as the sensor update, which I believe is UTC.
The first one does not seem to work in a script: now = hass.util.dt.utcnow()
gives Error executing script: Not allowed to access HomeAssistant.util
The second option gives me a time in str format, not a timestamp so I cannot subtract. And I am also not able to slice the string using [:2] or so. Can anyone help me?
[edit]
What I need it for? I want to start the exhaust fan of the bathroom a minute after the boiler status has changed to HW (hot water)
Somehow relative_time did not give me reasonable results, and due to the formatting I was not able to do math (gave me 19 seconds <== including the seconds).
Why I do this? Because my boiler sends a “Hot Water” signal once per hour, maybe to keep a small amount of water hot. I don’t want the fan to start running for that reason. I have another automation that activates on high humidity. It could have been combined but this was easier
I am using a Nefit heater/boiler combo in combination with a Nefit Easy thermostat. These models are sold in the Netherlands and I believe also in Germany.