Visualise smart- home sensor data
Matt Holder investigates how to take data from an API and display it in a home-built interface.
HOME ASSISTANT
Credit: www.home-assistant.io
Part One!
Don’t miss next issue, subscribe on page 16!
OUR EXPERT
Matt Holder has worked in IT support for over a decade, and always tries to utilise Linux alongside the other installed systems.
QUICK TIP
The complete code listing can be downloaded from https://github.com/mattmole/LXF308-309-API-GUI.
Over the past decade or so, the computing world has changed immensely and we’re going to capitalise on one particular area to grab data from a source and display it on the screen in a fancy Dan interface. It’s a useful ability to have because you can quickly prototype displaying important information from a range of sources when needed.
We’re going to work on an application that pulls data from the Home Assistant API and displays it in a GUI. This GUI enables the entities that are shown to be selected by the user and displayed in a table, and the values to be updated at regular intervals. As an added bonus feature, we are implementing a way to display whether the value has stayed the same, increased or decreased since the last reading.
Home Assistant is an amazing project and provides the glue that allows many different home automation tools to be used together. For example, data from a Nest thermostat could be used to switch on and off smart plugs, rather than just your boiler. This is a tiny example of what Home Assistant can do. It consists of lots of entities that store values about smart-home objects around your home. These entity values can be returned from the API. The API is capable of more, but that’s beyond the scope of this article.
Whether you are a Home Automation user or not, however, the concepts discussed in this tutorial will enable you to undertake similar projects that match your own interests.
This project is split into two areas. We’re first creating the necessary classes to read data from our API and then we’re creating the GUI functionality, which we use to draw the necessary widgets on the screen, provide the GUI interactions code and call the API code to extract the necessary data. Splitting the program in this manner is sensible as it means that the API library could easily be reused for a different project, such as making a command-line program or widget for your favourite desktop environment.