Home Assistant Dashboard On A Raspberry Pi

Overview

I wanted to create a display of a web page on a Raspberry Pi with no desktop or browser looking controls. This is called a kiosk mode.

The main driver for this is to replace the MagicMirror to show a dashboard from Home Assistant.

From a security stand point, this is not the best solution so proceed with caution.

Pre-Requisite

It assumes you have an internet connect Raspberry Pi 4 running Raspian OS lite (command line only version). It will need to be connected physically to a monitor/display and a keyboard to enter your log in details.

Create a user in Home Assistant for this user to log in. It’s best to set the user to not be an admin user and set the dashboard to show for non admin users aswell.
MagicMirror Dashboard Overall Permissions

A working cron or equivalent scheduler.

Configure Raspbian OS

Ensure auto login is setup to allow the device to start up and boot Chromium. This can be done by:
sudo raspi-config
The select: System Options > Boot/Autologin and select Console Autologin

Install the GUI packages to allow chromium to run:
sudo apt install --no-install-recommends xserver-xorg x11-xserver-utils xinit openbox

Install chromium:
sudo apt-get install --no-install-recommends chromium-browser

Setup

Edit openbox to run chromium by editing /etc/xdg/openbox/autostart and add the following to the end of the file:

xset -dpms # turn off display power management system
xset s noblank # turn off screen blanking
xset s off # turn off screen saver

# Remove exit errors from the config files that could trigger a warning
sed -i ‘s/”exited_cleanly”:false/”exited_cleanly”:true/’ ~/.config/chromium/’Local State’
sed -i ‘s/”exited_cleanly”:false/”exited_cleanly”:true/; s/”exit_type”:”[^”]\+”/”exit_type”:”Normal”/’ ~/.config/chromium/Default/Preferences

# Run Chromium in kiosk mode
chromium-browser –noerrdialogs –disable-infobars –kiosk $KIOSK_URL
# Disable chromium update check
–check-for-update-interval=31536000

Login

Once kiosk Chromium is running, log in using a keyboard (and mouse if necessary) and ensure you set it to remember your login. Otherwise when the session times out or automatic refresh is turned on, you’ll encounter the log in page again.

Auto Refresh

Kiosk mode doesn’t automatically refresh and if it’s like Home Assistant, there is heavy caching optimising in the browser. A script is needed to refresh the browser. This is where a tool called xdotool comes in. The tool will find the window and send a keyboard command. In this case, it’s F5 to refresh.

Create a file called refresh_kiosk.sh. It can be anywhere so long as it’s executable from the logged in user.

Past the following into the file:

DISPLAY=:0 xdotool search –name home windowactivate –sync key F5 >> ~/tmp.log 2>&1

Make sure it’s executable:
chmod +x refresh_kiosk.sh

Test the script out by changing the Home Assistant dashboard. A “Reload” will appear to tell you it’s out of date and it needs to be reloaded.

Run the script:
./refresh_kiosk.sh

If chromium refreshes with the new layout then it works.

To make the refresh automatic (timed) then put the following command into cron:
*/1 * * * * /home/pi/refresh_kiosk.sh
This assumes the script created above is in the pi user’s home directory. The */1 at the start means it will refresh every minute.

Be careful! If you need to enter log in credentials, then you will have 1 minute to log in and save your details otherwise the refresh script will refresh the page. You can disable this by putting a hash (#) at the beginning of the cron entry.

Home Assistant Dashboard

Summary

It’s not ideal nor the best solution however there are movements to help set this up like admin only dashboards. It serves the job and makes maintenance a lot easier and access to a lot of data.

The look and feel is not as elegant as a tablet, however I had a spare monitor and it’s served the purpose well especially in the mornings as well as getting family members interested in the weather.

Raspberry Pi Touchscreen Kiosk Setup (10 Steps)

Auto-refresh for Midori

About Danny

I.T software professional always studying and applying the knowledge gained and one way of doing this is to blog. Danny also has participates in a part time project called Energy@Home [http://code.google.com/p/energyathome/] for monitoring energy usage on a premise. Dedicated to I.T since studying pure Information Technology since the age of 16, Danny Tsang working in the field that he has aimed for since leaving school. View all posts by Danny → This entry was posted in Home Automation, IOT and tagged , , , , . Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.