Switch entity takes more time on the first switch

Test hardware (2 different devices):

  • Shelly 1PM gen3 with orig firmware (1.5.1) with official integration
  • Custom ESPHome switch (ESP32) running latest esphome config
  • HA green, HA 2025.4.1
  • connection wifi for both devices.

When you toggle the entity via an automation or from device view, first attempt takes about (feeling) 500ms to actually perform the action (relay toggle) while all immediate clicks/automation toggle the relay instantly. Both hardware act the same, so I assume it is not HW, but rather HA somewhere, somehow.

If you wait about 5 seconds and try again, switch will again take about 500ms to perform the action and all other clicks just after are instant.

Feels like some process starts in the HA backend that is alive for about 5 seconds and then destroys itself if no other command is being received

Is that expected behavior?

This is a gen 1 device. Have you enabled CoIoT as per the documentation?

If not, go to the Shelly’s webpage and configure this:

After pressing SAVE it should behave a lot better.

I have a PM1 with CoIoT enabled and it works responsively and consistently.

EDIT:

Oh wait. Did you flash the PM1 with ESPHome?

If so, ignore all that.

No, I have 2 different HW, one is Shelly 1PM gen3, another is a custom ESP32 with esphome flashed. I have updated the orig post.

The trick is that if you go to device view and start clicking the switch entity to turn it on/off, the first attempt takes longer than any other. It feels to me that there is a “sleep mode” for switch.turn_on action. When you press it first time, it activates itself and then all other clicks are really instant.

After 5 seconds (or so) the task goes back to standby mode.

It could just be the WiFi connection that needs to be re-negotiated.
WiFi is not a lightweight protocol and it has a complicated handshake process that takes time.

If I toggle the input in my esphome device, the binary sensor is instantly visible in the HA and I can see that automation gets instantly triggered.

I dont think it is wifi from that. But I will try Zigbee today, too.

Tested with Sonoff ZBMINIL2. Same thing, the first toggle of the switch takes more time than all subsequent toggle commands in the period of next ~5 seconds. I use Z2M with Sonoff dongle.

I guess it is a normal behavior in the HA context.

Do you have eco mode enabled?

Do you have a single AP your devices are connecting too, or multiple APs?

  1. no eco mode on esphome software
  2. single AP for all devices.

OK, but you also said:

Check if you get the same behaviour with MQTT, if you have a broker.

I took the esphome based device.

automation toggles the output on every off -> on transition

triggers:
  - trigger: state
    entity_id:
      - binary_sensor.pcf_io_expander_test_input_6
    from: "off"
    to: "on"
conditions: []
actions:
  - action: switch.toggle
    metadata: {}
    data: {}
    target:
      entity_id: switch.pcf_io_expander_test_output_6
mode: single

ESPhome input config has 50ms on_off filter:

# Inputs
binary_sensor:
  - platform: gpio
    name: "Input #6"
    pin:
      pcf8574: pcf8574_hub_input
      number: 5
      mode:
        input: true
    filters:
      - invert:
      - delayed_on_off: 50ms
    on_press: 
      then:
        if:
          condition:
            not:
              api.connected:
          then:
            - switch.toggle: switch_6

If I consider filter, it takes more than 300ms from pin going down in reality to toggle the output on the hardware.

Afterwards, every click in series, performs the toggle in less than 100ms (don’t forget that there is 50ms filter before the report time.

And finally, if I reset everything and start again, you can see that:

  • First press → takes almost 500ms for a toggle
  • All subsequent are almost instant
  • If I wait at least 4 seconds, next report is again delayed in the response

1 Like

I have said both because I am testing on 2 different hardware devices and 2 different software/integrations.

  • Shelly 1PM gen3 with official software and official integration
  • ESPhome with ESPhome software and ESPhome integration

Both of them are on the latest versions and both behave the same.

Then, I tried the zigbee Sonoff ZBMINIL2 and I see the same.

Now I don’t know if the issue is in my hardware (HA green) or is this the normal behavior in the HA.