I then have two automations. One sets the rain delay helper as soon as is_wet(none). The other unsets the helper after not is_set(none) for two hours.
Is there a better way of implementing this in general? It doesn’t seem like it will work correctly upon HA restart because the template triggers need to “change”. I can add a separate automation for restart, but it seems a bit clunky and like I’m fighting against the system to get the behavior I want.
I added the unused parameter because it seems like as_functionrequires the macro to have a parameter besides the returns parameter. Is this right?
Hi,
Your use of macros is very strange in the way you define it, use it, why you use it in the first place and how you think it should help with the delay. Is this something AI came up with? AI is no good for any of HA configuration.
So the template sensor is very nearly working (I think), but when I first restart the sensor becomes Unknown rather than Off. I think this is because of the delay_off. Is there any way around this? If not, I can probably just treat Unknown as synonymous as Off.
Yes, macro’s return strings. you can use to_jason and from_json to get around it or test for a specific string if you want. Both I and other replies suggested to create a binary sensor from the result. A binary sensor can be used as many times as you like. It is, in a sense, replacing your macro. That is why I suggested to not use macros at all.
I don’t think any of the delay options will survive a restart. I think you’d need to change to a trigger-based template sensor (without using the delay options) for more control and to achieve a persistent state.
So I’m still doing some testing, but actually it does seem like the template sensor survives a restart! It is only during the initial delay_off period that it shows as Unknown.
The issue is that if you are, for example, one hour into the 2-hour delay period and then perform a restart, the delay will have to run the full 2 hours once HA starts back up again.
You are right, it only resets after 2 hours in case HA is restarted. But that is not too bad. My original solution I think could get stuck indefinitely in the wrong state waiting for a state change.