How to access light group kelvin from state attributes?

I’m trying to programme a button to lower / raise the kelvin of a group of lights.

I based my code on some code that lowers and raises the light group brightness, but for some reason I’m having difficulty porting this to kelvin.

I think the issue may be accessing the kelvin attribute of the light group. When accessing the brightness, I was able to call this in a service call:

bri = states.light.kitchen_lights.attributes.brightness

in a service all. However, when I do the following:

kel = states.light.kitchen_lights.attributes.kelvin

I end up with an error:
“mappingproxy object’ has no attribute ‘kelvin’”

Full code for the automation is here:

- id: '1580246534378'
  alias: Kitchen Button - Lower Kelvin
  description: ''
  trigger:
  - device_id: 13646fb4d11343b5bfbfaf777cbb9857
    domain: deconz
    platform: device
    subtype: left
    type: remote_button_short_press
  condition: []
  action:
  - service: light.turn_on
    data_template:
      entity_id: light.kitchen_lights
      kelvin: '{% set kel = states.light.kitchen_lights.attributes.kelvin
        | int %} {{ [kel-200, 2200] | min }}'

Any ideas?

When you go to Developer Tools -> States and search for your entity, do you see the kelvin as an attribute there? I think for most lights the attribute is called color_temp, for my hue lights it is like this for example.

I’ve just looked, and all I can see is this in the state attributes:

min_mireds: 153
max_mireds: 500
friendly_name: Kitchen Lights
supported_features: 43

I know that brightness is supported, because that worked - so am I looking in the wrong place to see the attributes?

Is the light currently on? You will only see the attributes when the light is on.

Got it - it is indeed only brightness and color_temp listed!

So I notice that the data available in the state attributes is different to that listed in the service data attributes for light (https://www.home-assistant.io/integrations/light/)…

Just to confirm my understanding… are they different because the service calls are essentially functions to modify the state attributes? I’m just wondering why it’s possible to change the state attributes e.g., using kelvin, but that it’s not possible to actually retrieve the state attributes in kelvin…

Thanks!

Did you read this part at the top?

Most lights do not support all attributes. You can check the integration documentation of your particular light for hints, but in general, you will have to try things out and see what works.

The attributes differ based on what kind of light bulbs you have, some have kelvin, some have color_temp, maybe there are some that even have both.

Got it. Ok that makes sense.

Thanks for the help!

1 Like

Hi, since I am pretty new to automation templating (I think that’s how it called?), can you maybe explain your statement?

kelvin: '{% set kel = states.light.kitchen_lights.attributes.kelvin
        | int %} {{ [kel-200, 2200] | min }}'

I try to achieve the same thing for my yeelights, but it won’t work. I read all the docs about templating, Jinja2, … but I do not find them very helpful…

Thank you,
Steeveno