Making a HA cycling Kiosk with a pi

There are plenty of guides for doing a basic chromium kiosk, so I want to focus on the one weird trick aspect I learned that made it work better for me using HA lovelace panels. Pi My Life up has an excellent link on the basic setup: https://pimylifeup.com/raspberry-pi-kiosk/.

The problem I had with HA is that it is JS intense and some elements like the Map would take 20-30s to display – not good when you want to rotate tabs every 20s. I tried refreshing before I rotate, but that led to a memory leak on the pi and made the resource problem worse on a Pi 3. I’m sure a Pi4 would do better, but with the solution I found a Pi 3 is more than enough to do the job.

#!/usr/bin/env bash

xset s noblank                                                                                                    
xset s off                                                                                                        
xset -dpms

unclutter -idle 0.5 -root &                                                                                       
                                                                                                                  
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' /home/pi/.config/chromium/Default/Preferences            
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' /home/pi/.config/chromium/Default/Preferences              
                                                                                                                  
/usr/bin/chromium-browser \
--disable-background-timer-throttling \
--disable-renderer-backgrounding \
--disable-backgrounding-occluded-windows \
--disable-ipc-flooding-protection \
--enable-accelerated-2d-canvas \
--enable-hardware-overlays \
--enable-gpu-rasterization \
--enable-direct-composition-layers \
--noerrdialogs \
--disable-infobars \
--kiosk \
https://foo.com/ten-foot/0 \
https://foo.com/ten-foot/1 \
https://foo.com/ten-foot/2 \
https://foo.com/ten-foot/3 \
https://foo.com/ten-foot/4 \
https://foo.com/ten-foot/5 &

# extra buffer time to finish loading before starting the tab loop
sleep 40

while true; do                                     
  sleep 20                                                     
  xdotool keydown ctrl+Tab; xdotool keyup ctrl+Tab;                                                                                                  
done

Did you spot the trick? It’s not the acceleration, though that helps if you turn on fake kms and include those lines. No, it’s the disable flags. Lovelace isn’t all that demanding with a constant connection so resource consumption is far lower when the background tabs just keep their websockets open and active. Chromium knows that a pi has few resources and so zealously suspends processes when they leave active focus – that’s bad in the kiosk case.

Without the background flags active I have it working much of the time, but eventually locking up within the space of a day on a pi3. With them active I have yet to see it lock up. And that’s with a map, animated weather, 4 camera feeds, and some other sensor pages.

Feel free to improve on this setup as I still have the pi reboot each day just in case, and I have VNC active to log in the handful of times per year the “remember me” token times out.

You’ll have to restart the service if you change the layout of course, but a chron reboot will take care of that too.