andrey-git / home-assistant-custom-ui

Custom UI elements for https://home-assistant.io
https://home-assistant.io
MIT License
528 stars 97 forks source link

Slider controls off by a factor of 10 after a page refresh #103

Closed x99percent closed 5 years ago

x99percent commented 6 years ago

HA versions 0.63, 0.63.1, 0.63.2 Custom UI version 20180126

light.hallway:
  custom_ui_state_card: state-card-custom-ui
  state_card_mode: break-slider-toggle
  stretch_slider: true
  extra_data_template: '${state === ''on'' ? (attributes.brightness + ''%'') : ''off'' }'
  slider_theme:
    min: 0
    max: 100
    pin: true
    off_when_min: true
    report_when_not_changed: false

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.

andrey-git commented 6 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.

x99percent commented 6 years ago

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.

x99percent commented 6 years ago

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).

andrey-git commented 6 years ago

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 ?

andrey-git commented 6 years ago

Found the problem: Due to a bug template light returns brightness as a string and customui doesn't handle it well.