Media Player Volume Slider and Source Select

I have my denon ARV set up as a media player but I would like to display the volume controls and source options on a card, without having to click on the media player control to get to this menu:

image

Is that possible? How to go about it?

2 Likes

Hereā€™s what I have for Denon volume slider on my Denon S720W. If you have a different model it might need some changes, but you could try this. It updates both ways so the volume slider should stay in sync even if you change from a TV remote etcā€¦

input_number:
  denon_volume:
    icon: mdi:volume-medium
    name: Volume
    initial: 30
    min: 1
    max: 100
    step: 1
sensor:
  - platform: template
    sensors:
      denon_volume:
        value_template: >
          {% if is_state('media_player.denon_avr_s720w', 'on')  %}
            {{ (state_attr('media_player.denon_avr_s720w', 'volume_level') * 100) | int }}
          {% endif %}
        friendly_name: Receiver Volume Level
        icon_template: mdi:volume-medium
automation:

  - alias: "Denon Set Volume"
    initial_state: 'on'
    trigger:
      platform: state
      entity_id: input_number.denon_volume
    action:
      - service: media_player.volume_set
        data_template:
          entity_id: media_player.denon_avr_s720w
          volume_level: >
            {{states('input_number.denon_volume') | int / 100}}

  - alias: "Denon Update Volume Slider"
    initial_state: 'on'
    trigger:
      - platform: state
        entity_id: sensor.denon_volume
      - platform: homeassistant
        event: start
    condition:
      condition: state
      entity_id: media_player.denon_avr_s720w # receiver must be on to set the volume, without this would throw error on startup
      state: 'on'
    action:
      - delay:
          seconds: 3
      - service: input_number.set_value
        data_template:
          entity_id: input_number.denon_volume
          value: '{{ trigger.to_state.state }}'

(This gives you a slider only, not the mute button etc). Display in your Lovelace with the input_number.denon_volume entity.

3 Likes

I will give that a shot later, thanks.
Is it possible to do the sources the same way?

The mini media player card has access to both source and volume in the card.

EDIT: here https://github.com/kalkih/mini-media-player and installable with HACS.

2 Likes

That looks exactly like what I need.
Iā€™m new enough to HA/yaml and as I understand it when referencing the ui-lovelace.yaml file, it means the UI edit of HA is no longer possible and all changes need to be directly into the ui-lovelace.yaml file?

newbie here - can you tell me what yaml file(s) the code goes into?

Look at the top of the page. Click ā€œDocsā€. Read.

This type of comment is why alot of people dont like asking for help as you come back with comments like you, you might understand this well but other dont

2 Likes

What so youā€™d rather I copy and paste the docs in here?

1 Like

Yea like to the document would have been nice,something like, this type of info can be found in the document area, here is a link to it ā€œlinkā€ i hope it help. Basicly the same thing but read a lot better

2 Likes

Hey Sean, with your slider code, how does the ā€œinitialā€ for the input_number work? So what I get on a fresh restart is it shows 30 and the slider is real low. If I move my harmony remote up and down a bit it then adjusts to the current volume level that the remote is at. So my remote may be at a level of 60 when HA restarts but sits at 30 until itā€™s changed or moved unless it would have eventually adjusted on itā€™s own.

I would suggest just removing that initial: 30 line.

Itā€™s not needed and in hindsight just complicated things. The idea of it was to make my receiver always have an initial volume level of 30, but it didnā€™t work how I wanted and I never cared enough to look into fixing it.

By deleting that ā€œinitialā€ line it will just remember your last volume level upon restart. So if itā€™s at volume 60 on your remote/receiver, the input_number in Home Assistant should also remain at 60 even after a restart. That is probably the behavior you and most people want.

1 Like

Thanks Iā€™ll do that. Iā€™m having a visual problem with the slider:

image
So it works good but for the above, when on mobile, the 63 is cut off. If I turn the screen landscape it is there but cutting it off for some reason on portrait. Assuming itā€™s cut off and not a view change based on where and how itā€™s being viewed. So like the right side is cut off.

EDIT: Also I am getting an error in the logs:

2020-03-17 19:25:14 ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: 'dict object' has no attribute 'to_state'

Thinking itā€™s from this part of the automation?

value: '{{ trigger.to_state.state }}'

Good catch on that visual issue, I believe that might be a bug in the frontend and just opened an issue for it here: https://github.com/home-assistant/frontend/issues/5266

Not sure on the template part, hopefully someone else can help you with that.

For the input number can you not set negative values? Like on my Denon itā€™s basically -79dB to 18.5db. I get errors like:

Error while executing automation automation.denon_set_volume. Invalid data for call_service at pos 1: value must be at least 0 for dictionary value @ data[ā€˜volume_levelā€™]

So then technically the volume on the slider doesnā€™t match whatā€™s on the TV.

@nickrout Iā€™ve tried installing the resource for the mini media player. Did as the documentation says but when checking the config it gives me an error that it canā€™t find the resource. I do have the file in my www folder. I also tried doing it through the resources tab and still not getting it to show up in the UI when adding a new card. What am I doing wrong?

Better to ask in the main thread for the card.

Still getting this in the logs. Thought Iā€™d see if anyone knows as trying to clean up the logs. Imagine the error means itā€™s not doing anything but not sure.