Payload Logo
Saturday

Home Assistant: EP2 Let there be touch (display)!

Author

Norbert TakΓ‘cs

Date Published

18.5" ips screen

Its time to upgrade my 24" wall hung home assistant dashboard on the side of my fridge. The screen used a few magnets and a LCD screen cable extender between the motherboard and the screen panel. I placed the screen driver motherboard on top of the fridge and this is where the HDMI and the power cables connected.

two screens side by side

It looks quite okay on this image, with washy tape covering the grey borders of the extracted panel. From the sideview it was gnarly!

The only thing I was missing from this setup was the touch. I even had guests coming up and touching the screen hoping something would happen.

Nothing would happen, I knew it ahead of time but I let them try.

🀌 The screen options

Finding a new screen with touch sounded easier than it was. I had few criteria, I wanted something that could be used for travelling when its not hanging in the kitchen. Has to have touch and great viewing angles. It shouldn't be too hard right? Wrong!

πŸ”² Tablets

There are two options when finding screens. Tablets and touch screens. From my research the most recommended tablet is the Amazon Fire HD10. Unfortunately this screen is not readily available in Europe. Either way I would consider it too small at 10" coming from 24".

The biggest viable tablet I found was the Lenovo p12 at 12.7", its quite small still, and its not being actively supported, even on the used market it would yield easily 400 usd/eur. No homebrew community for this screen is available. The days of flashing custom roms from XDA are behind us.

p12 vs fire hd tablet

πŸͺ§ Commercial options

On the hunt after bigger touch screens I found a few commercial options deployed in malls and restaurants. Their price was astronomical and the availability quite low.

samsung commercial options

πŸ–₯️ Portable screen with touch

After an exhausting search I stumbled upon ONE viable Aliexpress option. The best screen I could source was the following usb-c 18.5" IPS portable panel which could be also used for travelling abroad as an additional screen for work.

Cdisplay 120hz 18.5" Touch Screen Portable Monitor 1920*1080 PS5 XBOX Gaming Display Lightweight 100%sRGB Travel Second Screen

The panel has

  • mini hdmi
  • 2 usb-c ports which can be used for video/touch/power capabilities (in my case I only use these 2 cables)
  • 1920*1080 120HZ IPS screen, no burn in, hopefully!
  • 178Β° Full View Angle (can confirm its really good)
  • built in speakers, for some reason...
  • VESA mount
  • kickstand which sits quite flush behind the screen
  • screen Type: Glossy, but not too glossy
  • 250 usd/eur price
power draw of the screen

The power draw is 5.2v at 1.4A which puts it a little over 7.2 Watts

To attach the screen to the fridge I opted for a low-tech magnet ring option as opposed to my last 3D printed chunky VESA mount. There are many of these on Aliexpress but I found this one having the best reviews. I would advise to replace the tape and setup a failsafe in case the tape detaches from either the fridge or the screen. The magnets are very strong to a point that I am having issues removing the screen.

screen held up with a single magnet, and the emergency string, which have saved it once already

I have had the screen get saved once since the adhesive has detached itself from the screen. The safety rope is essential! It has been rock solid after I replaced the factory tape with 3M VHB tape

πŸš— The driving computer hardware

I will cover both options, since I originally started out with raspberry pi, and then had to move to a Mac machine.

πŸ—οΈ Old screen computer Linux

I was using pi4 and would advice using a raspberry pi 5, since my pi 4 struggles with scrolling and the UI elements of home assistant.

I am sharing the script below to control the screen on/off status and a sensor which shows if the screen is on or off!

1command_line:
2 sensor:
3 unique_id: ha_screen_hdmi_state
4 name: HA Screen HDMI State
5 command: >
6 ssh user@10.0.0.88 -i /root/.ssh/id_rsa -o StrictHostKeyChecking=accept-new "WAYLAND_DISPLAY=wayland-1 wlr-randr | grep 'Enabled:' | awk '{print \$2}'"
7 scan_interval: 30
8 value_template: "{{ 'on' if value == 'yes' else 'off' }}"

To make this script work I had to mount /root/.ssh/ as a volume and use ssh-copy-id [email protected] to create ssh access keys in my home assistant container. Since the script uses SSH to jump into the raspberry box, and runs remotely a script to check the screens state every 30 seconds. This variable could be exposed in a better way, but it worked for a quick weekend hack.

To turn the screen on/off I used the following script

1switch:
2 - platform: template
3 switches:
4 hdmi:
5 value_template: "{{ is_state('sensor.ha_screen_hdmi_state', 'on') }}"
6 turn_on:
7 service: shell_command.ha_screen
8 data:
9 state: "on"
10 turn_off:
11 service: shell_command.ha_screen
12 data:
13 state: "off"
14 friendly_name: "HA Screen Control"
15
16shell_command:
17 ha_screen: "ssh [email protected] -i /root/.ssh/id_rsa -o StrictHostKeyChecking=accept-new /home/user/hdmi-control.sh {{ state }}"

This would send a command to the following script which lived in the home directory on the raspberry pi.

1# /home/user/hdmi-control.sh
2#!/bin/bash
3
4if [ "$1" == "on" ]; then
5 WAYLAND_DISPLAY="wayland-1" wlr-randr --output HDMI-A-2 --on
6elif [ "$1" == "off" ]; then
7 WAYLAND_DISPLAY="wayland-1" wlr-randr --output HDMI-A-2 --off
8else
9 echo "Usage: $0 {on|off}"
10 exit 1
11fi

The script turns on or off the script, and sets the rotation! I am sure this should have been a website instead. In a perfect world!

🎬 Starting the browser on boot and opening Home assistant Linux

I used to use a simple start-browser.sh script which was added to crontab.

1start-browser.sh
2sleep 29
3export DISPLAY=:0 && chromium-browser --app=http://home-assistant.com --start-fullscreen >> output.txt

Started on boot using crontab

1crontab -e
2@reboot /bin/bash /home/user/start-browser.sh >> output.txt

🍎 New screen computer MacOS

I ended up switching to an old MacBook with a broken screen, and terrible butterfly key-switches. Apple got sued and lost over these, their replacement wasn't any better than the original ones. Terrible design.

The mac made the scrolling feel buttery smooth, and I wanted to try apple-s screen mirroring from other devices if I am already switching. This device has been destined for the recycling station since it has been laying around without use for a while, so why not try reusing it.

reduce reuse recycle

Originally saved from a water damage after I performed micro soldering on it. It boasts 4 usb-c ports but it couldn't directly drive the screen, at least not reliably

πŸ¦• Touch on MacOS

Who would have thought that touch is not supported on macOS by default.

Supposedly there was a touch API which got removed around Mac OS X 10.7. Questionable choice possibly including touch support in mac OS could have affected the iPad sales negatively.

There are not many options either to make a touch screen work. The only one I found to date is UPDD Touch Software which is by no chance cheap, it has a trial version and there are options of extending this trial.

This software supports full multi-touch gestures, mimicking the functionality of a multi-touch trackpad or magic mouse. It is not a perfect solution since it still shows the mouse jumping around when it simulates clicks. This is a really niche field with a single player as far I know.

πŸ“œ Home assistant control scripts for MacOS

The above mentioned scripts for monitoring if the screen is on/off and toggling the screen state had to be adjusted. Remember to mount /root/.ssh/ and using ssh-copy-id to pre-authorise your home assistant container.

1switch:
2 - platform: template
3 switches:
4 hdmi:
5 value_template: "{{ is_state('sensor.ha_screen_hdmi_state', 'on') }}"
6 turn_on:
7 service: shell_command.ha_screen
8 data:
9 state: "on"
10 turn_off:
11 service: shell_command.ha_screen
12 data:
13 state: "off"
14 friendly_name: "HA Screen Control"
15
16shell_command:
17 ha_screen: "ssh [email protected] -i /root/.ssh/id_rsa -o StrictHostKeyChecking=accept-new /Users/my-user/hdmi-control.sh {{ state }}"
18
19command_line:
20 sensor:
21 unique_id: ha_screen_hdmi_state
22 name: HA Screen HDMI State
23 command: >
24 ssh user@10.0.0.100 -i /root/.ssh/id_rsa -o StrictHostKeyChecking=accept-new "pmset -g powerstate IODisplayWrangler | grep IODisplayWrangler | awk '{print \$2}'"

The hdmi-control.sh script which lives on the host computer has been updated also

1#!/bin/bash
2
3# Function to put screen to sleep
4sleep_screen() {
5 echo "Putting screen to sleep..."
6 pmset displaysleepnow
7}
8
9# Function to wake screen
10wake_screen() {
11 echo "Waking screen..."
12 caffeinate -u -t 1
13}
14
15# Main logic
16if [[ "$1" == "off" ]]; then
17 sleep_screen
18elif [[ "$1" == "on" ]]; then
19 wake_screen
20else
21 echo "Usage: $0 {on|off}"
22 exit 1
23fi

The display shows up as a sensor and a switch in the UI. I toggle the screen off during the night.

screen state
Join the Discussion on github