As mentioned in my What did you build/automated today (with pictures)? post recently, I’ve been able to adapt the Home Automation Switch Plate (HASP) project to work with openHAB. I’m posting a write-up here, in case anyone else is interested in using it.
What is it?
The HASP is a touch screen controller designed by aderusha (project page on Github), which fits into a spare “gang” in US-style electrical outlets (no design for the rest of the world yet, sorry). It uses a Nextion HMI (2.4") touchscreen, with a user interface designed by aderusha (9 total screens of different layouts with pushbuttons, sliders and a chart), and a Wemos D1 to drive the screen and interface with the control system (via MQTT). The finished product looks like this:
How does it work?
The Wemos D1 Arduino code and the Nextion HMI code are very nicely designed, made to be modular and generic, exposing all configuration to the home automation system incorporating the HASP. Every button text, background/foreground color, and font size are configurable via MQTT topics. Every button press is captured and sent to the home automation system via MQTT, as well.
Once flashed with code, the HASP allows easy configuration via Wifi (it creates an access point for connection and initial configuration). The initial load of the HMI code is via an SD card with the Github .tft file provided. After that, the HASP can be accessed via a webpage, to change its MQTT settings, Wifi settings, or even update the Wemos (ESP) and LCD (TFT) firmware via HTTP! This is a very cool feature to keep the display up to date!
How to build one?
The GitHub repo has excellent build documentation available, but I also created a short series of build and setup videos. Part 1 (Hardware build and software configuration):
Part 2 (Install and openHAB configuration):
How to use it with openHAB?
The initial project was designed specifically for Home Assistant, with the yaml configuration files included in the GitHub. But after looking at it for a while, I was able to mimic the automation rules for openHAB and I created a set of configuration files for OH. I’ve submitted a PR to aderusha and it’s been approved/merged to the HASP repository, under the /contrib/openHAB folder.
I won’t post the .items or .rules files here due to their length, but the files are available at the Github repo, and I’ve included a sample .sitemap file stub to be able to control/monitor status of the HASP via the Basic UI.
I’ve included a lot of comments in the items and rules files, a readme file on the GitHub repo, and sectioned off the rules file to make it clearer where the end user is able to modify their HASP, but the gist of configuration is as follows:
- Before you start, make sure you have the JSONPath transformation installed, the Rules & Items make use of it to decode the data received from the HASP.
- Decide which screens of the HMI you want to use. For example, my initial configuration will use screens 1, 2 and 4:
a. Screen 1 has 4 buttons, which I’ll use to fire off a specific Scene in my openHAB setup
b. Screen 2 also has 4 buttons, which I’ll use to show a clock, date, indoor and outdoor temperatures
c. Screen 4 has 3 buttons and 3 sliders, which I’ll use to control my HVAC system and possibly another light depending on which room the HASP is installed.
- Depending on the configuration selected above, adjust the variables in the rules file to match the configuration:
a. In the first part of the .rules file, make the bottom buttons point to the correct screen # and label them.
b. Adjust the variables corresponding to the button text and font size on the screens with buttons and sliders.
- Fill in the HASP -> openHAB and openHAB -> HASP rule sections with the appropriate handler rules for your configuration.
a. The HASP -> openHAB rules section has stub rules written for every button/slider on every screen. You’ll only need to fill in your code into the appropriate if statement to handle the button press/slider move (I’ve put in commented out example code for some of the cases).
b. The openHAB -> HASP rules section has some sample rules I’ve written to move the sliders to an appropriate position based on openHAB item state (e.g. to match the brightness slider of a light if it’s changed from some other interface than the HASP) and to put values on the chart of page 9 (e.g. to monitor the signal strength of the HASP Wifi signal, or to show a chart of the room temperature over time).
- Enjoy using the HASP!
Conclusion / Notes
My rules and items files should make it easier to incorporate the HASP into our openHAB setups, but there’s still work to be done by the end user to make the buttons and sliders actually “do things”. I’ve also not included some of the finer configuration items (background colors), since I was mostly concerned with getting the main functionality to work. I may add those items/rules in the future, if needed.
Let me know if you have any questions or issues with using this