Automation: Syncing Switch to White in RGBW Issue

I used to have this working using data templates for years and something broke over the past several months, I think it has to do with the revamping of RGBW control.

When the white brightness on the lights change, it updates the level on the switch. And when the level on the switch is changed, it updates the white brightness.

I understand data_template is now gone, so far I’m having trouble with this portion for the action:

service: light.turn_on
data:
  rgbw_color_template:
    - 0
    - 0
    - 0
    - "{{ state_attr(\"light.kitchen_counter_sw\"), \"brightness\" }}"
target:
  entity_id: light.kitchen_counter

However it results in the following error:
2022-12-25 08:51:43.714 ERROR (MainThread) [homeassistant.components.automation.kitchen_counter_light_on] Kitchen Counter Light On: Error executing script. Invalid data for call_service at pos 2: extra keys not allowed @ data[‘white_value’]

2022-12-25 08:51:43.720 ERROR (MainThread) [homeassistant.components.automation.kitchen_counter_light_on] Error while executing automation automation.kitchen_counter_light_on: extra keys not allowed @ data[‘white_value’]

What do I need to change? There has been a drastic change in the syntax since I first had this working.

You should replace the \" with ', I’m never escaping the double quotes, maybe it is ok, never tried.
Also, I did a test, using one of my input_number, but using the syntax I’m more familiar with and it worked.

service: light.turn_on
data:
  color_rgbw: "0,0,0,{{ states('input_number.duree_coucher') | int }}"
target:
  entity_id: light.chambre_parents

Oddly enough I had it in your format to begin with but it was automatically changed to the format I had posted. Might have had something to do with the data item having _template postpended to the end.

I removed that and now after saving and running it removes the quotations, and I’m left with:

service: light.turn_on
data:
  color_rgbw: 0,0,0,{{ state_attr('light.kitchen_counter_sw', 'brightness') | int }}
target:
  entity_id: light.kitchen_counter

Which doesn’t seem to be a problem syntax wise, however I’m still getting the same error:

Error while executing automation automation.kitchen_counter_light_on: extra keys not allowed @ data[‘white_value’]

Kitchen Counter Light On: Error executing script. Invalid data for call_service at pos 2: extra keys not allowed @ data[‘white_value’]

The states for light.kitchen_counter (which a really a group of two wifi strip controllers) shows rgbw function:

min_color_temp_kelvin: 2702
max_color_temp_kelvin: 6535
min_mireds: 153
max_mireds: 370
effect_list: blue_fade, blue_strobe, colorjump, colorloop, colorstrobe, cyan_fade, cyan_strobe, gb_cross_fade, green_fade, green_strobe, purple_fade, purple_strobe, random, rb_cross_fade, red_fade, red_strobe, rg_cross_fade, white_fade, white_strobe, yellow_fade, yellow_strobe
supported_color_modes: color_temp, rgbw
entity_id: light.kitchen_stove, light.kitchen_prep
icon: mdi:wall-sconce-flat
friendly_name: Kitchen Counter
supported_features: 36
color_mode: rgbw
brightness: 88
hs_color: 60, 0.578
rgb_color: 173, 173, 172
rgbw_color: 2, 2, 1, 173
xy_color: 0.324, 0.33```

I think I found the issue, there is more to the automations than I realized that I have in automations.yaml, lol! That’s why it wasn’t making any sense why it was referring to ‘white_value’ when it wasn’t visible in the UI editor…

Final state of my automation that is now working beautifully!

- id: sync_kitchen_counter_light
  alias: Sync Kitchen Counter Light
  trigger:
  - platform: state
    entity_id:
    - light.kitchen_counter
    id: kitchen_counter_change
    attribute: brightness
  - platform: state
    entity_id:
    - light.kitchen_counter_sw
    id: kitchen_counter_sw_change
    attribute: brightness
  - platform: state
    entity_id:
    - light.kitchen_counter_sw
    - light.kitchen_counter
    to: 'off'
    id: kitchen_counter_sw_off
  condition: []
  action:
  - choose:
    - conditions:
      - condition: trigger
        id: kitchen_counter_change
      - condition: state
        entity_id: light.kitchen_counter
        state: 'on'
      sequence:
      - service: light.turn_on
        data:
          brightness: '{{ state_attr(''light.kitchen_counter'', ''brightness'') |
            int * 2 }}'
        target:
          entity_id: light.kitchen_counter_sw
      - delay:
          hours: 0
          minutes: 0
          seconds: 2
          milliseconds: 0
    - conditions:
      - condition: trigger
        id: kitchen_counter_sw_change
      - condition: state
        entity_id: light.kitchen_counter_sw
        state: 'on'
      sequence:
      - service: light.turn_on
        data:
          rgbw_color:
          - 0
          - 0
          - 0
          - '{{ state_attr(''light.kitchen_counter_sw'', ''brightness'') | int }}'
        target:
          entity_id: light.kitchen_counter
    - conditions:
      - condition: trigger
        id: kitchen_counter_sw_off
      sequence:
      - service: light.turn_off
        data: {}
        target:
          entity_id:
          - light.kitchen_counter
          - light.kitchen_counter_sw
  mode: restart