Thibault Maekelbergh

🔋 Consumption monitoring with EnergieID & Home Assistant

Last year my colleague (and friend) Elias made me discover EnergieID, an intuitive and promising Belgian platform to gain insight into your consumption usage. Their web application is pretty straight forward and easy to work with when you want to track water consumption, electricity and heating, and even offers automatic integrations with digital meters.

Consuming the EnergieID API


But I was more interested in how I could integrate EnergieID into my Home Assistant setup because HA is the brain of everything happening in my house and filling in the usage values from the meter in the EnergieID webapp seemed tedious and smelled like it could be automated.

I was set on writing a native Home Assistant integration and submitting a PR to the main repository, but at that time it seemed like talking to their REST API easily via their Python wrapper could only be done with an oauth flow. That oauth flow required emailing someone at the EnergieID team and getting credentials required to complete that oauth flow. I sent a mail, received a response, but not the one I was hoping for: I could not get oauth credentials at that time.

Lucikly, there are a bunch of integrations available on the EnergieID webapp, one of them being webhooks. Unfortunately I could not do as much with webhooks, but at least I could update the values for my meters by triggering the webhook.

Updating consumption via webhooks


Ok, so webhooks it is! Getting these in HA is fairly straight forward. We need to set up some REST commands in HA and then use frontend helpers to update our usage.

First off, create automatic meters via the webhook integration in EnergieID. This will give you a unique URL where you can send a JSON payload to per meter, which will then update the relevant meter.

3 meters (electricity, heating & water) created via EnergieID's webhook integration.

With all required data for HA we can now create 3 rest_command integrations which can then be called from HA:

yaml
energie_id_set_heating_usage:
url: !secret energie_id_usage_webhook
method: 'post'
content_type: 'application/json'
payload: '{"remoteId": "ha-webhook-heating", "remoteName": "Aardgas (Home Assistant)", "metric": "naturalGasImport", "unit": "m³", "readingType": "counter", "data": [["{{ now().isoformat() }}", {{ usage }}]]}'
energie_id_set_electricity_usage:
url: !secret energie_id_usage_webhook
method: 'post'
content_type: 'application/json'
payload: '{"remoteId": "ha-webhook-electricity", "remoteName": "Elektriciteit (Home Assistant)", "metric": "electricityImport", "unit": "kWh", "readingType": "counter", "data": [["{{ now().isoformat() }}", {{ usage }}]]}'
energie_id_set_water_usage:
url: !secret energie_id_usage_webhook
method: 'post'
content_type: 'application/json'
payload: '{"remoteId": "ha-webhook-water", "remoteName": "Water (Home Assistant)", "metric": "drinkingWaterImport", "unit": "m³", "readingType": "counter", "data": [["{{ now().isoformat() }}", {{ usage }}]]}'

After a reload these become availble in your Developer tools:

3 Home Assistant RESTful Command services which we can call to update our meters

At this point, you could already start writing scripts and automations to update the meter values in EnergieID, but lets go for something more user friendly.

Creating UI helpers to update our meters


Home Assistants relatively new helpers offer a great way to perform more difficult interactions in the frontend and help triggering scripts and automations. Create 1 new Input helper per meter in HA and make sure to set the correct values for step, min, max and unit.

Creating an input helper for the electricity meter with a unit of kWh

Then with those helpers available, from the frontend (or via YAML if you prefer that) you can create a script to update all meters with the current values from the input helpers

A new "Run" script with a sequence to update all meters by sending the state from the inputs to the restful commands / webhook we created earlier

All that we have left to do now is add it to a card in our Lovelace view so that we can very easily update our meters individual values and then send it to EnergieID.

A Lovelace (UI) card with our inputs and the button so submit them to EnergieID

Et voila, a somewhat more convoluted approach to integrating EnergieID and Home Assistant, but for now this will do. There is however good news that landed this month:

The new EnergieID API


EnergieID recently gave its webapp a complete visual overhaul and now allows to interact with the REST API by skipping the tedious oauth flow and just use a user-generated access token. This opens the prospect of me trying to get EnergieID in HA core up again!

In the coming months I will try to find some hours in my spare time to work on this integration which I have roughly outlined with the following goals:

  • Creates new sensor entities per meter and pulls their state from the meters in EnergieID

  • Create a HA service which allows to update a meter by just passing a valid entity_id and a value to update the meter with

  • See what I can do with data anlytics (Grafana / HA recorder etc.)

As always, let me know what you think on Twitter!