I’ve been trying to come up with a solution to my problem so maybe i’ll start by layout that out first…
I have a Denon receiver which I want to control via Home Assistant. I know there’s a Denon platform already but it doesn’t do what I want, and a couple of times has put the receiver into 100% volume.
Ok so here’s the current state of things:
Scrape sensor to pull the current volume level from the receiver via HTTP every 10 secs - works fine:
So while the above mostly works, here’s my problem assuming the current volume level is -30dB, and the +10dB script is called:
The shell script uses the current sensor value for the volume
Adds +10dB
Sends the appropriate designated value (-20dB) to the receiver via curl
yay!
but if I activate any of the scripts within the next <10 seconds (prior to the scrape sensor picking up the new volume level), it just sends the previous designated volume level.
So my idea is to have another sensor (perhaps template??) that can hopefully do two things:
Every time the scrape sensor grabs a new value, apply it to this new sensor
Every time one of the scripts / shell commands is calculated, stick this new value into the sensor and remain until the scrape sensor goes and grabs the current value again
I’m not sure how to do it but i think this is what I need to do. Is it possible? Or am i way off?
You’d need an input number to store the value. You’d need an automation to to have the scrape sensor update the input number. And an automation for the input number to call a shell command based on the input number level. The value is essentially stored in the input number. Be warned tho, something like this will have a feedback loop and if your polling is set to 10 seconds, you might get wonkyness.
Your other option is to do the same thing with an mqtt sensor. Again, has the same limitations.
I guess in reality - i should maybe have the script or automation grab the current volume level from the receiver instead of getting it every 10 seconds.
So when the script or automation is called:
grab the current value
add or subtract the desired level
send command to receiver
it might add a bit of latency but it might work much more reliably.
Why can’t you use the component again? Seems like a waste of time when you got a component. I’m guessing the reason your volume is going to 100% with it is because the volume is getting set to zero which is high in decibels. I’d just not allow that.
it doesn’t allow me to make specific jumps in volume (ie +10, -10, +5, -5) which i need to work for google assistant integration.
our previous amp had direct +10/-10/+5/-5 commands which made life real easy and we got used to it.
as for the 100% volume thing - this was prior to any automation or scripts. I’d load up the HA app on my phone and see the volume slider sitting at max volume and try to drag it down only to have the amp receive the max volume command and almost blow our ears off. The platform driver is very limited with our receiver hence the wasting of time
Yah, but you can limit the volume slider by wrapping it against a numerical slider and constrain the numerical slider to values that you want. That’s what I did, I allow mine to go between -80 and -10 db. Anytime a move over (under) -10 forces it to -10 without sending the signal to the receiver. Just hide the media control in the UI and it won’t ever be a problem.
Beauty of this setup is that it inverts the slider. So when the system starts up, it will be low worse case scenario. The input slider also store’s the volume of your slider if you remove initial -80 and use restore state.
yamaha_receiver:
name: Zone 1 Volume
initial: -80
min: -80
max: 0
step: 5
unit_of_measurement: dB
In case you’re interested, I had a PR a few days ago that added template functionalities to input_number that allowed its value to be updated based on a template, and allowed for running a script (or sequence of services) when its value is changed via input_number.set_value. It didn’t get merged, but you could use or adapt the code if you’d like. I think it would enable you to accomplish this without having to define those automations.
Thanks. I actually don’t use those automations anymore, moved over to appdeamon a few years ago. I just dug em up from when I used the built in automations.
thanks a bunch @petro. I’ve tried to apply your code to my config but for whatever reason, the automations aren’t being triggered on either slider change or receiver volume change:
last_triggered: null
id: denon_media_to_slider
friendly_name: Zone 1 Volume (Media to Slider)
last_triggered: null
id: denon_slider_to_media
friendly_name: Zone 1 Volume (Slider to Media)
They’re both enabled and there’s no errors in the log. Might need to enable debugging.
denon1_receiver:
name: Zone 1 Volume
initial: -80
min: -80
max: -10
step: 5
unit_of_measurement: dB
Receiver is rarely off. The denon platform volume slider works ok but neither of the automations have triggered no matter what i change (input slider or amp vol).
I can see the input number change in the dev tools, as well as the volume.
The receiver doesn’t respond to any number input from the slider unless the slider hits 0, to which the receiver is then set to 0dB (assumingly due to the conditions templates not doing the conversion to/from -dB?)
I am using this script, but be careful with volume, I use 0.03 for instance , to increase with 3
I also have sliders in my config in Lovelace, that actually read current value , and also set the value if you’re change the slider …
I have something similar with my lights at home. I have set up telegram to work with my HA and when I send the command “brighter” (it’s a bit more complicated) it makes my lights brighter. Same for darker.
I am sure you can adapt that for your use. Especialy when you combine it with input_number, set as slider!
So what I would do is the following:
(Optional)
Create an automation that triggers when your Receiver turns on. No condition. Action is to read the current volume and set the input_number accordingly. (add a delay in case your receiver takes some time to turn on)
This is optional since once you change your slider, it’s updated anyway - but it’s a nice way to be percise in control!
Make an automation, that triggers when input_number state changes. Your input_number is the desired volume. -> when you change the input value, the automation sends the new volume to your receiver. If you want you can set a condition checking if the receiver is on.
As you want -10 -5 +5 + 10 dB, you want 4 automations/scripts. Scripts are provably easier here.
The action is a simple math operation. You grab the current input_number and add/subtract the desired value to it. Since you change the state of input_number, the second automation should trigger! (If it does not, don’t worry! Just add the set_volume action in your script too. So the script updates input_number AND media_player.volume!)
The line for my setup is
You need to adapt it for your setup, but that’s what should work and be easy to use.
I’m typing from my phone, so sorry for not providing more accurate info.
Try this template_number component. Just copy the folder I linked to your custom_components folder. I think the above configuration will work, no automations needed.