Rgbw lights with tasmota and MQTT

I’ve recently flashed some aiLight globes with Tasmota firmware and have discovered they need the white value tacked onto the end of the rgb hex string. My normal rgb configuration is

#Ailight with Tasmota
- platform: mqtt
  name: Lamp 6
  effect_list:
      - 0
      - 1
      - 2
      - 3
      - 4

  state_topic: "cmnd/ailight06/POWER"
  command_topic: "cmnd/ailight06/POWER"
  brightness_state_topic: "cmnd/ailight06/Dimmer"
  brightness_command_topic: "cmnd/ailight06/Dimmer"
  brightness_scale: 100
  rgb_command_template: "{{ '%02x%02x%02x' | format(red, green, blue)}}"
  rgb_state_topic: "cmnd/ailight06/Color"
  rgb_command_topic: "cmnd/ailight06/Color"
  availability_topic: "tele/ailight06/LWT"
  effect_command_topic: "cmnd/ailight06/Scheme"
  effect_state_topic: "cmnd/ailight06/Scheme"
  state_value_template: "{{ value }}"
  brightness_value_template: "{{ value }}"
  effect_value_template: "{{ value }}"
  rgb_command_mode: hex
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_not_available: "Offline"

The Light MQTT component has white value command and state topics but I’m at a loss to work out how to add the value to the end of the rgb string.

Could someone please point me in the right direction?

1 Like

+1 I’d be keen to know too.

Edit: this looks like it may work…

Thanks @mark.carline, That gave me an insight into using templates to parse the JSON status returned as a result but doesn’t address the fourth variable in the rgbw string. I’ve currently set it to 00, which means the white LEDs don’t turn on. Tasmota expects to see RRGGBBWW for the AiLight and RRGGBBCCWW for the Sonoff B1.
I can turn on the white LEDs by entering a HEX string on the Tasmota web console

14:13:25 CMD: color 000000b4
14:13:25 RSL: Group 0, Index 1, Command COLOR, Data 000000b4
14:13:25 MQT: stat/ailight06/RESULT = {"POWER":"ON","Dimmer":70,"Color":"000000B2"}

Cool. I’ve just this this to which might work:

https://github.com/arendst/Sonoff-Tasmota/issues/1353

See the comment/example by robotdad - any good?

light:

  • platform: mqtt
    name: ‘Living room lamp’
    state_topic: “stat/lr_lamp/POWER”
    command_topic: “cmnd/lr_lamp/POWER”
    rgb_state_topic: “stat/lr_lamp/COLOR”
    rgb_command_topic: “cmnd/lr_lamp/COLOR”
    rgb_command_template: “{{ ‘%02x%02x%02x0000’ | format(red, green, blue) }}”
    brightness_state_topic: “stat/lr_lamp/DIMMER”
    brightness_value_template: “{{ value_json.brightness }}”
    brightness_command_topic: “cmnd/lr_lamp/DIMMER”
    brightness_scale: 100
    color_temp_command_topic: “cmnd/lr_lamp/CT”
    qos: 1
    payload_on: “ON”
    payload_off: “OFF”
    retain: true
  • platform: mqtt
    name: ‘Family room lamp’
    state_topic: “stat/fr_lamp/POWER”
    command_topic: “cmnd/fr_lamp/POWER”
    brightness_state_topic: “stat/fr_lamp/DIMMER”
    brightness_command_topic: “cmnd/fr_lamp/DIMMER”
    brightness_value_template: “{{ value_json.brightness }}”
    brightness_scale: 100
    rgb_state_topic: “stat/fr_lamp/COLOR”
    rgb_command_topic: “cmnd/fr_lamp/COLOR”
    rgb_command_template: “{{ ‘%02x%02x%02x00’ | format(red, green, blue) }}”
    qos: 1
    payload_on: “ON”
    payload_off: “OFF”
    retain: true

In this example the Living room light is a Sonoff B1, the other is an AiLight.

This RGB command template is the problem child, I need a way to replace the 00 at the end of the formatted string with a value for the white LEDs.

Both configurations from your link are ignoring the white LEDs.

1 Like

Ok.

Also - have you seen SetOption15 ? Are you using that? Not sure if that will help

Also, are you in the UK ? If so, I wondered, where did you get your ailight from ?

Btw when we get this working 100% for Sonoff B1 and ailight bulbs we should submit a change to the Tasmota GitHub help page, the docs don’t have anything:

:slight_smile:

1 Like

GgI’m in OZ. The globes came from Banggood
Specification:
Brand: ARILUX
Lamp base:E27
Input voltage:AC85-265V
Output voltage:DC13.4V
Wattage:11W(White:5.3-5.5W Red:2W Green:2W Blue:2W)
LED chip:SMD5730
LED quantity:22leds (8pcswhite,6pcsred,4pcsblue,4pcsgreen)
Lumen: 920lm (white:450lm)
Light color:RGB + pure white
Wireless type: 2.4Ghz
Wireless standard: IEEE 802.11b/g/n
Color temperature:2600K-6500K
Beam angle:120°
PF:0.5
CRI:70
Is dimmable:yes
Material:PC+aluminum
Dimension:60*115mm

The Tasmota side is OK. Getting HA to speak to it correctly is the current problem.

Edit

Option 15 is set. I’ve flashed a couple of RGB controllers with Tasmota firmware, they both work correctly. It’s the W bit giving me a headache.

1 Like

Have you made it to work? Have issues with RGBW too.

Not with the Tasmota firmware. I flashed one lamp with AiLight

and used this for my config.

- platform: mqtt_json
  name: "Lamp07"
  state_topic: "AiLight07/state"
  command_topic: "AiLight07/set"
  availability_topic: "AiLight07/status"
  payload_available: "online"
  payload_not_available: "offline"
  qos: 1
  color_temp: true
  brightness: true
  rgb: true
  white_value: true
  effect: false
  optimistic: false
  retain: true

There is an open issue on the Sonoff-Tasmota issues GitHub that would be worth watching.

John

Bump.

Anyone get the Ailight bulbs working with Tasmota and HA?

I have the same issue with a similar controller

AiLight work with esp8285?

I think I did what you are trying to do with this, though a slightly different setup.

In my case, I have an RGBW strip controlled by a H801 running Tasmota. I initially added it using auto-discovery, but that only supports using either the white LEDs only (via a color temperature slider) or the RGB LEDs using the color picker, and it’s not possible via Home-Assistant to get a mix of RGB and White LEDs.

What I ended up adding is the following:

  - platform: mqtt
    name: "Kitchen Accent 2"
    availability_topic: "kitchen-accent/tele/LWT"
    command_topic: "kitchen-accent/cmnd/POWER1"
    state_topic: "kitchen-accent/stat/RESULT"
    state_value_template: "{{value_json.POWER}}"
    brightness_command_topic: "kitchen-accent/cmnd/Dimmer"
    brightness_state_topic: "kitchen-accent/stat/RESULT"
    brightness_value_template: "{{value_json.Dimmer}}"
    brightness_scale: 100
    rgb_command_topic: "kitchen-accent/cmnd/Color2"
    rgb_state_topic: "kitchen-accent/stat/RESULT"
    # RGB<->RGBW conversion
    rgb_value_template: "{% set red = (value_json.Color.split(',')[0] | round(0)) %}{% set green = (value_json.Color.split(',')[1] | round(0)) %}{% set blue = (value_json.Color.split(',')[2] | round(0)) %}{% set white = (value_json.Color.split(',')[3] | round(0)) %}{{ red + white }},{{ green + white }},{{ blue + white }}"
    rgb_command_template: "{% set white = ([red,green,blue]|min) %}{{ red - white }},{{ green - white }},{{ blue - white }},{{ white }}"
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"

Basically what rgb_command_template is doing is calculating white as the minimum of R,G,B, and then all R,G,B values have that amount subtracted. Some examples:

  • Pure red: 255,0,0 = 255,0,0,0
  • Pure white: 255,255,255 = 0,0,0,255
  • Yellow-white: 255,255,109 = 146,146,0,109
  • Purple-white: 163,72,255 = 91,0,183,72

Using The yellow-white as an example, basically instead of using blue to start mixing towards white, it just uses the white LED instead (so 0 blue). Likewise, pure white uses only the white LEDs.

Using the outside of the color picker, you always get a 0 for one of the colors, so the white LEDs are off. The closer you get to the middle, the more the white LEDs turn on until the center is only the white LEDs at full brightness and RGB LEDs are all off.

The rgb_value_template also has the corresponding opposite calculation so the color wheel is updated properly.

EDIT: I did a more complete write-up of this with demo video here: RGBW strip with H801 + Tasmota

7 Likes

I had been looking for a solution for some time and this was a very good answer.
My bulb was originally a Tuya controlled RGBW from Banggood, and now configured as AiLight in Tasmota (after flashing using Tuya Convert).

It seems daft that HomeAssistant does not provide an out of the box solution for RGBW lights such as these - with an RGB selector for colour, an overall brightness slider and a white brightness slider.

Thanks for this excellent solution.

This works really well. It even lets me use Google Assistant to change colors using words. Outstanding work! Thank you.

Hi,

i have an RGBWW (RGB + Warm Wight) strip and found a good solution with a small modification of gregmac’s template.

With the following template, when you chose pure white in the UI, the RGB LEDs all turn off and only the white LEDs turn on. When you select any color, the white LEDs turn off and only the RGB LEDs are active. That was the solution I was looking for.

light:
  - platform: mqtt
    name: "Lounge Light"
    availability_topic: "lounge-lights/tele/LWT"
    command_topic: "lounge-lights/cmnd/POWER1"
    state_topic: "lounge-lights/stat/RESULT"
    state_value_template: "{{value_json.POWER}}"
    brightness_command_topic: "lounge-lights/cmnd/Dimmer"
    brightness_state_topic: "lounge-lights/stat/RESULT"
    brightness_value_template: "{{value_json.Dimmer}}"
    brightness_scale: 100
    rgb_command_topic: "lounge-lights/cmnd/Color2"
    rgb_state_topic: "lounge-lights/stat/RESULT"
    # RGB<->RGBWW conversion
    rgb_value_template: >
      {% set red = (value_json.Color.split(',')[0] | round(0)) %}
      {% set green = (value_json.Color.split(',')[1] | round(0)) %}
      {% set blue = (value_json.Color.split(',')[2] | round(0)) %}
      {% set white = (value_json.Color.split(',')[3] | round(0)) %}
      {{ red + white }},{{ green + white }},{{ blue + white }}
    rgb_command_template: >
      {% if red==green and red==blue %}
        0,0,0,{{ red }}
      {% else %}
        {{ red }},{{ green }},{{ blue  }},0
      {% endif %}
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
3 Likes

@3breadt works really great! Thank You!

Hello,

I have now the same controller flashed with Tasmota, what did you set on the page Configure Module and on the page Other by MQTT template.

Another question is which rule should i to set to work also with RF controller?