Graphs using Home Assistant and Node-RED

EasyMQTT graphs are very customisable and easy to set up. It’s possible to create graphs using any sensor data available over MQTT. With a little bit of work, it’s even possible to get data from any Home Assistant entity into EasyMQTT. Here’s an example of a widget I’ve had on my Home Screen for some time:

Widget containing graphs for electricity prices across Europe

Electricity price data directly from Nordpool, a European power exchange

With the current energy crisis, electricity prices have been gaining a lot of attention. Many electricity providers are offering a spot/variable price model where electricity is sold at market price, allowing customers to take advantage of cheaper prices and avoid using electricity when prices are high.

With EasyMQTT it’s possible to get a graph of these prices directly on your Home Screen, showing you both the current price and some history of how prices changed over time.

The following is needed to achieve this:

  1. Set up Nordpool in Home Assistant

  2. Set up automation to publish data to MQTT in Node-RED

Home Assistant

Home Assistant is an open source home automation solution, meant to be the central hub for all sorts of of smart home devices. It’s a perfect data source for EasyMQTT and makes it possible to expose all sorts of sensors and entities to use in EasyMQTT graphs.
The integration we’re interested in is Nordpool. You can find it under Settings > Devices & Services then Add Integration and search for Nordpool.

The Nordpool integration has a bunch of different options to configure, like currency, whether to include VAT, decimal places and unit.

The most common way of displaying electricity prices is probably EUR(cents)/kWH.

Once you’ve configured the integration, you’ll end up with a sensor named something like sensor.nordpool_kwh_fi (adjusted for your region, unit of measurement, currency etc).

Now we’re ready to send those sensor values to MQTT. That can be done in multiple ways, one way is using Home Assistant automations to send a message to MQTT whenever the sensor changes.

👇 What I find easier is using node-RED 👇

Node-RED

Node-RED is a visual tool to model workflows. It’s been becoming increasingly popular in home automation, due to being easy to learn, quick to get into with many plugins to extend functionality.

Node-RED can be installed externally or using the Home Assistant OS add-on.

Get started by opening a flow and dragging a MQTT out node onto it. Double click to open it and select the edit button (pencil icon) to set up your MQTT Broker. Enter all your credentials and click add to save.

To publish sensor values to MQTT only two nodes are needed. The first one is a trigger: state node which triggers whenever the state changes. Drag one into the flow, double click and set your nordpool sensor as the entity id. The second node is the MQTT out node we set up earlier. Double click, set your MQTT Broker as the Server and set a topic, for example nordpool/fi.

Then connect the two nodes like this:

Repeat the above steps for any other sensors you have and then we’re ready to head into EasyMQTT.

EasyMQTT

The last step is adding a new widgets and graphs to EasyMQTT. Start by opening the app, selecting the Settings tab, then Widgets.

Adding a widget

Tap the + button to add a new widget and give it a title. Set the resolution, unit and number of datapoints. By default they’re set to 24 hours, meaning the graph will show 24 datapoints over 24 hours.
You can choose to enable the widget for live updates, doing so will tell EasyMQTT to subscribe to the topics in the background and update the widget live while the app is running.

The last thing to set is the graph engine, EasyMQTT graphs are simple graphs drawing out the datapoints. Swift charts graphs are more detailed, drawing datapoints based on the time they were recorded, displaying more accurate x and y axis labels. Swift charts graphs are only available on iOS 16, since they use the new Swift Charts library.

Adding the graphs

Now that we have the widget set up, it’s time to add the graphs. Click Select graphs, tap the + button to add a new graph.

Start by setting a title, the topic, property path and the broker. The way we set up the sensor, Home Assistant publishes the electricity price directly as a number to the nordpool/fi topic, meaning the property path can be set to payload. Check the FAQ for more info on property paths

Graphs have a couple of different customisation options:

  • Ignore duplicates: Ignores values that are identical to the previous one. This setting is useful for sensors/topics that don’t update frequently

  • Number of values: The number of datapoints that are kept

  • Decimal places: Decimal places of the values

  • Interval in hours: set a limit on how often a graph should update. Setting this to 1 will update it at most every hour, 2 every two hours. Setting it to 0 will update it without any limitations

Now the graph is all set! Feel free to repeat the steps above to add as many graphs as you’d like.

The end result will look something like this:

This widget will now be available both in the app but also on the Home Screen and Lock Screen (iOS 16). Add it by long pressing on the Home Screen, search for EasyMQTT, select the multi graph widgets. Then long press on the widget, Edit widget and select the name of the widget you just created in the app.

Widget in action

And that’s it! Now you have a brand new widget on your Home Screen that will update itself. The same principle of adding widgets can be applied to any other sensor from Home Assistant, or even any other MQTT topic.

Previous
Previous

EasyMQTT 1.13.0 - Standby and other cool stuff

Next
Next

Hello iOS 16! EasyMQTT 1.10.1