I had a nice little idea for a esp device with a small oled display to show the current audio volume.
Got it working in a very simple setup, just printing a value with Lambda to the display.
Ideally I would like to only show a value on the display when the value changes.
I have not found something similar in Lambda to the “hass_state” function but then for a change of state. Does that exist?
Thought about other solutions like triggering an automation when audio volume changes, start script, get value from Sonos and write that to an entity or something. But this all seems a bit complex for what I want to do.
So my question is, is there a way to only print/render a value with Lambda when it changes and then stop after a timed interval?
Or maybe in another way with automation/script?
I asked a very similar question here and did what zoogara suggested above. It works pretty well, but what if I want to display more than two pages and cycle through them without constantly seeing the page with the volume sensor?
Create a script: that continually displays the other pages at whatever interval you like. You can create infinite loops using while:. Any delay: is non blocking so the ESP will happily do other stuff.
Start the script on boot.
Change the above example to:
a) stop the running script
b) display the volume value
c) delay for appropriate time
d) start the script again
The delay seems a little bit odd, sometimes it is actually arround 5 seconds, sometimes less then 1 second before page 2 shown all of a sudden. Still going by trail and error to see how to fix that.
Solved the delay that seemed odd. What was happening was, everytime I change the volume level a new delay timestamp is added. So if I change the level a few times quickly, wait for the first delay to finish (empty page/display), change level again and it will show the volume level briefly and then a old delay will finish and turn to the empty page.
Now, after each button press for changing the volume level the delay is reset. It will only go to the empty page 5 seconds after the last button press/volume level change.