Led strip in multiple sections and one big ledstrip

So I have a custom piece of software/hardware to drive a led strip (ws2812) via mqtt (esp, homie, etc). Its fairly simple for the most part but i’ve added the ability to control parts of the led strip individually and have been trying to making homie know how to use it appropriately to no avail so far.

Driving the led strip as a single entity is easy enough:

light:

  • platform: mqtt
    name: “esplight”
    command_topic: “devices/dev1/switch/switch/set”
    rgb_command_topic: “devices/dev1/led/color/set”
    rgb_value_template: “value.rgb|join(’,’)”
    brightness_state_topic: “devices/dev1/brightness/brightness/set”
    brightness_command_topic: “devices/dev1/brightness/brightness/set”
    qos: 0
    payload_on: “on”
    payload_off: “off”
    optimistic: false
    state_topic: “devices/dev1/switch/status”

But I also want to divide the led strip into an arbitrary number of lights as sections. From the MQTT perspective, sending something like “0,20,on” turns on leds 0-20 but just sending “on” turns on all leds. I like to be able to keep it so that I dont have to flash the ESP when changing how the sections split up. So for example I might have “lounge light” for the entrie strip and “loung light 1”, “lounge light 2”, which are hard coded sections in home assistant and i just change the prefix on the message if i wanted to change the number of leds in each light. They all use the same MQTT topics and to control a section, prefixing it with start,end (0,20) for eg controls that section.

Sending the commands is actually quite easy enough. Interpreting the status that the ESP light responds with is proving very trick though. If i set the colour of the entire strip to 255,128,64 for eg, it reports “255,128,64” on the status topic, but setting 0-20 to 255,128,64 reports “0,20,255,128,64” on the same topic (not easy to deal with from a homie perspective).

Before i start coding a custom control i was wondering if anyone has any insights on how It might be achieved? (it’d be nice to see “lounge light 1,2,3,etc” be a sub-set of “lounge light” in the actual gui similar to what happens when you group lights, but not necessary).

As its my own code on the ESP, changing what it reports on MQTT on its status topic is possible, but I dont want to have to change which topics im using.

To be honest, I have read this through twice and I’m still not exactly sure what you want to achieve.

However, in general if you want more flexibility in the messages have you considered using a JSON payload like

{
   "leds" : "1-5",
   "state" : "on"
}

instead of changing the topic. You would have to do some decoding using templates, but it would seem possible in principle.

Yes, it ended up being alot harder to explain than i intended. But perhaps a better way of explaining, if i send “0,20,on” to a topic it turns on leds 0-20, if i send “21,40,on” it turns on leds 21 to 40 (which is easy enough). I’ll get the same reply back on the state topic “0,20,on” or “21,40,on”

Originally i was using json, but it didnt really change things much (or i didnt understand how to make it interret properly in home assistant) because both lights use the same topics. I ended up with both lights trying to interpret the json reply. i.e. only interpret this message if “leds” is “0-20” wasnt something i could get to work (either with or without json).

the extension to that problem was when there was no range (controls the entire strip) which made it all the more complex and adding rgb to it more complex again (but can be ignored for now)