Upload gas readings to mindergas.nl

rest_command:
  mindergas_post:
    url: https://www.mindergas.nl/api/meter_readings
    method: POST
    headers:
      AUTH-TOKEN: !secret mindergas_token
      Content-Type: "application/json"
    payload: '{ "date": "{{ date }}", "reading": {{ meterreading }} }'
    verify_ssl: true

automation:
  - alias: "update mindergas"
    trigger:
      - platform: time
        at: "00:15:03"   #Choose some random time near '00:00'
    action:
      - service: rest_command.mindergas_post
        data_template:
          date: "{{ (now().timestamp() - 60*60) | timestamp_custom('%Y-%m-%d') }}"  
          ## use 1h before now, to make sure we use yesterdays date
          meterreading: "{{ states('sensor.gas_consumption') }}"

Next to having my historical gas usage data in homeassistant, I also like to have it in mindergas.nl. This automates that process with data from homeassistant.

maybe someone else can use this

13 Likes

Nice! Thanks :ok_hand:

For degree days, just use:

4 Likes

maybe this also will help, have not tested yet

This will never become true: A number can not be equal or higher than 11 and at the same time lower or equal than 2

I think the or condition will work better:

  - sensor:
      - name: degree_day_factor
        state: >
          {% if now().month >=4 and now().month <= 9 %}
          0.8
          {% elif now().month >=11 or now().month <= 2 %}
          1.8
          {% else %}
          1
          {% endif %}

Iā€™m also not sure about the factors used in the template, this might be different for each country.

In The Netherlands the following is more or less accepted as a standard:
April - September: 0.8
March and October: 1.0
November - February: 1.1

Hi Mey,

As I am very new to Home Assistant, can you please explain (in Dummy language) where I have to put this script? I have my gas meter running in HA and created an account at MinderGas.nl, but I have no idea how to continue right now

Thank you for your help

Rick

That depends on how your configuration structure is set up.

Most likely, if you have a default setup youā€™ll have:

configuration.yaml

Here you add the part:

rest_command:

up until (but without) automation:

then the part below
automation:

starting with:

  • alias:

youā€™ll add to your automations.yaml file.

then finally:

in your secrets.yaml file

add:
mindergas_token: ā€œmindergastokenā€

Ik begrijp de regel ā€œNever mind this ā†’ this really dont make much senseā€ niet.
Is de bovenstaande configuratie nu wƩl of niet geschikt om mijn gasstand naar Mindergas te uploaden?

First post is fine :slight_smile:

be sure to adjust the exact time you post

Thank you as of 23-10-2022 this post still works.
I have the latest HA version 2022.10.5

Finally got this working (27-01-2023). In my case the sensor has a different name: sensor.gas_meter_gas_consumption

My automations file:

  - alias: "update mindergas"
    trigger:
      - platform: time
        at: "00:03:33"   #Choose some random time near '00:00'
    action:
      - service: rest_command.mindergas_post
        data_template:
          date: "{{ (now().timestamp() - 60*60) | timestamp_custom('%Y-%m-%d') }}"  
          ## use 1h before now, to make sure we use yesterdays date
          meterreading: "{{ states('sensor.gas_meter_gas_consumption') }}"

part in configurations:

#uploads to mindergas
rest_command:
  mindergas_post:
    url: "https://www.mindergas.nl/api/meter_readings"
    method: post
    headers:
      AUTH-TOKEN: !secret mindergas_token
      Content-Type: "application/json"
    payload: '{ "date": "{{ date }}", "reading": {{ meterreading }} }'
    verify_ssl: true

I canā€™t get this get to work. Even if I copy the code provided by @dsoveen I get:

update mindergas uses an unknown service

The automation ā€œupdate mindergasā€ (automation.mindergas) has an action that calls an unknown service: rest_command.mindergas_post.

Is there something changed in HA lately? Iā€™m running:

Home Assistant 2023.3.5
Supervisor 2023.03.2
Operating System 9.5
Frontend 20230309.1 - latest

Iā€™m a newby migrating from Domoticz. So bear with me.

Iā€™m running HA in a docker container on a RPi 4B. Running fine. However when I want to upload my mindergas meter reading successfully I have to turn off ā€˜verify_sslā€™. Otherwise I receive a ā€˜401ā€™ error which tells me ā€˜authentication failedā€™.
Is this correct behaviour (ie do I have to switch off verify_ssl)? Or am I missing a setting in my yaml configuration?

Thanks for the help.

Ik heb nooit problemen gehad met automatisch uploaden van mijn meterstand. Er zijn 2 wijzigingen in mijn systeem aangebracht nl. een nieuw modem van ziggo en de P1 kabel is vervangen door een home wizzard wifi P1. Als ik nu de Link gebruik voor upload krijg ik een foutmelding.

https://www.mindergas.nl/api/meter_readings

Als ik het rest command aanroep krijg ik dit in mijn logboek

Logger: homeassistant.components.rest_command Source: components/rest_command/__init__.py:144 Integration: RESTful Command (documentation, issues)
First occurred: 27 september 2023 om 22:10:06 (6 occurrences)
Last logged: 09:38:54

Timeout call https://www.mindergas.nl/api/meter_readings

Is er een andere manier om de meterstand te uploaden?

Heb je het uiteindelijk werkend gekregen?
Ik heb het zojuist geconfigureerd en bij mij werkt het.
Ik moest wel Home Assistant opnieuw opstarten voordat het werkte.

Good topic,

It took me some time because I got an 401 authentication error.
Finaly I found out the config.yml part had some strange characters in it. So I copied that part again into the configuration.yml restarted HA and yes it worked right away.
Further be awre of the gas sensor name it depends on the way you read the gas metric from your smart meter. I for instance use the Youless LS120 in combination with the youless integration so I have to use sensor.gas_usage as the sensor name.

When I manually start the automation from the automation dashboard the information is uploaded to mindergas.
Yesterday I checked my mindergas site and encounterd the last few days nothing has been uploaded. In the logs I see below message:

home-assistant.log:2023-12-04 00:03:03.971 WARNING (MainThread) [homeassistant.components.rest_command] Error. Url: https://www.mindergas.nl/api/meter_readings. Status code 400. Payload: bā€™{ ā€œdateā€: ā€œ2023-12-03ā€, ā€œreadingā€: unknown }ā€™

What can be the problem?