Closed x99percent closed 5 years ago
Can you reproduce this with a demo light?
light:
- platform: demo
It doesn't reproduce for me.
Also note that max: 100
is not doing what you might think it is doing. Light brightness is 0..255, so setting max to 100 you are just changing the slider range, i.e. slider at rightmost position at 100 will be at about 40% (100/255) brightness.
This is a template light, used because Lutron Caseta lights default to 100% brightness if you just hit the switch in HA and I was trying to break away from the 0-255 stuff. I can verify the brightness value in the Lutron app.
light.hallway = template light light.hallway_light = actual light, brought in via Lutron Caseta input_number.hallway_light = last brightness % of light, updated when there is a brightness change
- platform: template
lights:
hallway:
friendly_name: "Hallway Light"
value_template: "{{ is_state('light.hallway_light', 'on') }}"
level_template: >-
{% if is_state('light.hallway_light', 'on') %}
{{ (states.light.hallway_light.attributes.brightness * 100 / 255) | round | int }}
{% else %}
0
{% endif %}
turn_on:
service: light.turn_on
data_template:
entity_id: light.hallway_light
brightness_pct: "{{ states.input_number.hallway_light.state | int }}"
turn_off:
service: light.turn_off
entity_id: light.hallway_light
set_level:
service: light.turn_on
data_template:
entity_id: light.hallway_light
brightness_pct: "{{ brightness }}"
I can't reproduce the problem with a demo light. The weirdest part is why the pin would be off by a factor of 10, while the extra_data_template is showing the correct value.
I've dumbed the template light down as much as I can (removed the 0-100% <--> 0-255 stuff), and the slider is still off by a factor of 10 after a page refresh. (10/255 shows 100/255).
I don't have Lutron Caseta, so I can't try that. Could you try the same setup, but instead of Template+Input_number+Lutron try Template+input_number+demo ?
Found the problem: Due to a bug template light returns brightness as a string and customui doesn't handle it well.
HA versions 0.63, 0.63.1, 0.63.2 Custom UI version 20180126
When this light is set to 50%, everything behaves as you'd expect. If I refresh the page, the slider is shown all the way to the right, in the 100% position, while the actual light and the extra_data_template value are still at 50%.
If I use smaller values, like 6%, the slider will be shown at the 60% position after a refresh.