HOME ASSISTANT
Build a smart-home data application
Matt Holder investigates how to take data from an API and display it in a GUI for fun and possibly profit!
Credit: www.home-assistant.io
Part three!
Don’t miss previous issues, order on page 64!
OUR EXPERT
Matt Holder is an IT professional of 15 years, Linux user for over 20 years, user of plenty of home automation gear and selfprofessed geek.
QUICK TIP
The complete code listing can be downloaded from https://github.com/mattmole/LXF308-309API-GUI.
We’re putting the finishing touches to our smart-home data application. Our aim is to pull data from the Home Assistant API and then render it on screen in a GUI. We’ve split the program into two and in the first article we wrote the library that interacts with the API. Last month, we started writing the GUI application and we covered the entity selection window. This month, we will write the rest of the app, which consists of the configuration and main windows. As part of this article, we will be calling the API communication library, which will perform the actual data requests from the API.
Before we start coding again, let’s have a look at Home Assistant. It is one of the most popular open source projects on GitHub and provides a way of linking together home automation equipment from different manufacturers, which potentially all use different protocols. Home Assistant’s aim is to keep as much data as possible within the internal network, but it can interact with many cloud services as well. Data gathered by Home Assistant is collected in what are called entities, and a history of entities is automatically kept and can be viewed from the web interface. Home Assistant provides an API that can be used to extract a list of entities within the system as well as the state of any entity. This app will enable you to select a number of entities to display and if possible a trend line will be displayed. The API is also capable of more functionality, but this is largely outside of the scope of this article.
Let’s make a start by considering the configuration window. The code samples shown are only partial so that we can cover as many concepts as possible. The screenshot (opposite page) shows the configuration window, which will enable you to extrapolate the code shown with what is on the window itself.