Disable action toggle start home assistant (toggle switch with esp8266)

Hi,

I’m trying to make a fysical switch connected to an esp8266 to switch a light.

I works, but when I restart homeassisant, it also toggles the light. Any idea how to solve it, or is there a better way to get this switch to toggle ?

- alias: "light switch 0"
  trigger:
   - platform: mqtt
     topic: /Buitenverlichting/swschuur/Switch
     payload: '0'
  action:
     service: switch.toggle
     entity_id: switch.schuurverlichting

- alias: "light switch 1"
  trigger:
   - platform: mqtt
     topic: /Buitenverlichting/swschuur/Switch
     payload: '1'
  action:
     service: switch.toggle
     entity_id: switch.schuurverlichting

Yes, if you omit the mqtt payload in the trigger, it triggers on every state change.
So you need just one automation.
Don’t know if this helps for the restart problem.

- alias: "light switch toggle"
  trigger:
   - platform: mqtt
     topic: /Buitenverlichting/swschuur/Switch
  action:
     service: switch.toggle
     entity_id: switch.schuurverlichting
1 Like

Ok that is also working with one automation , but still when restart hass.io , the light goes on

I’m guessing that your mqtt device is publishing with the retain flag set, so when Hass starts it subscribes to the topic, gets a message delivered, and triggers the automation to toggle the light from off to on. You’ll need to change that code on the device and also use mosquitto_pub to publish a null retained payload to that topic to clear the current retained message.

1 Like

That could be the problem, I set the retain in espeasy, also checked it out, but it’s also stiil than in hass.io?, I must publish null, mosquitt_pub with the -n -r options?

moquitto_pub -h 192.168.x.x -t /Buitenverlichting/swschuur/Switch -n -r -d

Correct. The -r option sets the retain flag and the -n option sets a null payload.

thnx, that solved the issue, now it works as expected