Is it possible to split addresable LED strip into several "virtual" device entities?

Hi guys.
This is my beautiful setup :stuck_out_tongue_winking_eye: :stuck_out_tongue_winking_eye:, pure DIY by me :kissing_closed_eyes: :kissing_closed_eyes: :

Short explanation:

  • WS2812B LED strip was used here, 50 pixels in summary
  • Each bottle has 10 pixels within
  • From right to left, separate strips are connected with wires through pipes, so all 5 pieces are acting as 1 LED strip
  • There is an ESP01S module who control this, on the right end in small saltshaker
  • There is also physical momentary switch button on the top of saltshaker, attached to ESP01s, so I can turn it on/off, but this part isn’t important for my question.

This is the ESPHome code flashed to ESP01S:

esphome:
  name: bottle-lights

esp8266:
  board: esp01

logger:

api:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  
e131:
  method: multicast
  
light:
  - platform: neopixelbus
    type: GRB
    variant: WS2812X
    pin: GPIO0
    num_leds: 50
    name: "Bottle Lights"
    effects:
      - e131:
          universe: 1
          channels: RGB
      - random:
      - pulse:
      - strobe:
      - flicker:
      - addressable_rainbow:
      - addressable_color_wipe:
      - addressable_scan:
      - addressable_twinkle:
      - addressable_random_twinkle:
      - addressable_fireworks:
      
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO2
      mode: INPUT_PULLUP
      inverted: True
    name: "Bottle Lights Button"
    on_click:
    - min_length: 50ms
      max_length: 1000ms
      then:
        - homeassistant.service:
            service: light.toggle
            data: 
              entity_id: light.bottle_lights
    - min_length: 1001ms
      max_length: 10000ms
      then:
        - homeassistant.service:
            service: script.bottle_lights_warm_white

As you can see, I’m using also e1.31 effect in light platform, so I can additionally control pixels from my Hyperion server, via udpe131 protocol.

Question: Is there a chance that this LED strip of 50 pixels could somehow being split into 5 entities, so each bottle can be independent entity?

I made one custom effect in Hyperion, where it would turn on only pixels from one bottle with desired color, then wait 1s, then turn on second bottle and so on, but this is a no go, cause I would have to make an effect for every possible use case :fearful:

From other side, I can see on ESPHome documentation, there is something called universe within e1.31 component/effect. If I understand correct, this could be some kind of way to split one strip into more entities, cause in Hyperion I am also required to enter the number of universe:

But if I understood correct from ESPHome documentation, technicaly there could be only 2 universes?

If there’s more LEDs than allowed per-universe, additional universe will be used. In the above example of 189 LEDs, first 170 LEDs will be assigned to 1 universe, the rest of 19 LEDs will be automatically assigned to 2 universe.

I would be glad to take any interesting advice for how could I split this 50 pixels strip into 5 separate Home Assistant entities.
Many thanks in advance!

1 Like

Yes use partition.

1 Like

Hmmmm, I suppose this is something from ESPHome light component? Will search now and follow up.

EDIT: @nickrout : THANKS! I am pretty sure I saw this before, but that was several months ago before this bottle project, so I forgot the name. Yup, this is for sure solution, thanks once again.

No it’s instead of in addition to:

  - platform: neopixel

you use:

  - platform: partition

And I too have learnt something new today. Thanks @nickrout

@zoogara : Thank you also!

Will need to check is it use of e1.31 effect possible with partition platform. I’m using neopixelbus cause it was used in example for e1.31 effect on documentation. To be honest, I never tried e1.31 effect is it working with some other platform (FastLED for example). And I would like to keep Hyperion option as well, i.e. control pixels from Hyperion through e1.31 effect.

If I understand correct Light Partition documentation and their first example, Splitting a single LED strip, then strip can be firstly split into pieces, and afterwards in yaml code neopixelbus can be defined for each piece.

Will try it.

There is a working example of partition in this LINK

1 Like

Yu-hu, you are my hero, thanks a lot.

Firstly, I was meant that I should have one entity for whole strip, with neopixel platform, to be able to control whole strip at once (I want to be able). And on top of that I should have neopixel entity for each piece + partition entity for each piece, so they match id inside yaml. So my yaml was like below and I was surprised why when I turn on one piece entity, it turn off another piece entity previously turned on (confusing :slight_smile: ), (which is by the way totally normal, cause second turned on entity is telling to strip to turn off all other pixels except of certain 10):

light:
  - platform: neopixelbus
    type: GRB
    variant: WS2812X
    pin: GPIO0
    num_leds: 50
    name: "Bottle Lights"
    effects:
      - e131:
          universe: 1
          channels: RGB
      - random:
      - pulse:
      - strobe:
      - flicker:
      - addressable_rainbow:
      - addressable_color_wipe:
      - addressable_scan:
      - addressable_twinkle:
      - addressable_random_twinkle:
      - addressable_fireworks:
  - platform: partition
    name: "Partition Bottle 1"
    segments:
      - id: light1
        from: 40
        to: 49
  - platform: partition
    name: "Partition Bottle 2"
    segments:
      - id: light2
        from: 30
        to: 39
  - platform: neopixelbus
    id: light1
    type: GRB
    variant: WS2812X
    pin: GPIO0
    num_leds: 50
    name: "Bottle 1"
    effects:
      - e131:
          universe: 1
          channels: RGB
      - random:
      - pulse:
      - strobe:
      - flicker:
      - addressable_rainbow:
      - addressable_color_wipe:
      - addressable_scan:
      - addressable_twinkle:
      - addressable_random_twinkle:
      - addressable_fireworks:
  - platform: neopixelbus
    id: light2
    type: GRB
    variant: WS2812X
    pin: GPIO0
    num_leds: 50
    name: "Bottle 2"
    effects:
      - e131:
          universe: 1
          channels: RGB
      - random:
      - pulse:
      - strobe:
      - flicker:
      - addressable_rainbow:
      - addressable_color_wipe:
      - addressable_scan:
      - addressable_twinkle:
      - addressable_random_twinkle:
      - addressable_fireworks:

Now, everything is clear (at least should be finaly :slight_smile: ), that instead of previous, actually I should have one entity for whole strip, with neopixel platform + partition entity for each piece and that’s it - thanks for opening my eyes.

Anyway, when tested this above crazy setup, I noticed that could be flickering in my case, because of conflict of two entities/platforms (neopixel and partition), as mentioned on documentation. What I learnt from my previous experience and what I’m looking in your code example on provided link, is telling me that I will need to decide do I want to control strip in pieces or whole strip, one of those two things, not both (I want both :sob: :sob:). Now, I am on work, will try this tonight. Thanks for pointing me once again.

This is a section of my Ikea Kallax Unit, I have used a strip of LEDS split into 4 sections, each section joined by wires to make 1 long strip.

As you can see the strip is 48 leds, split into 12 leds per section. Kallax1 will control all the leds as a 48 leds light and the K1 - 4 each have 12 leds.

As it is, I can have all the lights on (Kallax1 and K1-4) and they will interfere with each other.

I’m just showing you how to have all the leds on 1 light AND partitions too, you only need to have 1 neopixelbus light.

I don’t think I’ve cleared this up :confused:

light:
  - platform: neopixelbus
    variant: WS2812
    pin: GPIO3
    num_leds: 48
    name: "Kallax1"
    id: kallax
    effects:
      - random:
      - random:
          name: Random Effect 1s
          transition_length: 0s
          update_interval: 1s
      - random:
          name: Random Effect 2s
          transition_length: 0s
          update_interval: 3s
      - addressable_rainbow:
      - addressable_rainbow:
          name: Rainbow Fast
          speed: 30
          width: 48
      - flicker:
      - strobe:
          name: EpiFit
          colors:
            - state: True
              brightness: 100%
              red: 100%
              green: 100%
              blue: 100%
              duration: 20ms
            - state: False
              duration: 20ms
      - addressable_scan:
      - addressable_scan:
          name: Scan 2
          move_interval: 40ms
          scan_width: 4
      - addressable_twinkle:
      - addressable_random_twinkle:
      - addressable_fireworks:
      - addressable_flicker:
      - addressable_lambda:
          name: Christmas
          update_interval: 10ms
          lambda: |-
            static int state = 0;
            if (state < 256) {
              it.range(0, 11) = ESPColor(state, 255-state, 0);
              it.range(12, 23) = ESPColor(255-state, state, 0);
              it.range(24, 35) = ESPColor(state, 255-state, 0);
              it.range(36, 47) = ESPColor(255-state, state, 0);
            } else if (state > 255) {
              it.range(0, 11) = ESPColor(510-state, state-255, 0);
              it.range(12, 23) = ESPColor(state-255, 510-state, 0);
              it.range(24, 35) = ESPColor(510-state, state-255, 0);
              it.range(36, 47) = ESPColor(state-255, 510-state, 0);
            }
            state += 1;
            if (state == 510)
              state = 0;

  - platform: partition
    name: "K1"
    id: k1
    segments:
      - id: kallax
        from: 0
        to: 11
    effects:
      - random:
          transition_length: 1000ms
      - addressable_rainbow:
      - strobe:
          name: StrobeSlowRed
          colors:
            - state: True
              brightness: 100%
              red: 100%
              green: 0%
              blue: 0%
              duration: 1000ms
            - state: False
              duration: 1000ms

  - platform: partition
    name: "K2"
    id: k2
    segments:
      - id: kallax
        from: 12
        to: 23
    effects:
      - random:
          transition_length: 1000ms
      - addressable_rainbow:
      - strobe:
          name: StrobeSlowRed
          colors:
            - state: True
              brightness: 100%
              red: 100%
              green: 0%
              blue: 0%
              duration: 1000ms
            - state: False
              duration: 1000ms

  - platform: partition
    name: "K4"
    id: k4
    segments:
      - id: kallax
        from: 24
        to: 35
    effects:
      - random:
          transition_length: 1000ms
      - addressable_rainbow:
      - strobe:
          name: StrobeSlowRed
          colors:
            - state: True
              brightness: 100%
              red: 100%
              green: 0%
              blue: 0%
              duration: 1000ms
            - state: False
              duration: 1000ms

  - platform: partition
    name: "K3"
    id: k3
    segments:
      - id: kallax
        from: 36
        to: 47
    effects:
      - random:
          transition_length: 1000ms
      - addressable_rainbow:
      - strobe:
          name: StrobeSlowRed
          colors:
            - state: True
              brightness: 100%
              red: 100%
              green: 0%
              blue: 0%
              duration: 1000ms
            - state: False
              duration: 1000ms

Are they conflicting and flickering if you e.g. turn on whole strip or run some effect on whole strip, then turn on some of segments?
(If this is the case, I believe that I could write some automation which will turn off all segments on any state change regarding whole strip and vice versa)

Btw, I’m not sure do you need id: 2 times inside - platform: partition.

If you mean this bit then the first is the id of the segment and the second is the id of the ‘parent’.

  - platform: partition
    name: "K1"
    id: k1
    segments:
      - id: kallax
        from: 0
        to: 11

Regarding the lights interfering with each other, yes, that is the case, a bit of code should sort that out if it bothers you :slight_smile:

Guys, and especially @RoadkillUK (cause I can see that you are interested in topic, and according other topic that you spent certain time with solving this puzzle), I am pretty satisfied.

I’m not sure am I right, but by reading on internet regarding “neopixelbus vs fastled”, I got impression that fastled is slightly better and less resource hungry, so I decided to try it instead of neopixelbus.

At the end of the post, there is my semi-final configuration. I say “semi-final” only because I want to add few more automation, like when I press the button, turn on bottles one by one with 1s delay between each other, in warm white color, same this for turning whole strip on from HA and from Alexa (via HA), but from “make it work” point of view - everything is ok, because there is no flickering at all when whole strip entity and single segment entities are turned on same time, even if they running different effects same moment. It simply acting like effects are having an advantage over solid color, and last action have an advantage over previous action, no matter if coming from whole strip or from single segment. I am ok with this.

I had just one situation that all entities, whole strip and single segments, were become unavailable in HA when I tried to run different effect on each single segment + on whole strip, but:

  1. I guess it’s more because ESP01S which is not anything special and powerful, and I also read on internet that much light partitions = much RAM consumed
  2. I believe that I will have a zero to very rare need for such a situation in real life (actually, probably never, except for testing purpose, so cost and size of ESP01S are wining the battle).
  3. There is also possibility this was because my wifi, which is unstable for some reason in last few days, I can see that Yeelight bulbs are also becoming unavailable, then appear again.

Setup:

esphome:
  name: bottle-lights

esp8266:
  board: esp01

logger:

api:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  
e131:
  method: multicast
  
light:
  - platform: fastled_clockless
    chipset: WS2812B
    pin: GPIO0
    num_leds: 50
    name: "Bottle Lights"
    id: strip
    rgb_order: GRB
    effects:
      - e131:
          universe: 1
          channels: RGB
      - random:
      - pulse:
      - strobe:
      - flicker:
      - addressable_rainbow:
      - addressable_color_wipe:
      - addressable_scan:
      - addressable_twinkle:
      - addressable_random_twinkle:
      - addressable_fireworks:
  - platform: partition
    name: "Bottle 1"
    id: bottle1
    segments:
      - id: strip
        from: 40
        to: 49
    effects:
      - e131:
          universe: 1
          channels: RGB
      - random:
      - pulse:
      - strobe:
      - flicker:
      - addressable_rainbow:
      - addressable_color_wipe:
      - addressable_scan:
      - addressable_twinkle:
      - addressable_random_twinkle:
      - addressable_fireworks:
  - platform: partition
    name: "Bottle 2"
    id: bottle2
    segments:
      - id: strip
        from: 30
        to: 39
    effects:
      - e131:
          universe: 1
          channels: RGB
      - random:
      - pulse:
      - strobe:
      - flicker:
      - addressable_rainbow:
      - addressable_color_wipe:
      - addressable_scan:
      - addressable_twinkle:
      - addressable_random_twinkle:
      - addressable_fireworks:
  - platform: partition
    name: "Bottle 3"
    id: bottle3
    segments:
      - id: strip
        from: 20
        to: 29
    effects:
      - e131:
          universe: 1
          channels: RGB
      - random:
      - pulse:
      - strobe:
      - flicker:
      - addressable_rainbow:
      - addressable_color_wipe:
      - addressable_scan:
      - addressable_twinkle:
      - addressable_random_twinkle:
      - addressable_fireworks:
  - platform: partition
    name: "Bottle 4"
    id: bottle4
    segments:
      - id: strip
        from: 10
        to: 19
    effects:
      - e131:
          universe: 1
          channels: RGB
      - random:
      - pulse:
      - strobe:
      - flicker:
      - addressable_rainbow:
      - addressable_color_wipe:
      - addressable_scan:
      - addressable_twinkle:
      - addressable_random_twinkle:
      - addressable_fireworks:
  - platform: partition
    name: "Bottle 5"
    id: bottle5
    segments:
      - id: strip
        from: 0
        to: 9
    effects:
      - e131:
          universe: 1
          channels: RGB
      - random:
      - pulse:
      - strobe:
      - flicker:
      - addressable_rainbow:
      - addressable_color_wipe:
      - addressable_scan:
      - addressable_twinkle:
      - addressable_random_twinkle:
      - addressable_fireworks:
      
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO2
      mode: INPUT_PULLUP
      inverted: True
    name: "Bottle Lights Button"
    on_click:
    - min_length: 50ms
      max_length: 1000ms
      then:
        - homeassistant.service:
            service: light.toggle
            data: 
              entity_id: light.bottle_lights
    - min_length: 1001ms
      max_length: 10000ms
      then:
        - homeassistant.service:
            service: script.bottle_lights_warm_white