Error in data_template turning on lights

I am using that script after looking at the examples in the repository of the component

action:
  service: light.turn_on
  data_template:
    entity_id: light.yeelight_6
    kelvin: "{{ state_attr('sensor.circadian_values', 'colortemp') | int }}"
    brightness_pct: "{{ state_attr('switch.circadian_lighting_circadian_lighting', 'brightness') | int }}"

But also this give me same error…

I think the script you posted in the OP and the error you posted there aren’t related.

the error says “expected int for dictionary value @ data[‘color_temp’]” but the script doesn’t contain any date entry that is called “color_temp:”.

I think this happens in the background, it tries to convert the rgb vlaue to color temp and then sends the color temp to the light, but not sure on this one.

Did you see this? I wouldn’t call this poor docs…

Which version of HA are you using?

If that’s the case then that error is really confusing. How would one ever know that or how to check it if so?

1 Like

99% sure you’re right.

It was only an example… i tried both of the scripts but with the same error…

was the error the example or the script?

do you get the exact same error referencing color_temp with both scripts (using either rgb_color: or color_temp)?

Yes same error in both scripts… but, i repeat, if i use absolute values and not templates it works, so i think the error is in the script syntax…

Which version of HA are you using?

Latest, HA 0.117.6

That’s not the latest.

Aside from what burningstone said above about trying to force a list into an integer try adding “legacy_templates: false” into your “homeassistant:” section in your configuration.yaml.

That should make you start using the new template engine and once you remove that “int” it might keep it as a list and allow it to work.

as far as using color_temp: in the script it’s hard to tell why that would fail since we haven’t seen that script syntax or the data it relies on.

No, I don’t think so. That’s been reported multiple times now, that the new template engine converts list with only ints, separated by a comma to a string, no matter what you do.

See this post from Taras and the ones below it.

Yes, i know… :slight_smile:

In this case i must rewrite all the templates i have actually?

No, not likely. it only affects certain templates and most people don’t really notice.

I’m using it on 117.3 right now and I only had a few templates that needed conversions and they were all related to a custom component configuration (hass-variables)

Hmmm…I think that’s backwards based on this statement from that post:

I know it’s definitely a bit confusing.

What’s worse is that becxause of a bug in the template editor makes it difficult to test this functionality.

I recommend giving it a try and see what happens.

If i use the template in the model editor i get the right values, so why the script is wrong ???

1 Like

I do have the same problem since 118.3

entity_id: light.garten_oben
brightness: "200"
color_temp: '{{ state_attr("light.wohnzimmer_stlmp_unten","color_temp") |int }}'

Logger: homeassistant.components.websocket_api.http.connection
Source: core.py:1405
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 17:35:41 (5 occurrences)
Last logged: 17:49:43

[1741517536] expected int for dictionary value @ data['color_temp']
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 135, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1405, in async_call
    processed_data = handler.schema(service_data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 218, in __call__
    return self._exec((Schema(val) for val in self.validators), v)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 340, in _exec
    raise e if self.msg is None else AllInvalid(self.msg, path=path)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 336, in _exec
    v = func(v)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 215, in _run
    return self._exec(self._compiled, value, path)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 340, in _exec
    raise e if self.msg is None else AllInvalid(self.msg, path=path)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 338, in _exec
    v = func(path, v)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: expected int for dictionary value @ data['color_temp']

By the way: This works so far:

- service: light.turn_on
              entity_id: light.garten_unten
              data:
                brightness: "250"
                xy_color:
                  - "{{state_attr('wohnzimmer_fenster_oben','xy_color')[0]}}"
                  - "{{state_attr('wohnzimmer_fenster_oben','xy_color')[1]}}"

So what is the difference?
I created an issue on Github #43730

Hi all, does anybody have found a solution for this?
Meanwhile, the code which works so far suddenly throws an error since yesterday evening.
Why yesterday, why not from the beginning? I’m confused.

I believe not. I luckily came across this post after being confronted with the same error. I wanted to dynamically generate the values for rgb_color on a service call for lights on. Eventually this worked;

service: light.turn_on
target:
  entity_id: light.woonkamer_woonkamer_plafond_midden
data:
  rgb_color:
    - "{{ (range(0, 255)|random|int) }}"
    - "{{ (range(0, 255)|random|int) }}"
    - "{{ (range(0, 255)|random|int) }}"
  brightness: 159