jono
(Jono)
June 30, 2017, 6:08am
1
I have some input sliders to adjust light brightness, and when moving the slider it shows the brightness level from 0 to 255.
Is there any way to change this to show the brightness from 0 to 100%? (while still moving the range from 0 to 255 in the background)
I’m guessing it would be possible with some sort of template, but have no idea how.
lambtho
(Lambtho)
June 30, 2017, 7:52am
2
Basically now you have an input slider called brightness that goes from 0-255, and an automation that changes light brightness when input slider state changes.
You could modify your slider to range from 0 to 100 and in your automation instead of having the slider from 0-255
data_template:
entity_id: light.bedroom
brightness: '{{ states.input_slider.brightness.state | int }}'
You could have something with a slider from 0-100 like (not sure about syntax, but that’s the idea)
data_template:
entity_id: light.bedroom
brightness: '{{ states.input_slider.brightness.state | float multiply(2.55) | round(0) }}'
jono
(Jono)
June 30, 2017, 9:14am
3
Thanks for the help!
I added this this to my HA, but it came back with an error message
- alias: "Office Light Brightness"
hide_entity: true
trigger:
platform: state
entity_id: input_slider.office_light_brightness
action:
- service: light.turn_on
data_template:
entity_id: light.office_light
brightness: '{{ states.input_slider.brightness.state | float multiply(2.55) | round(0) }}'
The error message said:
2017-06-30 10:12:48 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: invalid template (TemplateSyntaxError: expected token ‘end of print statement’, got ‘multiply’) for dictionary value @ data[‘action’][0][‘data_template’][‘brightness’]. Got None.
Any idea how to fix that?
lambtho
(Lambtho)
June 30, 2017, 9:29am
4
try (I tested it, it should work this time)
brightness: '{{ states.input_slider.brightness.state | int * 2.55 | round(0) }}'
note that you should also modify the name in the template, to match the name of your slider.
i.e. remplace states.input_slider.brightness.state
with states.input_slider.office_light_brightness.state
4 Likes
lambtho
(Lambtho)
June 30, 2017, 9:59am
6
Glad it worked. Flag my previous message as the solution, so It will directly show that the topic is solved
Hi,
I tried your solution, but I can’t get it to work. It still shows the value from 1 - 255 instead of 1 - 100.
My code is:
- alias: Lysstyrke
trigger:
platform: state
entity_id: input_number.slider1
action:
- service: light.turn_on
data_template:
entity_id: light.spisebord
brightness: '{{ states.input_number.slider1.state | int * 2.55 | round(0) }}'
Can you spot any issues here?
action:
- service: light.turn_on
data_template:
entity_id: light.spisebord
Off the top of my head move the entity_id line, so it’s like this:
action:
- service: light.turn_on
entity_id: light.spisebord
data_template:
brightness: '{{ states.input_number.slider1.state | int * 2.55 | round(0) }}'
1 Like
lambtho
(Lambtho)
October 28, 2017, 8:35am
10
also it should be /2.55 and not *2.55 I think…
Perhaps as it has changed from input_slider to input_number, you are not required to put the | int
.
Maybe just go with
brightness: '{{ states.input_number.slider1.state / 2.55 | round(0) }}'
elRadix
(elRadix)
October 28, 2017, 3:22pm
11
you should limit your inputnumber to max 100, and then it should work
input_number:
dimmer_slp1:
name: brightness
initial: 50
min: 0
max: 100
step: 5
mode: slider
1 Like
jono
(Jono)
October 31, 2017, 10:35am
12
Here’s an example of my config, it might help?
input_number:
office_light_brightness:
initial: 100
min: 0
max: 100
step: 5
automation:
- alias: "Office Light Brightness"
hide_entity: true
trigger:
platform: state
entity_id: input_number.office_light_brightness
action:
- service: light.turn_on
data_template:
entity_id: light.office_light
brightness: '{{ states.input_number.office_light_brightness.state | int * 2.55 | round(0) }}'
2 Likes