MQTT Lights

I am having trouble with my led strip lights. So I have two led strip lights that are each being controlled by a separate NodeMCU due to them being on separate cabinets. I am trying to control both led’s by only using one light setting. So for example if I turn the power on both light strips come on or if I change the color both strips change to the same color. The problem I am having is that if they are both on only one will switch with the commands I send. If I power one off then it seems to work perfectly for the one that is on and visa versa. Is there a way to control both with the same commands? Basically I have the same code running on both NodeMCUs where the only difference is the number of LED’s.

Here is my light.yaml code:

- platform: mqtt
  name: "Kitchen LEDs"
  command_topic: "home/kitchen/ledstrip/setpower"
  state_topic: "home/kitchen/ledstrip/setpowerpub"
  rgb_state_topic: "home/kitchen/ledstrip/setcolorpub"
  rgb_command_topic: "home/kitchen/ledstrip/setcolor"
  brightness_state_topic: "home/kitchen/ledstrip/setbrightnesspub"
  brightness_command_topic: "home/kitchen/ledstrip/setbrightness"
  optimistic: false

If you unplug the working one, does the second led strip work?

Did you use 2 different client ID in your NodeMCU?
Because they must be unique! So if you carefully uploaded the exact same code, it cannot work ^^ (you need to change the clientID on one of the two)

Actually, if you define the client id in terms of the chip id, which is unique per 8266, then you can upload the same code. But it is definitely something worth checking.

That’s true, but most of the code laying around online use a fixed ID, and I guess it’s not different in grangemd code :blush:
Some also use the mac address, since it’s supposed to be unique.

Thanks for the help. That fixed it. I missed that when I uploaded it to the 2nd NodeMCU. I was using someone else’s code as I usually use the chip id to name my client id and didn’t realize they didn’t do this.

Hi all,

Just following this as I want to simultaneously control multiple rgb lights (8266 controllers) and operate them (on/off colour and brightness) as though they were just one light.

In the 8266 sketch is this the client ID you are referring to? (I’m borrowing code)

const char* MQTT_CLIENT_ID = “arilux”;

If I follow this thread, for each of my 6 lights I need to have a unique value instead of arilux?

Many thanks.

If you only make one connection to the broker, then you only need one client id.

I still think it would be good practice to include the chip id, to make sure it is unique.

Thanks for the reply.

I’m new to this, so forgive me if I’m missing something basic!

My understanding is that each of the 6 8266-based controllers will have their own connection to the broker (RPi Mosquitto), each with identical State and Command topics? Is that the correct understanding of the terminology?

Yes each client id must be unique on your network.

I misunderstood your situation, I thought all your lights were controlled from one 8266.

@touliloup is correct, you need the client id to be unique for each 8266. As I said before, the best way to do this is to use the chip id as this is intended to be unique.

@touliloup and @gpbenton many thanks to both of you.

I am awaiting some more controllers from banggood, and once I’ve everything set up I will report back on my progress!

OK - the result is this;

Set up 9 lights, with just one identical topic each is subscribing to. One, just one, entry to HAss, which means that I do not need to control each light independently. They all work in unison, perfectly!

1 Like