Lovelace slider-entity-row with template lights

I’m using the Lovelace slider entity row with a template light. When I move the slider bar (see the Falls Pump) the brightness level (on the right) does not change.

r/homeassistant - Lovelace slider-entity-row with template lights
slide bar set to 5 but is shown as 1 (on the right)

Do I need to do something different since this is a template light rather than a regular light? When I look at the light.falls_pump in developer tools it also shows the brightness as 1.

r/homeassistant - Lovelace slider-entity-row with template lights
Does the “supported_features: 0” mean I have a problem?

I would like to use the slider value to send a restful call to the pump to change speed but I don’t know how to do that with no change in the brightness. I assumed I would be using the “brightness” value but that isn’t changing.

r/homeassistant - Lovelace slider-entity-row with template lights
Lovelace slider-entity yaml

r/homeassistant - Lovelace slider-entity-row with template lights
Template light definition

Both the level_template and the value_template are retrieved via restful command and they do work well. If the pump speeds change outside of HA the values do change on the slider_entity.

My problem is that if I change the value (via the slider bar) in HA it doesn’t update the “brightness” value. Any ideas on what I’m doing wrong?

Thanks for taking a look at this.

I tried changing the set_level to this:

      set_level:
        service: script.falls_pump_level
        data:
          brightness: "{{ state_attr('light.falls_pump', 'brightness') }}"

and it still had no affect.

I’d first double check that the script falls_pump_level actually exists and accepts a parameter named brightness etc.

The script exists but I don’t pass it a parameter. I use state_attr(‘light.falls_pump’, ‘brightness’) in my restful command which never gets the new value. Is this what I’m doing incorrect? I need to set the brightness on the slider? When I’ve used the slider with regular lights, just changing the slider manually changes it’s value.

falls_pump_level script

alias: falls_pump_level
sequence:
  - service: rest_command.falls_pump_on
    data: {}
  - service: rest_command.set_falls_pump_speed
    data: {}
  - service: notify.gmail_smtp_email_and_text
    data:
      message: >-
        The falls pump level has changed to ???   air temperature {{
        states("sensor.average_temperature") }} - {{ now().strftime("%-m.%-d.%Y
        %-I:%M:%S %p") }} HA
      title: Falls pump level has changed
mode: single
icon: mdi:waves-arrow-up

configuration.yaml

  set_falls_pump_speed:
    url: !secret url_set_falls_pump_speed

secrets.yaml

url_set_falls_pump_speed: “https://smartcontrol.aquascapeinc.com/external/api/update?token=MyToken&v2={{ state_attr(‘light.falls_pump’, ‘brightness’) }}”

I changed the falls_pump_level script to the following:

alias: falls_pump_level
sequence:
  - service: light.turn_on
    target:
      entity_id: light.falls_pump
    data:
      brightness: "{{ brightness }}"
  - service: rest_command.falls_pump_on
    data: {}
  - service: rest_command.set_falls_pump_speed
    data: {}
    enabled: false
  - service: notify.gmail_smtp_email_and_text
    data:
      message: >-
        The falls pump level has changed to "{{ brightness }}"   air temperature is  
        {{ states("sensor.average_temperature") }} - {{ now().strftime("%-m.%-d.%Y
        %-I:%M:%S %p") }} HA
      title: Falls pump level has changed
mode: single
icon: mdi:waves-arrow-up

I know the script is receiving the value of the slider bar since it is sent to me in the notifies but

  - service: light.turn_on
    target:
      entity_id: light.falls_pump
    data:
      brightness: "{{ brightness }}"

does NOT change the value of state_attr(‘light.falls_pump’, ‘brightness’) so the brightness value is never updated.

I’ve tried casting brightness to an int before the data assignment but that has no affect either. I’m just not sure how I’m supposed to be using {{ brightness }} for this assignment.

note: I have rest_command.set_falls_pump_speed disabled for now since it would not be receiving the correct value.

Hm, took me a while to understand your setup, but I think I got it now :slight_smile:

Still not entirely sure what’s going on, but two ideas:

a) Have you seen on GitHub - thomasloven/lovelace-slider-entity-row: 🔹 Add sliders to entity cards that the default brightness value for a light is brightness_pct? Maybe change it to brightness?

b) Can you call the light.turn_on service with the brightness setting from the developer menu? This is easier to debug there, than the UI.

Thanks for your continued help @nilsreiter. No I overlooked the fact that brightness_pct is the default. I think just by referencing “brightness” rather than pct - brightness is used. Since my last post I tried two slider bar tests - one with just a regular light and the other with my template light.

If I use this code, the chandelier light (regular light) is turned on:

alias: Test chandelier brightness
description: ""
trigger: []
condition: []
action:
  - service: light.turn_on
    data:
      brightness: 50
    target:
      entity_id: light.sunrmchandelier1
mode: single

But using almost same code on my template light - it doesn’t work.

alias: Test falls pump
description: ""
trigger: []
condition: []
action:
  - service: light.turn_on
    data:
      brightness: 2
    target:
      entity_id:
        - light.falls_pump
mode: single

There are two differences between these two “lights”. The chandelier light has a normal 0-255 brightness range whereas the falls pump is only 1-10 brightness value.
The second difference is the the falls pump is a template light not a regular light as the chandelier is.

This is the part that is driving me nuts. Having not worked with a template light before I’m not sure if I have that set up correctly.

I think the important thing is that a light is defined in HA with a brightness between 0-255. So your 0-10 or so of your pump needs to be translated into this range. See example from the docs copied below.

Second, the slider entity for a light is also 0-255 based. And it just retrieves the value from the level_template (which gets its input from the slider), so if you disable your set_level script then the state of the light cannot change.

Thus both level_template and set_level need to be converted to values between 0-255. The min/max/step options of the slider-entity-row should not be used, as you mimic a light. You may of course display the actual 0-10 value of your sensor separately in Lovelace.

HTH

light:
  - platform: template
    lights:
      theater_volume:
        friendly_name: "Receiver Volume"
        value_template: >-
          {% if is_state('media_player.receiver', 'on') %}
            {% if state_attr('media_player.receiver', 'is_volume_muted') %}
              off
            {% else %}
              on
            {% endif %}
          {% else %}
            off
          {% endif %}
        turn_on:
          service: media_player.volume_mute
          target:
            entity_id: media_player.receiver
          data:
            is_volume_muted: false
        turn_off:
          service: media_player.volume_mute
          target:
            entity_id: media_player.receiver
          data:
            is_volume_muted: true
        set_level:
          service: media_player.volume_set
          target:
            entity_id: media_player.receiver
          data:
            volume_level: "{{ (brightness / 255 * 100)|int / 100 }}"
        level_template: >-
          {% if is_state('media_player.receiver', 'on') %}
            {{ (state_attr('media_player.receiver', 'volume_level')|float * 255)|int }}
          {% else %}
            0
          {% endif %}

Thank you, thank you, thank you @verjager. I’ll get this switched tomorrow and hopefully finally have it totally working.