Hello everyone!
I’ve been scraching my head big time on how to do this automation.
I have a Sony Android TV which HA see’s as media_player.sony_bravia_tv which has a volume control (volume_up, volume_down, volume_set).
I’m trying to set u a trigger when volume goes up to action a script called script.volumeup and when volume goes down to action a script called script.volumedown.
The volume scripts send mqtt messages to my nodemcu which has IR sender on it controlling my sound sistem. The script is all set. All I need is the automation, so when I change volume on the TV it will chage volume on my sound system as I want to use optical out on TV.
I don’t think bravia can tell you the volume level its on or that volume is changing so I don’t think HA can know that volume is being turned up. You might try to use lirc component to read the IR from the remote.
I can click in HA on volume up/down so the must be a way to do it. I had a look at what other people were doing in regards to volume control, but I couldn’t find the answer to what I am trying to acheive.
Just because you can adjust a hardware device does not mean you can monitor the state of it. Check the states of your bravia tv. My guess is that it would be named media_player.braviatv or something like that. If that state object does not contain a volume level, then you are out of luck.
Lol, its all good. The good news is that from the looks of it, you can use the volume_level attribute to perform your automations. It should update when you use your remote as well.
This is an example of what I have done in the past using a slider bar and the volume_level attribute for my media_players.
- alias: Set Zone 1 Slider
trigger:
- platform: state
entity_id: media_player.yamaha_receiver
condition:
- condition: template
value_template: >
{% if is_state('media_player.yamaha_receiver','off') %}
true
{% else %}
{% if is_state_attr('media_player.yamaha_receiver', 'volume_level', states('input_number.yamaha_receiver') | int / 100) %}
false
{% else %}
true
{% endif %}
{% endif %}
action:
- service: input_number.set_value
entity_id: input_number.yamaha_receiver
data_template:
value: >
{% if trigger.to_state.state == 'on' %}
{% set n = trigger.to_state.attributes.volume_level | float %}
{{ (n - 1.0)*100.0 | int }}
{% else %}
-80
{% endif %}
- alias: Set Zone 1 Volume
trigger:
- platform: state
entity_id: input_number.yamaha_receiver
condition:
- condition: template
value_template: >
{% if is_state('media_player.yamaha_receiver', 'on') %}
{% if not is_state_attr('media_player.yamaha_receiver', 'volume_level', states('input_number.yamaha_receiver') | int / 100) %}
true
{% else %}
false
{% endif %}
{% else %}
false
{% endif %}
action:
- service: media_player.volume_set
entity_id: media_player.yamaha_receiver
data_template:
volume_level: >
{% set n = states('input_number.yamaha_receiver') | float %}
{{ n / 100 + 1 }}
- alias: Set Zone 2 Slider
trigger:
- platform: state
entity_id: media_player.yamaha_receiver_zone_2
condition:
- condition: template
value_template: >
{% if is_state('media_player.yamaha_receiver_zone_2','off') %}
true
{% else %}
{% if is_state_attr('media_player.yamaha_receiver_zone_2', 'volume_level', states('input_number.yamaha_receiver_zone_2') | int / 100) %}
false
{% else %}
true
{% endif %}
{% endif %}
action:
- service: input_number.set_value
entity_id: input_number.yamaha_receiver_zone_2
data_template:
value: >
{% if trigger.to_state.state == 'on' %}
{% set n = trigger.to_state.attributes.volume_level | float %}
{{ (n - 1.0)*100.0 | int }}
{% else %}
-80
{% endif %}
- alias: Set Zone 2 Volume
trigger:
- platform: state
entity_id: input_number.yamaha_receiver_zone_2
condition:
- condition: template
value_template: >
{% if is_state('media_player.yamaha_receiver_zone_2', 'on') %}
{% if not is_state_attr('media_player.yamaha_receiver_zone_2', 'volume_level', states('input_number.yamaha_receiver_zone_2') | int / 100) %}
true
{% else %}
false
{% endif %}
{% else %}
false
{% endif %}
action:
- service: media_player.volume_set
entity_id: media_player.yamaha_receiver_zone_2
data_template:
volume_level: >
{% set n = states('input_number.yamaha_receiver_zone_2') | float %}
{{ (n / 100.0) + 1.0 }}
The math performed on my slider bars is because my receiver displays decibels for some stupid reason. So i had to convert it.
So you could just remove the n / 100 + 1 crap you see everywhere and get it working with sliders.
I appreciate you reply but this doesn’t actually work for me.
I have the action in form of a script
what I’m missing is the trigger
when volume decreases I want to call script volume down and when volume increases I want to call script volume down.
Someone suggested Binary sensor trend
I’ve set it up but it doesn’t go on when I change volume. The sensor for the volume works fine, it does change volume.
binary_sensor:
trigger:
- platform: state
entity_id: media_player.sony_bravia_tv
condition:
condition: template
value_template: >
{% set from = trigger.from_state.attributes.volume_level | float %}
{% set to = trigger.to_state.attributes.volume_level | float %}
{{ to > from }}
Volume down:
trigger:
- platform: state
entity_id: media_player.sony_bravia_tv
condition:
condition: template
value_template: >
{% set from = trigger.from_state.attributes.volume_level | float %}
{% set to = trigger.to_state.attributes.volume_level | float %}
{{ to < from }}
I’ve spent load of hours trying to find a soluton. I can’t thank you enough!
Cheers!
It does work!
So, don’t know if I was clear but I have a sony android tv on which I wanted to use the original remote to control volume but not for the tv but for my surround sound system because the optical link between them.
I’ve setup a nodemcu with IR sender on it next ot the IR receiver for the surround sound system and I’m now pressing the volume on the remote which triggers the automation which calls script volume up or down. The script contains the IR code which is sent via MQTT to nodemcu. Does it make sense?
It’s like scratching your left ear with you right hand above your head. BUT it works.
The only thing that I can’t do at the moment is if I keep volume up/down pressed on the TV remote it won’t actually turn the volume up/down as much as I would like and I understand why. You can’t have it all…
Small thing to point out. there is a 5-10 seconds delay from the time that I press volume button on tv remote till sound system changes volume.
Once again! Thanks Petro! I hope this post will help other people with their automations!
Lol, thats a pretty cool work around. Glad it works.
You can remove some of the delay by switching over to appdaemon. I’m not sure how much delay will get removed for you. It ended up removing about ~1 second for me with the automations I posted above. At the time, they were taking ~2 seconds to fire. It might chop off ~5 seconds for you. But that would require you to learn python if you don’t already know it.
Dear,
i tried many ways to get it working but unable to do so
i have android tv box ( mini m8sii)
and i wanted volume bar for it,
can you please guide me,
thanks in adv
I have deleted all files related to slider,
I wanted to play media files in morning with volume to 25%,
thats what i want to do
I have Mini M8sii ( Andorid TV Box) witn onkyo receriver.
and i have installed HA on my oprange Pi +2e.
Please
yes it does
i am using broadlink rm mini3 to control all my media devices
my media configuration
platform: broadlink
host: 192.168.11.19
mac: ‘34:EA:34:58:BD:36’
name: SamsungTv
ircodes_ini: ‘broadlink_media_codes/samsung.ini’
ping_host: 192.168.11.37
and i am using vassils vpnmaster
dear,
i think this will be too hard for me to go around,
If you can help me that would make me my automation work,
else i think i have to stop automation for my media player