Manual MQTT switch

Hi there,

I’m trying to setup a switch in Home Assistant that publishes its state to other devices. The idea is that some ESPHOME devices subscribe to this switch and if is it turned on they stay up when they wake up.

I got it to work at some point but with my new installation, I can’t get it to work anymore and can’t find my previous setup :slightly_frowning_face:

Could someone give me a few pointers on how to do it? I’ll try to dig to set it up.

Here are a few configurations:

unique_id: esp12f_ht_ota
name: "esp12f-ht OTA Mode"
icon: "mdi:upload"
state_topic: "esp12f-ht/ota"
retain: true

I am using

  • Home Assistant 2023.9.3
  • Supervisor 2023.09.2
  • Frontend 20230911.0 - latest

Thanks

I had some leftovers from previous configurations. After removing them, I could get it to work with the following in my /config/configuration.yaml:

mqtt:
  switch:
    - unique_id: esp12f_ht_ota
      name: "esp12f-ht OTA Mode"
      icon: "mdi:upload"
      state_topic: "esp12f-ht/ota"
      command_topic: "esp12f-ht/ota/set"
      payload_on: "ON"
      payload_off: "OFF"
      state_on: "ON"
      state_off: "OFF"
      optimistic: true
      qos: 0
      retain: true

I followed the example from here: