Hey guys,
i must have some basic error here, I cannot explain why this isn’t working. Can you take a look for me?
I am trying to set the brightness of a light entity using input_number helper with a template:
- service: light.turn_on
data:
entity_id: light.led
brightness: "{{ states.input_number.led_brightness.state | int }}"
I get this error message:
expected int for dictionary value @ data['brightness']
If i put the template above (input_number.led_brightness
) into the template dev_tools, I get this here:
This should be an integer. What is going wrong here?
Are you running a version lower than 0.115? Then you need to change data:
to data_template:
It’s also better to use this notation:
states('input_select.led_brightness')
instead of states.input_select........
As explained in the docs here .
Hi Burningstone, thank you for your response!
I am running the most current version: 0.117.1
Your point about the states
notation is valid, but I tried that also and I get the same error message
Hmm, can you show the full automation please?
123
(Taras)
November 2, 2020, 2:41pm
5
I doubt this is the cause of the problem but I just want to confirm it:
Have you changed the legacy_templates
option from its default value of true
to false
?
If you didn’t or aren’t familiar with the option then it’s probably not the cause of the problem you are experiencing.
Natives type support for template (beta)
It’s not an automation, it is a script. I am trying to build a custom slider to control two different LED strips. To do that I wrote a template light which uses this script to turn on:
led_turn_on:
sequence:
- service: light.turn_on
data:
entity_id: light.led_1
brightness: "{{ states('input_number.led_brightness') }}"
- service: light.turn_on
data:
entity_id: light.led_2
brightness: "{{ states('input_number.led_brightness') }}"
No, I have not changed the legacy_templates
option
Should the two LED strips mirror each other? Then it would probably better to use a light group instead.
Thank you @Burningstone
This is awesome, I love this community! I did not know about light groups and how they work. This is exactly what I was trying to accomplish. Until now I have only automated switches, I have just begun installing controllable lights.
123
(Taras)
November 2, 2020, 3:06pm
10
That’s a good solution for combining lights to operate as a single entity but doesn’t explain why you are receiving this error message:
expected int for dictionary value @ data['brightness']
In fact, you may get the same error message when your script attempts to set the brightness of the Light Group.
- service: light.turn_on
data:
entity_id: light.my_light_group
brightness: "{{ states.input_number.led_brightness.state | int }}"
EDIT
Using version 0.117.0, I could not reproduce the problem you are experiencing. No error message was produced when the following script was executed and the light’s brightness was set to the input_number’s value.
template_test:
sequence:
- service: light.turn_on
data:
entity_id: light.hallway
brightness: "{{ states('input_number.range') | int }}"
The script was executed from Configuration > Scripts.
1 Like