Using sliders ("input_number") for volume and dimming

Hi, I want to control lights and volume with sliders, not + and - buttons. I tried to create input_number entities, and make automations for updating each way, but this approach has several drawbacks:

  • Quite a lot of code is required, and worse, must be duplicated (if I haven’t missed a good way of making generic automations)
  • I suspect loops might occur - slider is changed -> value is changed (and different values might be reported during the transition) -> slider is updated -> new value command is sent -> slider is changed

Is it possible somehow to just map a slider to an attribute?

here is my working configuration:
input_number:

tv_volume:
  name: volume
  icon: mdi:volume-medium
  initial: 0.5
  min: 0
  max: 1
  step: 0.01

automation:

- alias: Set TV volume
  initial_state: 'on'
  trigger:
  - platform: state
    entity_id: input_number.tv_volume
  action:
  - service: media_player.volume_set
    data_template:
      volume_level: '{{ states.input_number.tv_volume.state }}'
      entity_id: media_player.bnc

Thank you! I have a similar automation, but another automation is required in addition in order to update the slider when the brightness or volume is changed elsewhere. What I am really looking for, is a simpler way without having to create an input number and two automations for each of several tens of lights and a handful of media_players :slight_smile:

I understand, the update slider can be from another automation.

anyway if you want, i write a small script that will handle dim for all lights that are on,
i can post it if you like

Here is the script:

set_dim:
  alias: Set Lights brightness
  sequence:
  - service: light.turn_on
    data_template:
      entity_id: >
         light.dummy {% for state in states.light -%}
         {%- if state.state_with_unit =="on" %}
         , {{state.entity_id}}
         {% endif -%}
         {%- endfor -%}
      brightness_pct: '{{ states.input_number.dimlight.state }}'

Thanks a lot again :slight_smile: Unfortunately, what I really want is to have unique sliders for each light or media_player, and also to solve the looping problem, without having to write kilobytes of code. I am beginning to see the challenge, though - changing the value of a given attribute usually (?) requires calling some service, so there must be a somewhat complex mapping. Alternatively, light widgets could support a slider directly.

Oscillations confirmed :laughing:

the widget light_with_brightness gives you a on off switch where you can set brigthness with a slider.

for mediaplayer volume that isnt there, but its possible to create a custom widget based on the mediaplayer widget.
but you need to program in javascript for that.

edit: or you can create a small appdaemon app that set the volume for media players by changing a slider

1 Like

Where is the “light_with_brightness” widget? I don’t see it in the docs and when I try it, I get an error on the dashboard

hanginglamp:
  widget_type: light_with_brightness
  entity: light.hanging_lamp
  title: Hanging Lamp
  icon_on: mdi-ceiling-light
  icon_off: mdi-ceiling-light
  on_attributes:
    brightness: 250
    color_temp: 250

edit: Nevermind… found your custom widget repo on GitHub

oops, i thought it was implemented. :wink:
sorry when i would have realised i would have posted the link.

for others who read here, the light_with_brightness slider can be found here:

1 Like

Thank you! Is it planned for merging?

probably, but not in this way.
there is also a light with colorpicker

I think that Andrew will combine the 3 widgets at some point and you can chose by a setting, which one you like.
but he is a bit busy at the moment. :wink:

That’ll be great!! Hopefully we’ll be able to have both the colorpicker and brightness.