Category: Smarthome

  • Monitoring imbalance prices with Home Assistant

    With the rise of home batteries trading on the imbalance market and solar panel features like Zonneplan’s PowerPlay, there’s growing interest in understanding how imbalance prices fluctuate throughout the day. Fortunately, websites like Tenergy and Tennet offer real-time insights into balance prices. For those looking to integrate this data into their smart homes, you can load these prices into Home Assistant and create graphs to visualize the historical and current imbalance prices.

    Setting up monitoring

    To start, fetch the real-time prices from Tennet. Use the script below, which runs a GET request every 60 seconds to load the latest prices from Tennet.

    - platform: rest
      name: Tennet Delta Prices
      resource: https://www.tennet.org/xml/balancedeltaprices/balans-delta.xml
      method: GET
      headers:
        User-Agent: Home Assistant
      value_template: >
        {% set ns = namespace(record='') %}
        {% for record in value_json.BALANCE_DELTA.RECORD %}
          {% if loop.first %}
            {% set ns.record = record %}
          {% endif %}
        {% endfor %}
        {{ ns.record | tojson }}
      scan_interval: 60
    

    Once you have the prices loaded, extract the relevant information. The prices can be positive or negative, depending on the grid balance. Below is an example script for extracting this data and storing it in a sensor.

    - platform: template
      sensors:
        tennet_balance_price:
          unit_of_measurement: "EUR"
          friendly_name: "Tennet Balance Price"
          value_template: >
            {% set record = states('sensor.tennet_delta_prices') | from_json %}
            {% if record.MIN_PRICE is defined %}
              {{ record.MIN_PRICE }}
            {% elif record.MAX_PRICE is defined %}
              {{ record.MAX_PRICE }}
            {% else %}
              N/A
            {% endif %}

    Restart your Home Assistant after setting up these sensors. You should now have a sensor called sensor.tennet_balance_price that can be used in a graph component (see below for visualization). Your output should look like this:

    Sometimes, the grid will have a major surplus or shortage of energy, indicated as “Emergency Power”. This usually results in a significant spike in imbalance prices. To monitor this, create an additional sensor:

    - platform: template
      sensors:
        tennet_emergency_power:
          friendly_name: "Tennet Emergency Power"
          value_template: >
            {% set record = states('sensor.tennet_delta_prices') | from_json %}
            {{ record.EMERGENCY_POWER if record.EMERGENCY_POWER is defined else 'N/A' }}

    Now, you’ll have an additional sensor called sensor.tennet_emergency_power that can be used in an automation to notify you when emergency power is activated.

    Visualizing imbalance prices

    Of course, you’ll want to use the data you’ve imported to visualize the prices and observe how they develop throughout the day. For graphs, I’m using the Apex Charts Card, a flexible library with many charting options. If you haven’t installed ApexCharts yet, follow the installation instructions first, or leverage the built-in history graph. Here’s an example of how you can visualize the imbalance prices using Apex Charts:

    type: custom:apexcharts-card
    apex_config:
      chart:
        height: 250px
    graph_span: 12h
    header:
      show: true
      title: Balance prices
      colorize_states: true
      show_states: true
    all_series_config:
      stroke_width: 2
    series:
      - entity: sensor.tennet_balance_price
  • Uploading your gas meter to MinderGas.nl with Home Assistant

    MinderGas.nl is a popular tool to get more insight into your gas usage. If you haven’t used MinderGas.nl yet, this tool allows you to get more insight into how much gas you’re using and lets you compare against peers and your historical gas usage. This is ideal if you’re trying to save gas and making adjustments in your house.

    When I started with this tool, I manually entered the values, but why would you do something by hand if you can automate it too. Since I’m using Home Assistant for my home automation (more on this soon!), it should be easy to automate this task using Home Assistant.

    I already have my gas meter available as a sensor in Home Assistant (sensor.gas_meter) thanks to my Toon thermostat that I integrated with Home Assistant. MinderGas.nl has an API that allows us to upload our gas meter values easily. 

    This guide has 3 simple steps we need to follow:

    1. Create an API token and store it safely in Home Assistant
    2. Add a rest command to your configuration that calls the MinderGas.nl API
    3. Add the daily automation that uploads the gas meter values

    Create an API token and store it safely in Home Assistant

    First of all, we need to create an API token to use the MinderGas.nl API. If you already have an account, you can go to https://www.mindergas.nl/member/api and generate an API token. Now, store this API token safely in your secrets.yaml file in Home Assistant. This file should contain:

    mindergas_api_token: <token>

    Add a rest command to your configuration that calls the mindergas.nl API

    This step creates the command that will call the API of MinderGas.nl. The command does not contain any information about the date or gas meter values yet. Those will be added later in the daily automation. 

    Add the code below to your configuration.yaml file:

    rest_command:
      mindergas_upload:
        url: 'https://www.mindergas.nl/api/gas_meter_readings'
        method: POST
        headers:
          content-type: application/json
          AUTH-TOKEN: !secret mindergas_api_token
        payload: '{ "date": "{{date}}", "reading": "{{reading}}" }'

    Add the daily automation that uploads the gas meter values

    To get the most detailed view of our gas usage, we want to upload our gas meter values every day. MinderGas.nl indicates that they see the values as the end values of that day, so we’ll want to upload the values as late as possible in the day. I’ve chosen to use 23:58 local time, giving the script a little buffer before the next day kicks in.

    To avoid making mistakes, I recommend creating this automation using the YAML editor or add it directly to the automations.yaml file:

    - alias: MinderGas Upload
      trigger:
      - platform: time
        at: '23:58'
      action:
        data_template:
          date: '{{ (as_timestamp(now())) | timestamp_custom("%Y-%m-%d", True)}}'
          reading: '{{ states(''sensor.gas_meter'') }}'
        service: rest_command.mindergas_upload
      mode: single

    Once enabled, the script will run each day at 23:58 and upload your gas meter values to MinderGas.nl. I want to thank jvdmast for his example script, as this gave me great guidance on how to get this working.