Go back to the homepage

#2: Building a Prague public transport departure screen with openHASP and Home Assistant

I built a small Prague public transport departure and weather info screen with openHASP and Home Assistant

Missing a bus or tram by just a few seconds and having to wait for the next one is really frustrating. Especially in the winter when a missed connection means freezing out in the cold for the next bus or tram. For a while, I looked up the departure times on Google maps but that cost precious moments as I had to pull out my phone, open maps, wait for it to load, type the destination and tap to see the departure from the stop. I felt that there should be a better way. Several tram stops in Prague have a departure board that show which trams are arriving and when. So I thought that I could build one for our flat as well.

First, there was the issue of data. After some digging, I came across the awesome Golemio API which exposed some really cool data about the city of Prague, including real time data from DPP, the Prague public transport company. After playing around with several API calls, I was able to get exactly the data I wanted, which is all the upcoming departures from a specific stop.

Screenshot of postman showing the output from the Golemio API
Golemio departure boards endpoint result

Next, there was the question of hardware. Being a frontend developer, the most straightforward way for me to build an info screen is to build a small web app and use a raspberry pi or some other computer to display it on a screen. But I wanted to keep the cost low and a raspberry pi and a display was more expensive than I would like for a project like this. So I kept looking and came across the openHASP which allows building touchscreen UIs for ESP32 based microcontroller boards. openHASP also had an integration with Home Assistant where it could get data from HA and trigger HA events. Since I was already running HA to control my home automation, I figured that I could retrieve the departure board data into HA and then expose it to the openHASP device.

Out of all the devices supported by openHASP, I went with the Wireless Tag WT32-SC01 which seem to have the best specs for the money. I got the 16MB flash version from alibaba which came to $38 with shipping and arrived around 3 weeks later after some confusing shipping updates.

Picture of the Wireless Tag WT32-SC01 board
Wireless Tag WT32-SC01

With the guides on the openHASP site, it was relatively straightforward to flash openHASP to the board using the web installer, setup the HA integration and upload the example weather UI. Then the tinkering began to get the data from the Golemio API into HA. I ended up using the RESTful sensor integration to download the data from the Golemio API and store it in an entity attribute since entity states can only be primitive values. Next I used the Template integration to process the data downloaded into the REST sensor attribute and split it by station, since I was requesting departure data for multiple stations with the API call. Finally, I wrote a whole bunch of openHASP objects to read the data from the template sensor attributes and format it for display. Annoyingly, openHASP didn't support creating objects through a loop and the objects had to be defined in HA's configuration.yaml so I had to write all the objects by hand there. Finally, I adapted the existing weather example data to show the hourly forecast.

Picture of the departure screen in action
Public transport departures and weather at a glance

You can find the entire configuration and openHASP design jsonl here. What I find really cool about this setup is how the screen is updated in real time. Whenever fresh information is fetched from the API by the REST sensor, the entire chain of sensors and objects is updated with no extra code. It's entirely declarative, similar to working with a modern framework but with the whole process split between HA and openHASP.

bash.lk logo
What do you think? Click start or continue discussion to leave a comment as a reply on the forum.