How to control Shelly RGBW2 White Channel Brightness in Automation (Increase and Decrease on Trigger)

I wanted to control the brightness of my Shelly RGBW2 (Not connected via MQTT; using the Shelly Integration) White Channel using an Automation. But I am unable to do so. I went into Automation & Scenes > Automations > Create automation > Start with an empty automation > Actions > Light: Turn on > Target - Choose Device - Study Room LED. I have tried all the option under this (Tried to run each option) & I couldn’t control the brighntess of my White Channel of my Shelly RGBW2. In the RGBW2’s color card, the brightness slider at the top of the card controls the brightness of all the RGB channels. The second brightness slider controls the brightness of the selected RGB channels (I think). And the bottom most brightness slider controls the brightness of the white channel. I want to control the brightness of the white channel in an automation. FYI the first/ top most brightness slider doesn’t affect the brightness of the white channel.
Can someone please point me to a soluition? Preferably GUI withouit going into YAML code. But if there is no option to do this via GUI, then YAML code will be my only option.
P.S. I am attaching a screenshot of all the options that I saw under the automation as well as the picture of the card with 3 different brightness sliders.



My use for this automation will be to increase or decrease the brightness of the white channel with an increment of 10 on every trigger in an automation.

1 Like

You need to control the RGBW-color like sending [0,0,0,0-255] (where the last is the value for white brightness and can have a value from 0 to 255).

1 Like

I had a ton of trouble with this as well, and I ended up making the below script to do it for me. It grabs the white brightness using array indexing from the attribute on the strip, then grabs the standard ‘brightness’ attribute (which represents the color brightness slider) and then applies a markup to them. I haven’t spent a ton of time using it, so it prob needs some edits, but then I tied this to my up button presses on my pico and it is working for what I need right now.

Ok, so after playing with it for a min, the next thing to add is to get the variables for the current R,G,B colors and use those in the color setting so it maintains the color while changing bright level. But this at least gives you a way to handle it with an automation. (I tied mine to a remote).

For the ‘decrement’ brightness function, I just multiplied by 0.85 instead of 1.25, and it worked perfectly.

alias: Light_ShellyStripIncrBright
variables:
  strip02WhiteBrightVal: "{{state_attr('light.kitchen_strip_02','rgbw_color')[3]}}"
  strip02BrightVal: "{{state_attr('light.kitchen_strip_02','brightness')}}"
sequence:
  - service: light.turn_on
    data:
      rgbw_color: [255, 255, 255, "{{strip02WhiteBrightVal * 1.25}}"]
      brightness: "{{strip02BrightVal * 1.25}}"
    target:
      entity_id: light.kitchen_strip_02
mode: single

I’ve updated the inc brightness to fix an issue with setting values outside the available range and allowed the script to keep the RGB values. It still has an issue with scaling. Since it is percent based, when the light is low, the inc/decr values are much lower. At some point I will add a ‘min step’ type value. The ‘min/max’ settings in the script are already a bit confusing as written though, so it could use some cleanup for that too. The logic in the scripts makes sure the range is between 1-255, and at least one more or one less than the current value (since when below a certain number, incrementing by a % doesn’t actually go up unless you do a ceiling rounding).

Inc Brightness:

alias: Light_ShellyStripIncrBright
variables:
  strip02RVal: "{{state_attr('light.kitchen_strip_02','rgbw_color')[0]}}"
  strip02GVal: "{{state_attr('light.kitchen_strip_02','rgbw_color')[1]}}"
  strip02BVal: "{{state_attr('light.kitchen_strip_02','rgbw_color')[2]}}"
  strip02WVal: "{{state_attr('light.kitchen_strip_02','rgbw_color')[3]}}"
  strip02WValAdjMax: "{{[strip02WVal * 1.45 , 255]}}"
  strip02WValMinMax: "{{[strip02WValAdjMax|min|int,([strip02WVal+1,255]|min)]}}"
  strip02BrightVal: "{{state_attr('light.kitchen_strip_02','brightness')}}"
  strip02BrightValAdjMax: "{{[strip02BrightVal * 1.45 , 255]}}"
  strip02BrightValMinMax: "{{[strip02BrightValAdjMax|min|int,([strip02BrightVal+1,255]|min)]}}"
sequence:
  - service: light.turn_on
    data:
      rgbw_color:
        - "{{strip02RVal}}"
        - "{{strip02GVal}}"
        - "{{strip02BVal}}"
        - "{{strip02WValMinMax|max|int}}"
      brightness: "{{strip02BrightValMinMax|max|int}}"
    target:
      entity_id: light.kitchen_strip_02
mode: single

Decr Brightness

alias: Light_ShellyStripDecrBright
variables:
  strip02RVal: "{{state_attr('light.kitchen_strip_02','rgbw_color')[0]}}"
  strip02GVal: "{{state_attr('light.kitchen_strip_02','rgbw_color')[1]}}"
  strip02BVal: "{{state_attr('light.kitchen_strip_02','rgbw_color')[2]}}"
  strip02WVal: "{{state_attr('light.kitchen_strip_02','rgbw_color')[3]}}"
  strip02WValAdjMax: "{{[strip02WVal * 0.85 , 1]}}"
  strip02WValMinMax: "{{[strip02WValAdjMax|max|int,([strip02WVal-1,1]|min)]}}"
  strip02BrightVal: "{{state_attr('light.kitchen_strip_02','brightness')}}"
  strip02BrightValAdjMax: "{{[strip02BrightVal * 0.85 , 1]}}"
  strip02BrightValMinMax: "{{[strip02BrightValAdjMax|max|int,([strip02BrightVal-1,1]|min)]}}"
sequence:
  - service: light.turn_on
    data:
      rgbw_color:
        - "{{strip02RVal}}"
        - "{{strip02GVal}}"
        - "{{strip02BVal}}"
        - "{{strip02WValMinMax|max|int}}"
      brightness: "{{strip02BrightValMinMax|max|int}}"
    target:
      entity_id: light.kitchen_strip_02
mode: single

Oh yeah, prob last edit. It does not work if the light is off. It isn’t a perfect solution. The best solution would be for Shelly to add a setting in their firmware for ‘brightness controls both white and color brightness’…

Another Edit:
Ok, I couldn’t help but add this in, because it was driving me crazy. I will add logic for put in a ‘choose’ action with selections for my primary house schedules, but this at least prevents an error for Inc if the light is off:

alias: Light_ShellyStripIncrBright
sequence:
  - choose:
      - conditions:
          - condition: state
            entity_id: light.kitchen_strip_02
            state: "off"
        sequence:
          - service: light.turn_on
            data: {}
            target:
              entity_id: light.kitchen_strip_02
    default:
      - variables:
          strip02RVal: "{{state_attr('light.kitchen_strip_02','rgbw_color')[0]}}"
          strip02GVal: "{{state_attr('light.kitchen_strip_02','rgbw_color')[1]}}"
          strip02BVal: "{{state_attr('light.kitchen_strip_02','rgbw_color')[2]}}"
          strip02WVal: "{{state_attr('light.kitchen_strip_02','rgbw_color')[3]}}"
          strip02WValAdjMax: "{{[strip02WVal * 1.45 , 255]}}"
          strip02WValMinMax: "{{[strip02WValAdjMax|min|int,([strip02WVal+1,255]|min)]}}"
          strip02BrightVal: "{{state_attr('light.kitchen_strip_02','brightness')}}"
          strip02BrightValAdjMax: "{{[strip02BrightVal * 1.45 , 255]}}"
          strip02BrightValMinMax: "{{[strip02BrightValAdjMax|min|int,([strip02BrightVal+1,255]|min)]}}"
      - service: light.turn_on
        data:
          rgbw_color:
            - "{{strip02RVal}}"
            - "{{strip02GVal}}"
            - "{{strip02BVal}}"
            - "{{strip02WValMinMax|max|int}}"
          brightness: "{{strip02BrightValMinMax|max|int}}"
        target:
          entity_id: light.kitchen_strip_02
mode: single

Hi @revan415,
I am sorry to pick up an old thread, but I have just bought a new 4-colors led strip and I am trying to configure the white channel with the Shelly RGBW2.
I have other Shelly RGBW2 controllers, but they drive RGB strips. This is the first time that I got one with warm white as well.
I see in the status of the Shelly item no “rgbw_color” parameter, but only “rgb_color”.
If I try to set the rgbw_color parameter to [0 0 0 255], I get a white color from the mix of the other 3, but I do not get the original white leds on. It seems that the extra white is “mapped” into the mix of the other 3.
If I configure the white from the Shelly web interface directly, this is working well.
Any idea of what has changed or what can I do to solve the issue?
Thank you.

No worries, happy to help! Can you post a pic of your dev tools debug state for the entity? Mine looks like this:

effect_list:
  - "Off"
  - Meteor Shower
  - Gradual Change
  - Flash
supported_color_modes:
  - rgbw
color_mode: rgbw
brightness: 255
hs_color:
  - 60
  - 37.255
rgb_color:
  - 255
  - 255
  - 160
xy_color:
  - 0.387
  - 0.428
rgbw_color:
  - 255
  - 255
  - 65
  - 255
effect: "Off"
friendly_name: Kitchen Strip Left
supported_features: 36

Also, what is the device info look like? This is what mine shows:
Shelly RGBW2
Firmware: 20230913-113259/v1.14.0-gcb84623
Hardware: gen1 (SHRGBW2)

Also, check the Developer Tools, then Services tab, then pick ‘Light: Turn on’ and select the target entity as the rgbw2 in question. Mine actually shows input options for “Color”, “RGBW-color”, “RGBWW-color” and Hue/Sat, xy-color, brightness, steps, etc.

What gen device are you using? 1, 2, 3? I did have to go set in the rgbw2 settings the CoIoT field to my HA server.

1 Like

Nice pointer to check Developer Tools > Services, then you see exactly what is availble to control the entity :slight_smile:

Hi there,

if anyone is looking for a solution for this I managed to create one. It’s basically an automation which gets triggered once the brightness is changed or the RGBW values change.

Inititial RGBW values get stores in an option helper (input_select.array) which is absued as a global array storage. Once you change the brightness and the CW/WW or the RGW values the helper get updated and the values stored in there.

The strange +0.01,+0.02,… etc. is needed as it’s not allowed to have two options with the same name.

Hope this helps someone.
Happy greetings!

alias: RGBW White Adjustment 
description: "When you change the overall brightness of a Shelly RGBW2 device in Home Assistant the white channel gets not dimmed. Resulting in white colors on low brightness settings. This automation adjust the white channel after any brightness change"
trigger:
  - platform: state
    entity_id:
      - light.shellyrgbw2
    attribute: brightness
  - platform: state
    entity_id:
      - light.shellyrgbw2
    attribute: rgb_color
condition:
  - condition: state
    entity_id: light.shellyrgbw2
    state: "on"
action:
  - if:
      - condition: template
        value_template: "{{ true == (R==new_R) == (G==new_G) == (B==new_B) == (CW==new_CW) }}"
    then:
      - service: light.turn_on
        data:
          entity_id: light.shellyrgbw2
          rgbw_color:
            - "{{ R }}"
            - "{{ G }}"
            - "{{ B }}"
            - "{{ CW_Adj }}"
      - service: input_select.set_options
        target:
          entity_id: input_select.array
        data:
          options:
            - "{{ R+0.01 }}"
            - "{{ G+0.02 }}"
            - "{{ B+0.03  }}"
            - "{{ CW_Adj+0.04  }}"
            - "{{ new_BT+0.05  }}"
            - "{{ initial_CW+0.06  }}"
            - "{{ initial_BT+0.07  }}"
    else:
      - service: input_select.set_options
        target:
          entity_id: input_select.array
        data:
          options:
            - "{{ new_R+0.01 }}"
            - "{{ new_G+0.02 }}"
            - "{{ new_B+0.03  }}"
            - "{{ new_CW+0.04  }}"
            - "{{ new_BT+0.05  }}"
            - "{{ new_CW+0.06  }}"
            - "{{ new_BT+0.07  }}"
variables:
  R: "{{ state_attr('input_select.array','options')[0]|int }}"
  G: "{{ state_attr('input_select.array','options')[1]|int }}"
  B: "{{ state_attr('input_select.array','options')[2]|int }}"
  CW: "{{ state_attr('input_select.array','options')[3]|int }}"
  BT: "{{ state_attr('input_select.array','options')[4]|int }}"
  initial_CW: "{{ state_attr('input_select.array','options')[5]|int }}"
  initial_BT: "{{ state_attr('input_select.array','options')[6]|int }}"
  new_R: "{{ state_attr('light.shellyrgbw2','rgbw_color')[0]|int }}"
  new_G: "{{ state_attr('light.shellyrgbw2','rgbw_color')[1]|int }}"
  new_B: "{{ state_attr('light.shellyrgbw2','rgbw_color')[2]|int }}"
  new_CW: "{{ state_attr('light.shellyrgbw2','rgbw_color')[3]|int }}"
  new_BT: "{{ state_attr('light.shellyrgbw2','brightness')|int }}"
  x: "{{ initial_CW - ( (initial_BT-new_BT)/initial_BT * initial_CW )  }}"
  CW_Adj: "{{ ([0,[x,255]|min]|max)|int }}"
mode: single

Edit: Added the == true in the if-action so the if clause is not true when all values changed at once.

This is cool! Good solution to fix the lack of proper brightness control on these devices.

sorry to revive an old thread but can you explain how can we add this automation ? @Thotto

Managed to add it in automation but seems that it’s not working. My RGB brightness is zero and only the white Chanel is on but impossible to change the brightness.

Finally managed to add the automation and changed the light.shellyrgbw2 with my light id but when running the automation i’m getting below error in the logs:
Error rendering variables: UndefinedError: None has no element 0

Any idea what could be causing this ?

Hi mate,

did you create the helper (input_select) named “array” with the following options (0-6)? This is important to store the initial values once the color or white channel is changed.

Incredible … sometimes I’m an idiot. It worked perfectly.

Now, if I have 3 RGBW I need to create 3 automations (of course) and 3 helpers array’s, right ?

I was on the point of selling all shelly RGBW’s but it worked with automation and array for each of them, thank you !!

What i’ve noticed, if brightness is set to 100% and you take it down to 50% it’s triggering the automation but not the actual brightness.

If i set it to any value under 10%, it’s triggering the automation and also the actual brightness of the led strip.

Any ideas with what values should I play ?

LE: so did some more troubleshooting

Any value of the LED brightness between 6% and 100% - keeps the rgbw white brightness at 100%
5% - white at 90%
1% - white at 33%

@Thotto

Hello mate,

I am super happy that I saved your devices and your money. Was super annoying for me as well.

The actual white channel brightness is based on the initial brightness +/- the current overall brightness in comparison to the initial. I have made it like that do your color will remain hopefully the same on dimming.

For me it works quite well. I could only think of your white channel was on 100% when your overall brightness was at 6% in your example. For sure when setting the overall brightness higher white channel will stay at 100% and only be changed on overall brightness’s between 1-5%.

I do the following. I choose the color which I like at max brightness setting and than when lowering the brightness white channel setting will follow.

Example attached - hope it’s clear for you. Hard to describe.

IMG_9415

Hi Thotto,

Yes, totally true. I’ve played around with it and moved all at 0 brightness then at full and got the correct brightness level but only after deactivate and re-activate the automation.

Anyway, your workaround saved a lot of people, including me, money and frustration.

Thank you so much !!

1 Like

Anyone finding this like i did and its after (i don’t know when it started) but after today Oct 20, 2024. I added a Shelly Plus RGBW PM. i assume (i know) that it will work on others; but i don’t have to add any code to get this to work in automation. Once that device was imported in, and i choose service “Light: Turn on” not device and then choose my entity, i have the options all the options and its working for me. Color, transition, temp, brightness, etc.

Just a heads up to all thinking the above was the only solution. It might solve other problems, but for me its working fine. **NOTE i do have my shelly device updated to an Oct 2024 firmware release; not sure if that matters to if this solution works or not.