Raspberry Pi-based Home Assistant Control Panel

This is my take on a Home Assistant control panel platform. It's based on this guide to creating a Raspberry Pi minimal browser kiosk but with wake-on-motion and some tweaks to improve the experience. Background info, why I chose this over the other options, and plans for future expansion are at the bottom, for anyone interested. My plan is to install one in each room with room-specific widgets.

Hardware

Assemble the parts according to the included instructions but keep the microSD out for now for imaging.

Raspbian lite setup

  • Image Raspbian Lite to the SD using the imaging tool or other method.
  • Create an empty file on the SD boot directory named ssh to enable SSH on boot.
  • Create a file in the SD boot directory named wpa_supplicant.conf with the following content, replacing the variables with your details of course.
    Note: Country code is required. This file must use Unix LF line endings, not CRLF endings.
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<Insert 2 letter ISO 3166-1 country code here>

network={
 ssid="<Name of your wireless LAN>"
 psk="<Password for your wireless LAN>"
}
  • Insert the microSD and boot the RPi. WiFi should have connected automatically.
  • Connect via SSH using the default username pi and password raspberry
  • Run sudo raspi-config to set the following
    • Change default password
    • Select “Desktop / CLI” and then “Console Autologin”
  • Update Raspbian by running the following. 

    sudo apt-get update; sudo apt-get -y upgrade; sudo reboot

    Minimal Chromium install

    Reconnect via SSH then run the following to install Chromium with the minimal required packages. 
    sudo apt-get install --no-install-recommends xserver-xorg x11-xserver-utils xinit openbox chromium-browser vim

    Motion install

    We'll use the motion app to wake the screen on camera motion. Motion also supports streaming the Pi camera to Home Assistant or motionEye, should you wish to do that.

    Mmalcam is the preferred camera API over the alternative bcm2835-v4l2 kernel module as mmalcam supports hardware parameters which we'll use later. Unfortunately, as of this writing, the motion package in the RPi repo isn't compiled with mmalcam support so you'll need to download the deb file from the Motion releases page. Make to download the one starting with "pi_".
    wget https://github.com/Motion-Project/motion/releases/download/release-4.3.2/pi_buster_motion_4.3.2-1_armhf.deb
    dpkg -i pi_buster_motion_4.3.2-1_armhf.deb
    Change/add the following lines in /etc/motion/motion.conf. The other existing lines can be left as default.
    # Find and change these lines
    log_level 1
    ; videodevice /dev/video0 # comment this line out
    mmalcam_name vc.ril.camera
    mmalcam_control_params -rot 90
    # Low res and framerate reduces motion CPU usage
    width 320
    height 240
    framerate 5
    
    # Add these lines
    on_motion_detected DISPLAY=:0 xset dpms force on
    lightswitch_percent 90
    Since the SmartiPi enclosure has a rotated camera mount, we need to rotate the image if we want to use it for anything besides motion detection in the future. Using mmalcam for this (as in the config above) is more efficient than software rendering. Reducing the resolution and framerate also helps to reduce CPU usage and power consumption. With these settings, motion consumed about 3% CPU down from over 20%.

    We can optionally remove the unused kernel UVC module. 
    sudo modprobe -r bcm2835-v4l2

    Startup scripts

    Edit ~/.bash_profile and add the following which will start X on the first console if it isn't already running.
    [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && startx -- -nocursor
    
    Create /etc/xdg/openbox/autostart with the following contents, changing the URL to your HA dashboard URL.
    ## Allow quitting the X server with CTRL-ATL-Backspace
    setxkbmap -option terminate:ctrl_alt_bksp
    
    ## Set screen sleep to 300s (5min)
    xset s 300
    
    ## Add user "motion" to xhost in order to wake screen
    xhost +si:localuser:motion
    
    ## Start Chromium with flags
    chromium-browser https://your home assistant dashboard \
      --window-size=800,480 \
      --window-position=0,0 \
      --start-fullscreen \
      --kiosk \
      --disable-translate \
      --no-first-run \
      --fast \
      --fast-start \
      --disable-features=TranslateUI \
      --disk-cache-dir=/dev/null \
      --overscroll-history-navigation=0 \
      --disable-pinch \
      --noerrdialogs \
      --disable-infobars \
      --pull-to-refresh=1 \
    Your RPi should now boot directly to HA. Login to HA using non-admin credentials and be sure to click "remember login" when prompted.

    Lastly, I found the screen to be too bright so I reduced it to 75 (of 255). This setting is persistent across reboots.
    sudo sh -c 'echo "75" > /sys/class/backlight/rpi_backlight/brightness'  

    Power load

    I connected a USB power meter to check the load. The panel draws 0.33A and 0.43A with the screen off and on respectively, though I find it surprising that the LCD only draws 100mA. In any case, it appears to be a power-efficient solution. 





    Background and alternatives considered

    I have been using the Wallpanel Android app on an old Android tablet but prefer a battery-less solution to avoid the risk of spicy pillows. Most consumer tablets fail to boot with the battery removed but cable-powered alternatives are limited. LineageOS on RPi3 was laggy on the official RPi touchscreen due to the software swiftshader driver. An RPi4 or HDMI touchscreen should have fixed that but I couldn't find a clean enclosure for an HDMI touchscreen + Pi and wanted to keep the price low. I also considered one of the many AOSP cable-powered wall tablets on Alibaba but didn't have the confidence in the compatibility, security, and updates to take that risk.

    The objective for this panel was to try to replicate the Wallpanel app but at a minimum should boot directly to the UI and support auto sleep & wake. This RPi solution meets those requirements but lacks additional features Wallpanel provides, like MQTT reporting and remote controls. 

    Future expansion

    The next step is to try to add some features from Wallpanel through the use of an MQTT client. Ideally the client should be able to:

    • Report motion detected
    • Report RPi hardware health
    • Refresh the browser window remotely
    • Reboot the RPi remotely
    I haven't found any existing tool which does all this so I may need to try to write my own using paho-mqtt.

    Even with that, the RPi would still be underutilized. A broad range of devices/sensors could easily be added using RPiEasy, though I'd need to rethink the enclosure. Room Assistant could also be added to enable BT/BLE presence detection, though I had limited success with an older version.

    Lastly, since the plan is to install one panel in each room, it would be great for them to also work as video intercoms either to specific panels, broadcast, or to mobile devices. This jitsi-meet system looks promising. There's even a Docker container that should be able to run on the HA server.

    Comments

    Post a Comment

    Popular posts from this blog

    Flash Wio Node to ESPHome or Tasmota

    Railway Museum (鉄道博物館, Tetsudō Hakubutsukan)