MQTT Multiple Switch Issue

Hi Forum!

Been running Home Assistant for almost a year now and have a pretty basic setup of network and weather details. My main usage for Home Assistant was to monitor my front porch light and my garage door. I have an MQTT sensor for my front light, and another for my door. In addition I have an MQTT switch with I use to trigger a momentary switch to cause my garage door to open/stop/close depending on what it’s doing. (Door opening/closing is controlled separately to detecting open/closed state)

Recently I decided to investigate adding an ESP8266 MQTT RGB LED strip to Home Assistant to see if I could look at some funky lighting. This website is pretty much bang on what I did with the hardware: https://eryk.io/2015/10/esp8266-based-wifi-rgb-controller-h801/ but with the code base being built pretty closely to https://github.com/mertenats/open-home-automation/tree/master/ha_mqtt_rgb_light

What I found with Home Assistant 0.41 is that after I’d used the RGB LEDs my Raspberry Pi would lock up and require the power to be pulled to restart it. I attributed this to maybe my Raspberry Pi just being slow and adding the RGBs was the straw that broke the camel’s back.

Since upgrading to 0.42 that error has gone away and I’m now facing a new issue. I can either use the MQTT switch to control my garage door, or I can use it to control the RGB LEDs, but I cannot have both systems working at the same time. Depending on which device I try and use first, after restarting Home Assistant, that will determine which device will function.

I’m using the build in MQTT broker for Home Assistant and my topics are:

  • platform: mqtt
    name: ‘Bedroom RGB light’
    state_topic: ‘bedroom/rgb1/light/status’
    command_topic: ‘bedroom/rgb1/light/switch’
    brightness_state_topic: ‘bedroom/rgb1/brightness/status’
    brightness_command_topic: ‘bedroom/rgb1/brightness/set’
    rgb_state_topic: ‘bedroom/rgb1/rgb/status’
    rgb_command_topic: ‘bedroom/rgb1/rgb/set’
    brightness_scale: 100
    optimistic: false

  • platform: mqtt
    name: ‘Bedroom White light’
    state_topic: ‘bedroom/w1/light/status’
    command_topic: ‘bedroom/w1/light/switch’
    brightness_state_topic: ‘bedroom/w1/brightness/status’
    brightness_command_topic: ‘bedroom/w1/brightness/set’
    brightness_scale: 100
    optimistic: false

  • platform: mqtt
    name: “Toggle Garage”
    state_topic: “switch/garage/door/status”
    command_topic: “switch/garage/door/set”
    payload_on: “ON”
    payload_off: “OFF”

I’ve got the Toggle Garage switch in my switches.yaml file and my RGB LEDs in my lights.yaml file.

Has anyone experienced an issue like this with MQTT and Home Assistant? I have a bit of a feeling that it might be because my topics don’t start with the same top level name (switch/bedroom) but I’m not actually sure if that’s a requirement with MQTT.

I’m happy to provide my full code for analysis (both Home Assistant and my ESP8266/Arduino code).

Thanks heaps if anyone has any ideas! (FYI the LEDs look wicked when they work)

Kyle.

1 Like

I’m having the same issue. One thing I found and tried was using a unique client name for each ESP board.

WiFiClient espCLEDmain;
PubSubClient client(espCLEDmain);

WiFiClient espCLEDexp;
PubSubClient client(espCLEDexp);

That doesn’t seem to have solved my problem though.
If you figure it out please post. I’ll keep searching for the solution myself as well.

1 Like

Did anyone find a solution for this problem yet? I have two mqtt_json lights and can only operate one of them at once. As you told, it’s that, that I switched on first. My config:

light:
  - platform: mqtt_json
    name: "Porch Strip"
    state_topic: "bruh/porch"
    command_topic: "bruh/porch/set"
    effect: true
    effect_list:
      - bpm
      - candy cane  
      - confetti  
      ....
    brightness: true
    flash: true
    rgb: true
    optimistic: false
    qos: 0  
  - platform: mqtt_json
    name: "Porch Strip Bett"
    state_topic: "bruh/porch2"
    command_topic: "bruh/porch2/set"
    effect: true
    effect_list:
      - bpm
      - candy cane  
      - confetti  
      ....
    brightness: true
    flash: true
    rgb: true
    optimistic: false
    qos: 0

The most common cause of this in the forums is the client_id being set the same on both esp8266. You must create a different client_id for each esp8266.

1 Like

Nope, does not work. Every device has its own client_id

Ok… my fault. It was indeed a problem with the client_id. When I changed it, I had my lamp connected to my computer, which delivered to little power via the USB and forced the ESP to reboot. :confounded:

2 Likes

Doh!
Glad you got it solved