Add input_number slider as volume_set In Universal Media Player

Hi, I have a input_number entity that syncs and adjusts volume via an automation working well.
My goal is to have it integrated into my Universal Media Player entity as volume_set.

Section from Universal

      volume_set:
        service: media_player.volume_set
        data_template:
          entity_id: input_number.slider1
          volume_level: "{{ value('input_number.slider1') | float }}"

input_number

input_number:
  slider1:
    name: Slider
    min: 0.00
    max: 1.00
    step: 0.01

With the above, I get nothing but this in logs.

UndefinedError: ‘mappingproxy object’ has no attribute ‘volume_level’

I have also tried an automaton and sensor.
When I add an MQTT sensor that pulls the volume value to universals attributes section it shows a slider with current volume. But when using it, it just reverts to last value, with this in logs.

[homeassistant.helpers.service] Error rendering data template: UndefinedError: ‘value’ is undefined

- id: mediaplayer-slider-sync
  trigger:
    platform: state
    entity_id: media_player.tvtest
  action:
    service: input_number.set_value
    data_template:
      entity_id: input_number.slider1
      value: >
        {{ states.media_player.tvtest.attributes.volume_level | float }}
sensor:
  - platform: mqtt
    name: "Current TV Volume"
    state_topic: "/remoteapp/mobile/broadcast/platform_service/actions/volumechange"
    value_template: '{{value_json.volume_value / 100 | float }}'

I just want the volume slider working !
Can anyone help?

What output does this produce in the developer tools template editor:

{{ states.media_player.tvtest.attributes }}

Try it with the media player on and off.

I suspect the volume_level attribute is only available when the media player is on.

There are ways around this but check that the volume level is available with the media player on first.

I get this when player is on or off.

{‘volume_level’: ‘0.11’, ‘is_volume_muted’: False, ‘media_content_type’: ‘channel’, ‘source_list’: [‘ABC’, ‘SBS ONE’, ‘Channel 7’, ‘Channel 9’, ‘10’, ‘10 Bold’, ‘10 Peach’, ‘TVSN’, ‘SpreeTV’, ‘ABC Comedy/Kids’], ‘active_child’: ‘media_player.living_room_tv’, ‘friendly_name’: ‘TVTEST’, ‘supported_features’: 3516}

Well that’s good.

Try this:

- id: mediaplayer-slider-sync-one-way
  trigger:
    platform: state
    entity_id: input_number.slider1
  action:
    service: media_player.volume_set
    data_template:
      entity_id: media_player.tvtest
      volume_level: >
        {{ states('input_number.slider1') | float }}

With this automation you should be able to control the media player volume with the slider. If it does not work, try it like this:

- id: mediaplayer-slider-sync-one-way
  trigger:
    platform: state
    entity_id: input_number.slider1
  action:
    service: media_player.volume_set
    entity_id: media_player.tvtest
    data_template:
      volume_level: >
        {{ states('input_number.slider1') | float }}

Getting it to work both ways may cause a loop, but see if this works first.

Also instead of creating your own interface have you seen this (it’s very customisable):

I’ve used it to create a very minimalistic interface:

Screenshot_2019-11-30%20Home%20Assistant(2)

You could go further and have nothing but the volume slider, if that’s what you want.

I tried both but still get the same as before with and without the volume_level attribute pointing to a sensor with the volume.
When I use the attribute, I get a slider in the media player interface that is in the same position as the input_number slider. But it shows no numbers (?) and snaps back to original position when you try and adjust it.
So I though it could be possible to do the reverse and automate adjusting the slider that now shows in the media player to adjust the input_number slider. but still nothing…

- id: mediaplayer-slider-sync
  trigger:
    platform: state
    entity_id: media_player.tvtest
  action:
    service: input_number.set_value
    data_template:
      entity_id: input_number.slider1
      value: >
        {{ states.media_player.tvtest.attributes.volume_level | float }}

But adjusting this slider is not changing the volume so it doesn’t trigger anything anyway…

I would use a custom lovelace card, but i’m planning on using this to pass to google assistant to use commands and a homehub display to operate it.

Try the mini media player.

I figured it out ! Long story short, I was using volume_set very incorrectly.
I finally found a few examples of correct usage with MQTT.
The TV is controlled directly via MQTT, I guess i should have mentioned that…
Didn’t need an input_number entity at all. Just a sensor.

      volume_set:
        service: mqtt.publish
        data_template:
            topic: /remoteapp/tv/platform_service/08:C5:E1:4F:7B:96$normal/actions/changevolume
            payload: '{{ (volume_level * 100) | round(0) }}'
    attributes:
          state: switch.tvstate
          volume_level: sensor.current_tv_volume
1 Like

@tom_l do you know of a setting in the mini player that will display a numeric value for the volume level.? I want to try changing from the slider to the plus and minus using the volume_stateless but I want to see the level it’s set at…