i have my Denon AVR in a closed cupboard beneath the TV. Since i cannot see the AVR’s display i have set up sensors in Home Assistant to display Volume and Sound Mode in Lovelace.
now i wanted to display a notifiaction on the LG TV whenever volume changes to display the current volume level. this is what i have so far
it works just fine. whenever i press volume up or down the TV will display a notification with the new volume level.
The problem is that most of the time i want to adjust volume by more than just one increment pressing the button multiple times or even holding it.
This is where the above solution kind of falls apart: for one there is a short delay which i probably won’t get rid of due to technical limitations. However the bigger problem is that the delay will add up for every increment the volume is changed. that means if i press the button ten times for example , i will get ten notitifications and since every notification stays on screen for x seconds it takes forever to show me the current volume level after pressing the button multiple times.
now my question is if anybody has an idea to optimize this automation. my idea was to either have the notifications be displayed for a shorter time if another notification is “queued” or have it set up in a way that when HA recognizes multiple button presses that it will only show a notification for every fifth button press or something similar.
unfortunately this kind of voodoo exceeds my HomeAssistant knowledge. so i am hoping the wizards around here might be able to help.
There are multiple ways you could do this, but the easiest might be to time stamp a helper entity with the last notification time, then write logic that says that if it’s been more than X seconds (or minutes, etc) since the last notification then notify again, otherwise do not. Or even use the same logic to detect that you have pressed it multiple times and only show when there’s no additional volume change in X seconds.
To use an example from my own system, I have a button helper that I use for nothing more than a time stamp to let me know when I last changed the furnace filter, then I have a sensor that analyzes that button press (which is a timestamp) to not only display how many hours the filter has been in use but to also trigger automation when it reaches 250 active hours, I then replace the filter and click the button which sets the timestamp to now and I start again. This same methodology would work for you, to programmatically press that button when you do a notification.
thank you kindly for your reply! this sounds brilliant alas too sophisticated to my feeble coding skills … as in: i wouldn’t know where to start
it would be awesome if you could provide me with some code (example) for the helper entity and how to implement it in the original automation that i could tinker with and modify to my needs
Well, first you would create a helper button (there are other ways and other helpers you can use for your timestamp but I like the ease of use of buttons) and call it something like “Last TV Notification” which would become input_button.last_tv_notification.
Then in your automation you would add a condition template that calculates how long it’s been since the last time you got a notification and if it’s within the time you want. For example, in this case the condition returns true if the last notification was more than 5 seconds ago:
So this says that the time passed between the last notification “button click” and now was more than 5 seconds, if it’s not then the condition fails and the automation doesn’t run, if it has been more than 5 seconds then the automation continues to fire actions.
And in your actions you simply add another action (in addition to your notification action) to “click” the button using the “Call Service” on input_button.press:
got sidetracked by family last night but i can confirm the code works i just reduced the time limit! wish i could buy you a beer
there is just one detail i need to work out:
with the new automation when i press the button multiple times and the last button press was not within the timeframe then the actual current volume level i end up with is not the one displayed on screen by the automation.
thus i need to figure out how to use the automation above but additionally have a condition that the last registered button press will always be displayed. but i don’t know if this is even possible
That gets trickier, you can do it but it will require a lot more logic. Often times you have to approach any automation with the mindset of “what would I see/feel/know in the real world and then how do I translate that to computer logic?”. For example, if you generally press the volume button once per second then want a notification when 3 seconds has passed without a button press. Implementation would, under those circumstances, require a knowledge of how many repeats were made in what time period and then how long since the last one and act upon that.
If I was doing what I just described then I would have two automations. The first would be for nothing more than setting the timestamp of the button click, the second would be “if the last input_button.last_tv_notification” hasn’t changed in X seconds THEN pop the notice. So one to track the times you hit the button and one that notifies you when a certain amount of time since the LAST click has passed.
thanks again that’s super interesting but i think above my paygrade…
anyway i might have found another approach: since kodi is running 24/7 on the device i might actually use kodi’s notification feature.
this has another variable “message duration”. maybe this will prove useful for my usecase. still have to wrap my head around the nnecessary logic