New rgb_command_template assistance please

So I came across a new feature here that allows mqtt RGB color commands to be sent in HEX format.

I am using Tasmota which requires HEX. I can change color fine within Tasmota webUI.

I don;t think I have the rgb_command_template setup correctly. can anyone assist? thanks

platform: mqtt
name: “Goose-LED”
retain: true
state_topic: “stat/IOT-Ext-Goose/POWER”
command_topic: “cmnd/IOT-Ext-Goose/POWER”
rgb_command_template: “{{ ‘#%02x%02x%02x’ | format(red, green, blue)}}”
rgb_state_topic: “stat/IOT-Ext-Goose/Color”
rgb_command_topic: “cmnd/IOT-Ext-Goose/Color”

PS: I have gotten this to work using the method described here but I don’t want to use this since it will be overwritten with future updates.

Thanks in advance.

nm. thank you, thank you, thank you for making this happen. I’m really happy with Tasmota and I’m even happier to get it working with HA. for reference here’s my final YAML for a ws2812 string with, scenes, dimmer and color selector.

NOTE: you might have to change the red, green, blue order to match your ws2812 string. enjoy!

I will ask this, does anyone know how to make the effect list show nice pretty names like xmas, police, etc… instead on 0,1,2,3?

platform: mqtt
name: “Goose-LED”
retain: true
state_topic: “stat/IOT-Ext-Goose/POWER”
command_topic: “cmnd/IOT-Ext-Goose/POWER”
rgb_command_template: “{{ ‘%02x%02x%02x’ | format(blue, green, red)}}”
rgb_state_topic: “stat/IOT-Ext-Goose/Color”
rgb_command_topic: “cmnd/IOT-Ext-Goose/Color”
effect_state_topic: “stat/IOT-Ext-Goose/Scheme”
effect_command_topic: “cmnd/IOT-Ext-Goose/Scheme”
state_value_template: “{{ value_json.state }}”
brightness_state_topic: “stat/IOT-Ext-Goose/Dimmer”
brightness_command_topic: “cmnd/IOT-Ext-Goose/Dimmer”
brightness_value_template: “{{ value_json.Dimmer }}”
brightness_scale: 80
effect_value_template: “{{ value_json.scheme }}”
effect_list:
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10

2 Likes

I am curious, I am trying to do exactly what you obviously have working, but I am having less joy.
Firstly, i have nothing ever publishing to stat/##/Color it all goes to stat/##/results
second, even if i pull the state from results with a template, that works ok, but whenver i adjust the colour, the brightness goes to 100%, and you have to pull it back down.
Do you notice similiar results?

Not at all. Is it working for you at all? Post your yaml also describe your Tasmota setup

Thanks for the response.
Yes it works, but i pick the state from the RESULTS topic as nothing else seems to pick anything up. Here is a copy of the console on the tasmota while i change things, like colour etc.

14:40:02 MQT: stat/rangehood/RESULT = {"POWER":"ON"}
14:40:02 MQT: stat/rangehood/POWER = ON
14:40:28 MQT: stat/rangehood/RESULT = {"POWER":"OFF","Dimmer":0,"Color":"0,0,0"}
14:40:28 MQT: stat/rangehood/RESULT = {"POWER":"ON"}
14:40:28 MQT: stat/rangehood/POWER = ON
14:40:28 MQT: stat/rangehood/RESULT = {"POWER":"OFF","Dimmer":0,"Color":"0,0,0"}
14:40:28 MQT: stat/rangehood/RESULT = {"POWER":"ON"}
14:40:28 MQT: stat/rangehood/POWER = ON
14:40:28 MQT: stat/rangehood/RESULT = {"POWER":"ON"}
14:40:28 MQT: stat/rangehood/POWER = ON
14:40:28 MQT: stat/rangehood/RESULT = {"POWER":"ON","Dimmer":100,"Color":"255,255,255"}
14:40:28 MQT: stat/rangehood/RESULT = {"POWER":"ON"}
14:40:28 MQT: stat/rangehood/POWER = ON
14:40:41 MQT: stat/rangehood/RESULT = {"POWER":"ON"}
14:40:41 MQT: stat/rangehood/POWER = ON
14:40:42 MQT: stat/rangehood/RESULT = {"POWER":"ON","Dimmer":49,"Color":"124,124,124"}
14:40:42 MQT: stat/rangehood/RESULT = {"POWER":"ON"}
14:40:42 MQT: stat/rangehood/POWER = ON
as you can see i have my Color set to RGB in decimal, not hex, like you did. However i did try hex as well and it seems to have the same symptoms. I basically have everything working ok by picking state from RESULT, that isn't hte issue. I just found it strange that everyone else seems to subscribe to stat/%topic%/Color i have never get anything on that topic.

Yaml look slike this:

  - platform: mqtt
    name: "Rangehood"
    state_topic: "stat/rangehood/POWER"
    command_topic: "cmnd/rangehood/POWER"
    rgb_state_topic: "stat/rangehood/RESULT"
    rgb_value_template: "{{ value_json.Color }}"
    rgb_command_topic: "cmnd/rangehood/COLOR"
    brightness_state_topic: "stat/rangehood/RESULT"
    brightness_command_topic: "cmnd/rangehood/DIMMER"
    brightness_scale: 100
    brightness_value_template: "{{ value_json.Dimmer }}"
    qos: 0
    optimistic: false
    retain: true
    effect_state_topic: "stat/rangehood/SCHEME"
    effect_command_topic: "cmnd/rangehood/SCHEME"
    effect_value_template: "{{ value_json.scheme }}"
    effect_list:
    - 0
    - 1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    - 10

THe only issue i have remaining is when i select a colour from the colour picker, lets say white, it sends 255, 255, 255 as it should.
If i then dial the brightness back, that changes to say 124, 124, 124, as you can see from the Tasmota console with dimmer set to 49%.
if I then select green say, it changes to 0, 255, 0, bumping the brightness back to 100% where i would have expected it to say 0, 124, 0.

i guess 255, is green full brightness and 124 is green at 49%

If i then dial the brightness back again, it does work, but i expected the brightness setting to stick when changing the colour, rather than going to 100 every time.

I guess one sollution would be to divide each rgb value by the dimmer setting before sending it, i have no idea how to do that, and it seems no one else needed to do this.

The Tasmota is a Wemos D1 mini, all i changes in the firmware was the SSID settings and MQTT settings. I then logged into the web interface and set the topic to rangehood and the type to wemos d1.

I then selected WS2812 on one of the pins. GPIO4 if i am not mistaken. LED light strip is not connected yet, I am just sorting the wemos and ha first.

thanks for your assistance.

I had the same issue.

stat/%Topic%/ was useless… I found that using the state topics with the same cmnd as the command topics works for me. I have a few D1 minis with WS2813’s hooked up. The only thing that doesn’t show is the selected colour, but I usually have an effect set.

@HickHackerz Do you have Tasmota on the D1?
Do you mind sharing your yaml and any adjustments you made to tasmota, or if not tasmota what firmware you use on the D1?

@Wihanh I run the latest Tasmota on the D1’s. I can share what I have but its almost the same as what you have listed currently

- platform: mqtt
  name: Garage Door Xmas Effect
  effect_list:
      - 0
      - 1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      - 10
      - 11
      - 12
  state_topic: "stat/wemos/POWER"
  command_topic: "cmnd/wemos/POWER"
  brightness_state_topic: "cmnd/wemos/Dimmer"
  brightness_command_topic: "cmnd/wemos/Dimmer"
  brightness_scale: 100
  rgb_command_template: "{{ '%02x%02x%02x' | format(blue, red, green)}}"
  rgb_state_topic: "cmnd/wemos/Color"
  rgb_command_topic: "cmnd/wemos/Color"
  effect_command_topic: "cmnd/wemos/Scheme"
  effect_state_topic: "cmnd/wemos/Scheme"
  state_value_template: "{{ value }}"
  brightness_value_template: "{{ value }}"
  effect_value_template: "{{ value }}"
  rgb_command_mode: hex
  retain: false
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"

In the console if you run a command with no parameter set, you get the current value. So to query it I just run the command again and get the result. By no means is this the best way to achieve this, or is it the right way but it seems to work for every Wemos I have flashed with Tasmota.

I also have sonoffs flashed as well and since most are just a single output to a relay, the cmnd is always POWER ( unless you have a dual or 4 relay). Running stat on the POWER seems to work just fine.

Thanks for that, I have the sonoff working, but as you said, it just has ON, or OFF.
I have seen the rgb_command_mode parameter somewhere else, but i can’t see it on the HA website under the mqtt component
Is there any documenation on it?
Thanks, will have a play tonight and see how it goes.

Does Tasmota support RGBW ? How does it present the W? Can you switch it on separately without RGB?

Hey Guys,
So I have just uploaded the Tasmota Firmware onto a MagicHome RGB Contoller. The module type is set to 34 MagicHome. There is not a Toggle or control on the Main menu however I am able to control the LED’s utilizing the Console and using the PWM commands such as PWM1 255 turns Red on 100%.

My problem now is I cant seem to be able to figure out how to get this to work in HA. I have attmepted the examples above in my lights.yaml file but upon restart HA would fail with a long error. I found what i have below and it succesfully reloads but controlling it from HA is unsuccesful and it also does not have a color pallet to choose from.

Any Suggestions would be great.

- platform: mqtt
   name: East Cabinet Light
   state_topic: "stat/East-Cabinet-Light/POWER"
   command_topic: "cmnd/East-Cabinet-Light/POWER"
   brightness_state_topic: "cmnd/East-Cabinet-Light/Dimmer"
   brightness_command_topic: "cmnd/East-Cabinet-Light/Dimmer"
   brightness_scale: 100
   rgb_command_template: "{{ '%02x%02x%02x' | format(blue, red, green)}}"
   rgb_state_topic: "cmnd/East-Cabinet-Light/Color"
   rgb_command_topic: "cmnd/East-Cabinet-Light/Color"
   effect_command_topic: "cmnd/East-Cabinet-Light/Scheme"
   effect_state_topic: "cmnd/East-Cabinet-Light/Scheme"
   state_value_template: "{{ value }}"
   brightness_value_template: "{{ value }}"
   effect_value_template: "{{ value }}"
   rgb_command_mode: hex
   retain: false
   qos: 1
   payload_on: "ON"
   payload_off: "OFF"

Have you tried disabling PWM mode in the Tasmota console? Use “SetOption15 on”. I had to do this before I could control colour or the dimmer in HA.

Perfect. That made the difference. Thanks

I’m running into an issue with this…
Can some one please please confirm that selecting a color from the RGB color wheel functions properly?

All I can achieve is ON/OFF and Dimming to a value.
Selecting any color from the wheel throws an error in the log :

Feb 13 14:33:57 home hass[7258]: File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/light/mqtt.py”, line 266, in listcomp
Feb 13 14:33:57 home hass[7258]: self._rgb = [int(val) for val in
Feb 13 14:33:57 home hass[7258]: ValueError: invalid literal for int() with base 10: ‘ffbf00’

This doesn’t quite answer your question but here is what I have in my configuration.yaml This allows me to turn the leds on/off and select the different scheme’s. Selecting a color from the color wheel isn’t working yet, so I’m sure I’m just missing something in my confg, once I get it figured out I’ll update.

I’ve also been able to confirm that in the sonoff console I can change all colors, and even set the brighter white color (my strip is an RGBW light strip)

  - platform: mqtt
    name: Office LED
    state_topic: "stat/sonoff2/POWER"
    command_topic: "cmnd/sonoff2/POWER"
    brightness_state_topic: "stat/sonoff2/RESULT"
    brightness_command_topic: "cmnd/sonoff2/Dimmer"
    brightness_scale: 100
    rgb_command_template: '{{ "%02x" | format(red|int) }}{{ "%02x" | format(green|int) }}{{ "%02x" | format(blue|int) }}'
    rgb_state_topic: "stat/sonoff2/RESULT"
    rgb_command_topic: "cmnd/sonoff2/Color"
    rgb_value_template: "{{ value_json.Color[0:2] | int(base=16) }},{{ value_json.Color[2:4] | int(base=16) }},{{ value_json.Color[4:6] | int(base=16) }}"
    effect_command_topic: "cmnd/sonoff2/Scheme"
    effect_state_topic: "stat/sonoff2/Scheme"
    state_value_template: "{{ value_json.state }}"
    brightness_value_template: "{{ value_json.Dimmer }}"
    effect_value_template: "{{ value_json.scheme }}"
    effect_list:
    - 0
    - 1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    - 10
    retain: false
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"

@brandon250r Thanks for posting your yaml… mine is very similar, and the results are identical…all works except picking a color.

I’m sure you’ll have the same errors in your log when you click on a color in the colorpicker.

I also can’t get RGBW working with Tasmota :frowning: Any help appreaciated

I did end up with the same results. I ended up trying the espurna firmware with success. I would prefer tasmota, as other things I have are using it. But for now espurna it is for this particular light strip.

Do you have RGBW 100% working with dimming, choosing between white or RGB etc?
Could you post config too?

meanwhile i got that sorted out, all works perfectly - except for the CW and WW channels, I haven’t looked at getting those working yet. I did se a config somewhere that could bring CW and WW into the mix, so there’s hope.
Here’s the configuration portion :

light:
  - platform: mqtt
    name: "Kitchen"
    state_topic: "stat/h80101/POWER"
    command_topic: "cmnd/h80101/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    rgb_state_topic: "cmnd/h80101/STATUS11"
    rgb_command_topic: "cmnd/h80101/COLOR"
    rgb_value_template: "{{ value_json.StatusSTS.Color.split(',')[:3] | join(',') }}"
    brightness_state_topic: "stat/h80101/DIMMER"
    brightness_command_topic: "cmnd/h80101/DIMMER"
    brightness_scale: 100
    brightness_value_template: "{{ value_json.Dimmer }}"
    qos: 0
    optimistic: false
    retain: true

You need to set these options in the H801, easiest through the Console part in Tasmota :
setoption15 ON and powerretain ON.

I would like to add, there are a couple of configs floating around, none of these function properly, even if they do seem to work they are very likely bombarding your log files with dozens of error lines at every command mqtt sends to the Tasmota RGB device.
The code above is the ONLY version I have found that works cleanly.