Sonoff binary sensor change lost during HA restart

I have had a problem with Home Assistant showing the same state for a sensor (a binary humidity sensor connected to gpio14) for several hours, which wasn’t the behaviour I expected

When I checked it was indeed showing the wrong state; when I manually toggled the switch a couple of times it started to report the correct state in HA

What probably happened is that the switch changed its state while HA was restarting and it missed the change as the sonoff only publishes the state of a sensor when this changes (but HA and mqtt were busy restarting)
Is there a way to avoid that?

No one has got this issue or thought about this?

I also have this issue and only found this post when I searched for a solution.
Anyone out there know how to get around this problem?
I was wondering how to restart the sonoff on (or just after) a HA restart…anyone know how to do that?

Publish a cmnd/sonoff/restart on HA start

1 Like

Cheers @francisp Via an automation in HA?

Something like this

- id: '1565194745362'
  alias: Status bij opstarten HA
  trigger:
  - event: start
    platform: homeassistant
  condition: []
  action:
  - data:
      payload: ''
      topic: cmnd/Qia/restart
    service: mqtt.publish

1 Like

@francisp Cheers!
Will do some testing and report back how it goes!

EDIT: The automation triggers but does not restart the sonoff…So instead of hijacking this post I have detailed my steps to try to solve this problem here