Need help controlling WS2812 LED via MQTT JSON

Hello my friends!
I have followed the ws2812b led driver instruction on github. I have completed the hardware and loaded the code. The module has now worked perfectly. It supports control via MQTT and many advanced customizations with JSON MQTT commands. Unfortunately, in the following section, the author instructed the Home Assistant, with only a little of my knowledge, can only control the lights and turn off, the remaining advanced effects are supported via JSON MQTT commands, I do not know how to do. how to do it despite trying to see examples of JSON MQTT.
I hope that you will help me how to complete it. The following is a document from github:

Home Assistant Examples

light: Basic control of a light.

- platform: mqtt
  name: Lamp
  state_topic: "light/lamp/state"
  command_topic: "light/lamp"
  rgb_state_topic: "light/lamp/rgb/state"
  rgb_command_topic: "light/lamp/rgb"
  availability_topic: "light/lamp/availability"
  payload_not_available: "0"
  payload_available: "1"
  payload_off: "0"
  payload_on: "1"
  retain: false

Note: The recovery topic does not need to be used in the Home Assistant config.

input_select: UI to allow user to trigger an animation.

    name: Lamp
      - "Select..."
      - "Warm Light"
      - "Strobe"
      - "Fire"
      - "Colour Phase"
      - "Sparkle"
      - "Shoot / Drip"
      - "Rain"
      - "Rainbow 1"
      - "Rainbow 2"
    initial: "Select..."

automation: Sends the appropriate MQTT command when a mode is selected and then returns the input select back to ‘Select…’

- alias: "Lamp Mode"
    platform: state
    entity_id: input_select.lamp       
    - service: mqtt.publish
        topic: "switch/stairs"
        payload: >
          {% if trigger.to_state.state == 'Warm Light' %}
          {% elif trigger.to_state.state == 'Strobe' %}
          {% elif trigger.to_state.state == 'Fire' %}
          {% elif trigger.to_state.state == 'Colour Phase' %}
          {% elif trigger.to_state.state == 'Sparkle' %}
          {% elif trigger.to_state.state == 'Shoot / Drip' %}
            {0:7,2:[255,147,41],8:0,10:1,9:30, 5:0 ,4:255,3:0,12:5,7:0}
          {% elif trigger.to_state.state == 'Rain' %}
          {% elif trigger.to_state.state == 'Rainbow 1' %}
          {% elif trigger.to_state.state == 'Rainbow 2' %}
          {% else %}
          {% endif %}
        retain: false
    - service: input_select.select_option
        entity_id: input_select.stairlamp_mode
        option: 'Select...'

My items:
Switch Bedroom_Light “Light” (Bedroom, gLight) [“Lighting”, “Switchable”] => I use the user interface to create Things and turn it on and off via topic: light/lamp
Number item = Bedroom_Light_Color
My Sitemap:
Switch item = Bedroom_Light label=“Bedroom Light” icon=“light”
Selection item = Bedroom_Light_Color label=“Light Color” icon=“rgb” mappings = [1 = “Warm Light”, 2 = “Strobe”, 3 = “Fire”, … 13 = “Rainbow 2”]

At this point, I don’t know how to get it to work with effects, which components I am missing? What are its rules like?
I hope you will take some time to give me a specific example in this case so that I can understand what works.
Sorry for my english! Thank you very much.

First since you are turning on/off the light you must have the MQTT stuff in OH configured correctly. Is this using automatically discovered Things or did you create a Generic MQTT Thing?

Assuming a Generic MQTT Thing, it looks like you’ve created a Number Item to represent the state you want (e.g. 1 == “Warm Light”). So what you need is a Map to transform “1” to “{0:2,2:[255,147,41]}” which you need to apply to the to outgoing messages (transformationPatternOut).

Thanks for your answer. I already have the map file, but I do not know the configuration of transformationPatternOut now, I have some actual images, can you guide me more clearly?


That’s the format to use a transformation to transform a label on the sitemap. See for correct examples. The format is the same for incoming and outgoing transformationsl.

Have a look at loading this firmware as there is a openhab binding for this project. Much more active project.

Thank you, I will learn about it :slight_smile: