This is working great! But now I also want to have an automation that will adjust the volume slider itself when the receiver changes state. This however is not working… not sure how I can readout the attribute of the media player correctly to pass along the input_number?
Current try in automations.yaml
- alias: Denon - Adjust input number
initial_state: true
trigger:
platform: state
entity_id: media_player.denon_avr_x2100w
to: 'playing'
action:
- service: input_number.set_value
entity_id: input_number.denon_volume
data_template:
value: "{{ media_player.denon_avr_x2100w.volume_level }}"
Gives following exception in the log
ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: 'media_player' is undefined
ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: 'homeassistant.core.State object' has no attribute 'volume_level'
With
- alias: Denon - Adjust input number
initial_state: true
trigger:
platform: state
entity_id: media_player.denon_avr_x2100w
to: 'playing'
action:
- service: input_number.set_value
data_template:
entity_id: input_number.denon_volume
value: "{{ states.media_player.denon_avr_x2100w.volume_level.state }}"
The media player does have the volume_level data property when I check the json structure… not sure how to use it here though…
Yeah, the thing is that volume_level ist not the state but only an sub-attribute.
If you look here: Automation Trigger - Home Assistant
you can see that they are accessing those attributes like this
state.attributes.battery
So based on that i’d guess that you need something like this:
states.media_player.denon_avr_x2100w.attributes.volume_level
@jo-me AWESOME! That did the trick… was not sure how to read out those attributes.
Now that it is working, I’m actually thinking this is not completely a correct setup.
Because I would rather want to register volume changes of the receiver itself as a trigger to the input_volume slider. Not sure if this can be monitored with a trigger though?
Yes that should also work. It is basically what the example in the link above does. Search for the snippet I posted on the page l linked and you’ll find an example on how to use an attribute as automation trigger.