I have an input_boolean.summer_toggle defined to switch my automations from summer and winter mode. All of my climate automations check this to decide what to do.
I have automations that trigger when a window in a room is opened then HA turns the heat off in there and if the window is closed it turns the heat in that room back on.
I also have an automation (Toggle Summer) that triggers directly on that input_boolean.summer_toggle which will turn heating in the entire house on or off depending on the state.
My problem is if a window is open, so the heating in that room is off, then the HA system is reset (like from today’s 2021.4.4 update) then this Toggle Summer automation gets triggered and turns the heat in that room back on while the window is open. Now I could make the Summer Toggle automation check each room with a choose action and only if all windows are closed in that room it will turn the heat on but that increases the complexity by 10x and I’m not 100% confident that as soon as the system comes back the window state will be accurate.
All I really want is that this automation only runs when I manually flip the switch and no other way. Is there a condition I can add to check this?
- platform: template
sensors:
s_ha_uptime:
friendly_name: HA Current Uptime
value_template: >
{% set secs = as_timestamp(states.sensor.time.last_updated) - as_timestamp(states('sensor.uptime')) %}
{% set days = (secs / (24 * 60 * 60)) | int %}
{% set plural = ' days ' if days > 1 else ' day ' %}
{% set hrmn = secs | timestamp_custom('%H:%M', false) %}
{{ days ~ plural ~ hrmn if days > 0 else hrmn }}
but you could just as easily create a binary sensor and use that for multiple automations
Edit: as Marius says below, for your use case this should be VERY rare. I use this on my boiler switch to prevent changes just after a restart, to ensure my sensors are up to date before taking any actions based on those sensor values
using many input_booleans my self to trigger automations, I do not see this at all. Could be you have initial: set on these booleans, and that state is changed during startup?
The whole benefit of the booleans is they survive restarts, preventing this behavior?
Unless I misunderstood you first sentence:
by switch, do you mean trigger, or turn-on/off the automation?
I have the sensor set up any way and the ONLY time it is 00:00 is in the first 60 seconds following the restart so this was just minimum effort. I’m just a lazy bastard !
I think the issue is I need to add from and to. To make it more simple I have no from/to and then use a template of the action to set on or off in the climate. I probably need to add both possibilities.
This triggers when the input_boolean maintains a state (any state) for 30 seconds.
- platform: state
entity_id: input_boolean.summer_mode
for: 00:00:30
Is that the behavior you want?
Was the input_boolean created via the UI or did you define it using YAML? If you used YAML, did you specify an initial_state? (Same question as Mariusthvdb)
Yes because if you look I do an if else in the action, but it is probably also being triggered when the state is already off and its being set again to off, like a restart, which I don’t want. So I added the 2 on/off states as in the 2nd automation I posted.
- platform: state
entity_id: input_boolean.summer_mode
for: 00:00:30
does not behave the same way as this:
- platform: state
entity_id: input_boolean.summer_mode
from: "off"
to: "on"
for: 00:00:30
- platform: state
entity_id: input_boolean.summer_mode
from: "on"
to: "off"
for: 00:00:30
The second example looks for a state-change from one value to another and then that new value must persist for at least 30 seconds.
The first example doesn’t need a state-change. It simply requires any state to persist for at least 30 seconds. Restart Home Assistant, the input_boolean is restored to its previous state, that state remains unchanged for 30 seconds, and that’s sufficient to cause it to trigger.
Right, that’s why I made the change. I didn’t realize a restart of the server does indeed trigger state changes, just the “change” is still the same state.
Either you didn’t express your thoughts properly or you misunderstood my explanation because that’s not what is causing the first example to trigger.
The input_boolean’s state value remains the same as it was prior to the restart. The first example’s State Trigger isn’t concerned with state-changes, it simply requires a state to persist for 30 seconds (and that countdown begins at startup because the State Trigger starts fresh on startup).
Ok, so are you saying had I not had that 30 second timer, it wouldn’t have triggered on the restart? That timer is there just incase I fat finger the toggle and I don’t want to ever accidentally turn it on/off.