Restart button falshes light

Hello,

In my ESPHome I have a restart button like this.

button:
  - platform: restart
    name: "${device_name} switch Restart"

but when I press it while the light is on, it toggles off and on again.
I don’t want this to happen, and rather maintain the state without any flashes.

what light?

Good question :bulb:

If your light is connected to a relay you can try to re-wire it to NC (normally closed) and invert the pin for the relay in your esphome yaml. :pencil2:

The “problem” is that when your esp restarts it is not in control of the GPIOs for a short amount of time :timer_clock:

good question,
the one from this binary switch

output:
  - platform: gpio
    pin: GPIO12
    id: relay_1

light:
  - platform: binary
    name: ${switch_name}
    id: light_1
    output: relay_1
    on_turn_on:
    - light.turn_on: stat_led
    on_turn_off:
    - light.turn_off: stat_led

that would also invert the problem, so when the light is off, it will flash on,
besides the fact that my hardware skills aren’t good enough.

That makes sense to me, but not being in control would mean it should remain the status is has. Now it’s actively turned off by ESPHome(I think).

At least if I compare with Tasmota(I know, I do this a lot), those devices I can reboot/update/modify and none of the relay statuses gets changed.
At that point I’m able to update them without my wife complaining about the flashes.

ok,
I did some tests between tasmota and esphome
esphome devices flash on a reboot, off/on
tasmota devices do not.

For both count, pulling the pcb from the actual switch means the switch turns off.
but when putting this back, the tasmota device immediately remembers the state and turns on the switch.
where ESPHome restores to default.

Which leads me to the conclusion that Tasmota remembers the state after a powerloss(probably saves the state on flash) where ESPHome doesn’t.

This might has something to do with my issue of else this is a different one I’m facing.

It could also be that tasmota reboots faster, or does not fully reboot so it can maintain the switch statuses.

have you tried enabling esp8266_restore_from_flash ? (if it is an esp8266 you are using)

1 Like

Actually esp8285

so I have this

esp8266:
  board: esp01_1m
  restore_from_flash: true

in some other place I use

board: esp8285

And I don’t know the difference, I assume it’s the same.

But adding restore_from_flash: true doesn’t make any difference in behavior
I would assume I need to apply some setting like persistent: true to a switch or outlet,
but can’t find that in the documentation.

Just found this page, you could try early_pin_init: false

I just added it to a plug I have that clicks off-on on firmware update and this has stopped it doing that

1 Like

unfortunately still the light flashes, also I can hear the clicks

esp8266:
  board: esp01_1m
  restore_from_flash: true
  early_pin_init: false

maybe it’s because I use light component instead of switch
if I have some time later I will setup a test using the switch component instead

Ok,
I did some tests and found what I need thanks to the suggestions above.
first of all early_pin_init does not seem to apply to light component, only to switch, so changing to switch does the trick for me,
Maybe this could be improved in ESPHome but for now switches are ok for me. Also I like the direct pin assignment of switches

Regarding restore_from_flash this actually works, but I needed to take the 1 minute interval into a count.

this is something I didn’t do during testing. Maybe I will disable this feature later, I think tasmota doesn’t have this one, so that’s why it always immediately restores to the previous version.

my full config for debug now is like this.

substitutions:
  device_name: esphome-debug
  switch_name: debug light

esphome:
  name: ${device_name}

esp8266:
  board: esp01_1m
  restore_from_flash: true
  early_pin_init: false

packages:
  base: !include base.yaml

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode:
        input: true
        pullup: true
      inverted: true
    id: button_1
    on_press:
      then:
        - switch.toggle: light_1

switch:
  - platform: gpio
    pin: GPIO12
    name: ${switch_name}
    id: light_1
    on_turn_on:
    - light.turn_on: stat_led
    on_turn_off:
    - light.turn_off: stat_led
light:
  - platform: status_led
    id: stat_led
    # name: "Switch state"
    pin:
      number: GPIO13
      inverted: yes