Recent update to MQTT Switches not working

Hi All,

I have a rasp pi w with a 4 relay board on top of it to run a sprinkler control interface.
In the pi I loaded a MQTT python script that receives the commands from Homeassistant to turn on and off the switches.
I was in a phase of testing it before replacing my disconnected rainbird system and installing it in place when there was an update to the homeassistant. After the update there was a message asking to fix some things on my MTQQ switch configuration.
I had it like this:

switch:
  - platform: mqtt
    name: "Sprinkler 1"
    state_topic: "home/sprinkler/valve1/get" 
    command_topic: "home/sprinkler/valve1/set" 
    qos: 2 
    payload_on: "on"
    payload_off: "off" 
    retain: false 
  - platform: mqtt
    name: "Sprinkler 2"
    state_topic: "home/sprinkler/valve2/get"
    command_topic: "home/sprinkler/valve2/set"
    qos: 2 
    payload_on: "on" 
    payload_off: "off"
    retain: false 
  - platform: mqtt
    name: "Sprinkler 3"
    state_topic: "home/sprinkler/valve3/get"
    command_topic: "home/sprinkler/valve3/set" 
    qos: 2 
    payload_on: "on"
    payload_off: "off"
    retain: false  
  - platform: mqtt
    name: "Sprinkler 4"
    state_topic: "home/sprinkler/valve4/get" 
    command_topic: "home/sprinkler/valve4/set"
    qos: 2 
    payload_on: "on"
    payload_off: "off"
    retain: false 

With this config, I had 4 entities of MQTT switches created and activated from my dashboard. You can see the image below is with the new configuration and there is only one active MQTT switch.
image

After the update it is like this now.:

mqtt:
  switch:
    unique_id: sprinkler_1_sw
    object_id: sprinkler_1_sw
    name: "Sprinkler 1"
    state_topic: "sprinkler_valve1/get" 
    command_topic: "sprinkler_valve1/set" 
    qos: 2 
    payload_on: "on" 
    payload_off: "off" 
    state_on: "on"
    state_off: "off"
    optimistic: false
    retain: false  # or false if you want to wait for changes
  switch:
    unique_id: sprinkler_2_sw
    object_id: sprinkler_2_sw
    name: "Sprinkler 2"
    state_topic: "sprinkler_valve2/get" 
    command_topic: "sprinkler_valve2/set" 
    qos: 2 
    payload_on: "on" 
    payload_off: "off"
    state_on: "on"
    state_off: "off"
    optimistic: false
    retain: false  # or false if you want to wait for changes
  switch:
    unique_id: sprinkler_3_sw
    object_id: sprinkler_3_sw
    name: "Sprinkler 3"
    state_topic: "sprinkler_valve3/get"
    command_topic: "sprinkler_valve3/set"
    qos: 2 
    payload_on: "on" 
    payload_off: "off"
    state_on: "on"
    state_off: "off"
    optimistic: false
    retain: false  # or false if you want to wait for changes
  switch:
    unique_id: sprinkler_4_sw
    object_id: sprinkler_4_sw
    name: "Sprinkler 4"
    state_topic: "sprinkler_valve4/get"
    command_topic: "sprinkler_valve4/set" 
    qos: 2 
    payload_on: "on" # defined by your device
    payload_off: "off"
    state_on: "on"
    state_off: "off"
    optimistic: false
    retain: false # or false if you want to wait for changes

It’s interesting that always just the last switch loaded in the configuration.yaml works, not all 4 switches.
If I remove the 4th switch from the list, the 3rd will work.

Can anyone guide me to a solution to this issue?

get rid of all the extraneous “switch:” entries. you only need one.

mqtt:
  switch:
    - unique_id: sprinkler_1_sw
      object_id: sprinkler_1_sw
      name: "Sprinkler 1"
      state_topic: "sprinkler_valve1/get" 
      command_topic: "sprinkler_valve1/set" 
      qos: 2 
      payload_on: "on" 
      payload_off: "off" 
      state_on: "on"
      state_off: "off"
      optimistic: false
      retain: false  # or false if you want to wait for changes
    - unique_id: sprinkler_2_sw
      object_id: sprinkler_2_sw
      name: "Sprinkler 2"
      state_topic: "sprinkler_valve2/get" 
      command_topic: "sprinkler_valve2/set" 
      qos: 2 
      payload_on: "on" 
      payload_off: "off"
      state_on: "on"
      state_off: "off"
      optimistic: false
      retain: false  # or false if you want to wait for changes
    - unique_id: sprinkler_3_sw
      object_id: sprinkler_3_sw
      name: "Sprinkler 3"
      state_topic: "sprinkler_valve3/get"
      command_topic: "sprinkler_valve3/set"
      qos: 2 
      payload_on: "on" 
      payload_off: "off"
      state_on: "on"
      state_off: "off"
      optimistic: false
      retain: false  # or false if you want to wait for changes
    - unique_id: sprinkler_4_sw
      object_id: sprinkler_4_sw
      name: "Sprinkler 4"
      state_topic: "sprinkler_valve4/get"
      command_topic: "sprinkler_valve4/set" 
      qos: 2 
      payload_on: "on" # defined by your device
      payload_off: "off"
      state_on: "on"
      state_off: "off"
      optimistic: false
      retain: false # or false if you want to wait for changes

Awesome @finity !! Really appreciate the help. Small miss on my side.
It’s all working now!

1 Like