Delay in switch statuses

Hello,

I have a question about about switch statuses
I have a lot of switches, and In my automation I use this

if:
  - condition: state
    entity_id: input_boolean.heater_attic
    state: "on"
then:
  - data: {}
    target:
      entity_id:
        - switch.floorheating_upstairs_valve_1
    action: switch.turn_on

when this switch is turned on, another switch should also turn on.
so later on in the same automation I use this

if:
  - condition: or
    conditions:
      - condition: state
        entity_id: switch.floorheating_upstairs_valve_1
        state: "on"
      - condition: state
        entity_id: switch.floorheating_upstairs_valve_2
        state: "on"
      - condition: state
        entity_id: switch.floorheating_upstairs_valve_3
        state: "on"
      - condition: state
        entity_id: switch.floorheating_upstairs_valve_4
        state: "on"
      - condition: state
        entity_id: switch.floorheating_upstairs_valve_5
        state: "on"
then:
  - data: {}
    target:
      entity_id: switch.floorheatingpump_upstairs
    action: switch.turn_on

but for some reason when in step 1 the switch is turned on, still in this last step the condition returns false.

all switches are on esphome devices,
could it be that HA needs some time to update the switch statuses and my steps in the automation are executed sooner then that? or am I missing something obvious?

Most likely unrelated but you can put all the five valve entities in a group and you only need to use one entity in the if condition.

1 Like

Yes. The action to turn the switch on is a request to the device to turn the switch on. Once it turns the switch on the updated state will be sent to HA, or if the integration uses polling on the next cycle. The process takes time. For a zwave switch it’s typically 100ms (time between initiating the action and the state being updated). So yes, if you turn the switch on and check its state immediately it’ll always be off. You can wait for the switch to updates using a wait template, or determine how long to delay for empirically and delay.

The other option is to use a demand driven approach as I think you are trying to turn the pump on if any of the valves are on? Create a sensor template that counts the number of “on” switches. Write an automation that turns the pump on or off based on the value of this template being non-zero or zero.

1 Like

thnx,
this is clear, for now I added a timer delay because that was the easiest. I needed to be sure about the root cause of the issue.

There are a lot of ways to resolve this.
at the moment I’m using 2 4Channel switches. I’m thinking about replacing those with 1 6channel(I only need 6realys) and then move the logic for controlling the pump to esphome.

for now I’m not going to do that, but it’s nice to know this is a possibility

Instead of a delay try putting this between your switch turn on and the if statement:

- action: homeassistant.update_entity
  entity_id: switch.floorheating_upstairs_valve_1
1 Like