Need help controlling WS2812 LED via MQTT JSON

Tags: #<Tag:0x00007f61785e74b0> #<Tag:0x00007f61785e7280>

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: https://github.com/Dullage/ESP-LED-MQTT

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.

lamp:
    name: Lamp
    options:
      - "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"
  trigger:
    platform: state
    entity_id: input_select.lamp       
  action:
    - service: mqtt.publish
      data_template:
        topic: "switch/stairs"
        payload: >
          {% if trigger.to_state.state == 'Warm Light' %}
            {0:2,2:[255,147,41]}
          {% elif trigger.to_state.state == 'Strobe' %}
            {0:3}
          {% elif trigger.to_state.state == 'Fire' %}
            {0:4}
          {% elif trigger.to_state.state == 'Colour Phase' %}
            {0:5,3:15}
          {% elif trigger.to_state.state == 'Sparkle' %}
            {0:6,2:[50,50,50],3:0,4:5,5:0}
          {% 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' %}
            {0:8,11:1100}
          {% elif trigger.to_state.state == 'Rainbow 1' %}
            {0:12}
          {% elif trigger.to_state.state == 'Rainbow 2' %}
            {0:13}
          {% else %}
            {}
          {% endif %}
        retain: false
    - service: input_select.select_option
      data:
        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?

Thanks!

That’s the format to use a transformation to transform a label on the sitemap. See https://www.openhab.org/addons/bindings/mqtt.generic/#incoming-value-transformation 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: