Rotate (replace) one line of display text using a timer

Hi,
What would be the best approach to rotating between multiple sensors on one line of text on a display?
example: “test 123”, sleep 10s, replace text with “test 456”…

I’m using a 128x128 display and my display → lambda does quite a bit of stuff such as changing states and colors based on if a home assistant sensor states I’m in a meeting, weather display with icons, time, wifi reception, and some other text…).
What I want to do is rotate between 2 or 3 lines of text on a timer.

I tried adding a while loop with sleep but it seems that lambda doesn’t like sleep, at least not how I used it, and I had to re-flash to get back to it.

I’m aware of pages but from my understanding I would basically have to have a copy of my lambda for each page with the one different printf, but that feels wasteful to me.

I could probably do this from home assistant with a template sensor or even with using a text_sensor from an input_text, but that also feels like a workaround to me and really relies on home assistant for every change instead of just updating it once a day and rotating.

Am I missing something obvious? is there a way to do a while loop with a sleep? is there a way for a page to only replace 1 part of the page? some other obvious way that I’m missing?

Thanks!

The simplest solution is probably to store something in a static variable in the lambda. So you can know what you displayed last time. Then you can use that information to know what to display “now”. That could be a counter or a time.
Instead of defining a static variable in the lambda a global variable is also an option.

/Mattias

1 Like

Excellent, I wasn’t aware of the global variable option.
The lambda static variable was basically what I was doing, but I couldn’t find how to sleep and update it from inside the lambda. Moving to the yaml side global will (I think) allow me to have a while with a delay. I haven’t tried that on esphome yet, but that is hopefully fairly straight forward.

Thank you!