MQTT switches and lights are not persistence

I added this automation to get the state of sonoff switches when Home Assistant loads up:

- alias: "Power state on start-up"
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: mqtt.publish
      data:
        topic: "cmnd/lamp/POWER"
        payload: ""
    - service: mqtt.publish
      data:
        topic: "cmnd/porchlight/POWER"
        payload: ""

Now when I restart HA, it knows the state of the switches from the MQTT request for an update.

2 Likes