Hourly electricity prices Netherlands

More and more energy providers have hourly tariffs in the Netherlands. An example is the ANWB: Energie

When I look at the devtools (F12) is see that the prices are retrieved form this json:

https://api.energyzero.nl/v1/energyprices?fromDate=2022-11-06T23%3A00%3A00.000Z&tillDate=2022-11-07T22%3A59%3A59.999Z&interval=4&usageType=1&inclBtw=true

Did someone integrated these Dutch dynamic prices into Home Assistant?
If so, you could share your script and the method how to do this?

4 Likes

That would probably be rest integration or sensor, see below. What.how to do this depends a bit on what you would like to do after the collection of data.

RESTful - Home Assistant (home-assistant.io)

sensor:
  - platform: rest
    unique_id: energyzero_prices_rest
    name: Energyzero prijzen 
    resource: https://api.energyzero.nl/v1/energyprices
    scan_interval: 900
    value_template: OK
    params:
      fromDate: >
        {{(now().strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      tillDate: >
        {{((now()+ timedelta(days=2)).strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      interval: 4
      usageType: 3 (or 1)
      inclBtw: true
    json_attributes:
      - Prices

This is awesome, Iā€™ve been looking for this info for a while. Iā€™m probably doing something wrong because Iā€™m getting this response

Prices:
  - price: 1.16
    readingDate: '2022-11-20T00:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T01:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T02:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T03:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T04:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T05:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T06:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T07:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T08:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T09:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T10:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T11:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T12:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T13:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T14:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T15:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T16:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T17:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T18:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T19:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T20:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T21:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T22:00:00Z'
  - price: 1.16
    readingDate: '2022-11-20T23:00:00Z'
  - price: 1.16
    readingDate: '2022-11-21T00:00:00Z'
  - price: 1.16
    readingDate: '2022-11-21T01:00:00Z'
  - price: 1.16
    readingDate: '2022-11-21T02:00:00Z'
  - price: 1.16
    readingDate: '2022-11-21T03:00:00Z'
  - price: 1.16
    readingDate: '2022-11-21T04:00:00Z'
friendly_name: Energyzero prijzen'

@mupsje I used your code without modifications

Change 2 settings and try again:
value_template: Ok in value_template: ā€œOKā€
usageType: 3 in usageType: 1

@complex1 : yes that was the solution, mainly the usageType:. After changing it to 1 it gave the correct value. I also searched the code and found it there, and there you see when you select gas it changes the value to 3. Thanks for your help, Iā€™m starting to understand it a bit. I do notice that it does not load the last hour of the day after, I think there is still something wrong with the time notation in the end time

fromDate: >
        {{(now().strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      tillDate: >
        {{((now()+ timedelta(days=2)).strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z

And I found another site where I can get the data from:

https://www.easyenergy.com/nl/iframe/energietarieven-stroom-nieuwestroom

and the url for the data:

https://mijn.easyenergy.com/nl/api/tariff/getapxtariffs?startTimestamp=2022-11-20T23%3A00%3A00.000Z&endTimestamp=2022-11-21T23%3A00%3A00.000Z&grouping=&includeVat=false

But from this url comes an xml file, which I also got to work in node red but I donā€™t know how to get todayā€™s date in node red. This section:

fromDate: >
        {{(now().strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      tillDate: >
        {{((now()+ timedelta(days=2)).strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z

This is the code in Node-Red:

[{"id":"0438d6830456e250","type":"http request","z":"a468b9631abe51c4","name":"","method":"GET","ret":"obj","paytoqs":"body","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":670,"y":260,"wires":[["1d6fd45c9a7cd789"]]},{"id":"1d6fd45c9a7cd789","type":"debug","z":"a468b9631abe51c4","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1060,"y":260,"wires":[]},{"id":"a8a9402d64df24e0","type":"inject","z":"a468b9631abe51c4","name":"Energy prices","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"https://mijn.easyenergy.com/nl/api/tariff/getapxtariffs?startTimestamp=2022-11-20T23%3A00%3A00.000Z&endTimestamp=2022-11-21T23%3A00%3A00.000Z&grouping=&includeVat=false","payloadType":"str","x":270,"y":260,"wires":[["70154cd4.de1444"]]},{"id":"70154cd4.de1444","type":"change","z":"a468b9631abe51c4","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":260,"wires":[["0438d6830456e250"]]}]

You see, you are learning fast :wink:

(I also edited my code to the correct values)

What am I doing wrong??

sensor:
#enegyGascost
  - platform: rest
    unique_id: energyzero_prices_rest_gas
    name: Energyzero prijzen
    resource: https://api.energyzero.nl/v1/energyprices
    scan_interval: 900
    value_template: OK
    params:
      fromDate: >
        {{(now().strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      tillDate: >
        {{((now()+ timedelta(days=2)).strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      interval: 4
      usageType: 3 #  of 1 voor electra
      inclBtw: true
      json_attributes:
        - Prizes

Invalid config for [sensor.rest]: template value should be a string for dictionary value @ data[ā€˜paramsā€™][ā€˜json_attributesā€™]. Got [ā€˜Prizesā€™]. (See ?, line ?).

I have managed to get energy and gas working with help from someone.

Please try the following:

sensor:
  - platform: rest
    unique_id: energyzero_gasprices_rest
    name: Gasprijs per uur 
    resource: https://api.energyzero.nl/v1/energyprices
    scan_interval: 900
    unit_of_measurement: "EUR/mĀ³"
    value_template: >
        {{value_json.Prices[now().hour].price}}
    params:
      fromDate: >
        {{(now().strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      tillDate: >
        {{((now()+ timedelta(days=2)).strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      interval: 4
      usageType: 3
      inclBtw: true
    json_attributes:
        - Prices
        - readingDate

  - platform: rest
    unique_id: energyzero_powerprices_rest
    name: Stroomprijs per uur 
    resource: https://api.energyzero.nl/v1/energyprices
    scan_interval: 900
    unit_of_measurement: "EUR/kWh"
    value_template: >
        {{value_json.Prices[now().hour].price}}
    params:
      fromDate: >
        {{(now().strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      tillDate: >
        {{((now()+ timedelta(days=2)).strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      interval: 4
      usageType: 1
      inclBtw: true
    json_attributes:
        - Prices
        - readingDate

Also in Github: GitHub - mbeefcake/homeassistant

Only problem I am having is that it reads the next hour and not the current hour. Does anybody know the solution to this?

The time when the screenshot was made is 18:53.

I think the dates of the imported energy prices are in UTC time (iso time). As you are (probably) in the Amsterdam time zone there is an 1 hour mismatch. You can add a timedelta to your {{value_json.Prices[now().hour].price}} but then you will have to update it again when our time zone switches from winter to summer.
When i plot the data using Apexcharts it seems to recognize the iso time format and gives the correct time when the price goes in effect.
Screenshot 2022-12-06 204524

The apexchart code:

type: custom:apexcharts-card
graph_span: 48h
span:
  start: day
now:
  show: true
  label: Now
  color: var(--green)
header:
  show: true
  title: Energyzero Electricity Price (ā‚¬/kWh)
  standard_format: true
yaxis:
  - min: 0
    decimals: 2
    apex_config:
      tickAmount: 8
      labels:
        show: true
      title:
        text: ā‚¬/kWh
        style:
          fontSize: 12px
          fontFamily: Arial
          fontWeight: 500
series:
  - entity: sensor.energyzero_electricity_price
    float_precision: 3
    stroke_width: 2
    type: column
    opacity: 0.5
    color: var(--purple)
    data_generator: |
      return entity.attributes.Prices.map((record, index) => {
              return [record.readingDate, record.price];
            });
3 Likes

Thanks for the tip @janeau! Have got it working with the correct hour (keeping in mind that I need to change it when the hours change during the winter and summer)

  - platform: rest
    unique_id: energyzero_prices_rest
    name: Gasprijs per uur 
    resource: https://api.energyzero.nl/v1/energyprices
    scan_interval: 900
    unit_of_measurement: "EUR/mĀ³"
    value_template: >
        {{value_json.Prices[(now()+timedelta(hours=-1)).hour].price}}
    params:
      fromDate: >
        {{(now().strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      tillDate: >
        {{((now()+ timedelta(days=2)).strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      interval: 4
      usageType: 3
      inclBtw: true
    json_attributes:
        - Prices
        - readingDate

  - platform: rest
    unique_id: energyzero_powerprices_rest
    name: Stroomprijs per uur 
    resource: https://api.energyzero.nl/v1/energyprices
    scan_interval: 900
    unit_of_measurement: "EUR/kWh"
    value_template: >
        {{value_json.Prices[(now()+timedelta(hours=-1)).hour].price}}
    params:
      fromDate: >
        {{(now().strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      tillDate: >
        {{((now()+ timedelta(days=2)).strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      interval: 4
      usageType: 1
      inclBtw: true
    json_attributes:
        - Prices
        - readingDate

Perhaps a noob question, but I tried your last code and added it to my configuration.yaml and restarted. It gives me the message: This entity is no longer being provided by the rest integration. If the entity is no longer in use, delete it in settings.

Any idea Iā€™m doing something wrong with perhaps my dashboard?

See that I missed the sensor in the code, can you try this?

sensor:
  - platform: rest
    unique_id: energyzero_prices_rest
    name: Gasprijs per uur 
    resource: https://api.energyzero.nl/v1/energyprices
    scan_interval: 900
    unit_of_measurement: "EUR/mĀ³"
    value_template: >
        {{value_json.Prices[(now()+timedelta(hours=-1)).hour].price}}
    params:
      fromDate: >
        {{(now().strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      tillDate: >
        {{((now()+ timedelta(days=2)).strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      interval: 4
      usageType: 3
      inclBtw: true
    json_attributes:
        - Prices
        - readingDate

  - platform: rest
    unique_id: energyzero_powerprices_rest
    name: Stroomprijs per uur 
    resource: https://api.energyzero.nl/v1/energyprices
    scan_interval: 900
    unit_of_measurement: "EUR/kWh"
    value_template: >
        {{value_json.Prices[(now()+timedelta(hours=-1)).hour].price}}
    params:
      fromDate: >
        {{(now().strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      tillDate: >
        {{((now()+ timedelta(days=2)).strftime('%Y-%m-%d')|as_datetime).isoformat()}}Z
      interval: 4
      usageType: 1
      inclBtw: true
    json_attributes:
        - Prices
        - readingDate

Thanks, yeah I did that but something went bad. Removed the lines, restarted, added them again and now it seems to work.

Thanks for the great code! Really useful since I moved to ANWB energy.

1 Like

FYI, Iā€™m currently working on an integration that will allow you to retrieve EnergyZero prices. The python package is almost ready and now mainly working on fixing the last bits in the integration (like how to handle tomorrowā€™s retrieval before 15:00).

2 Likes

That is awesome! This will also work for ANWB customers ofcourse, which is great :slight_smile:

1 Like

Note that if you want to use ā€œshow extremasā€ feature, you have to change the data_generator.
Example:

type: custom:apexcharts-card
graph_span: 24h
span:
  start: day
now:
  show: true
  label: Now
header:
  show: true
  title: Energyzero Electricity Price (ā‚¬/kWh)
  standard_format: true
yaxis:
  - min: 0
    decimals: 2
    apex_config:
      tickAmount: 8
      labels:
        show: true
      title:
        text: ā‚¬/kWh
        style:
          fontSize: 12px
          fontFamily: Arial
          fontWeight: 500
series:
  - entity: sensor.energyzero_electricity_price
    float_precision: 3
    stroke_width: 2
    show:
      in_header: true
      extremas: true
    type: column
    opacity: 0.5
    data_generator: |
      return entity.attributes.Prices.map((record, index) => {
              return [new Date(record.readingDate).getTime(), record.price];
            });

The data generator now creates a date object.
In the series config the ā€œshow:ā€ section is added to enable extremas (marking of the highest and lowest value)

1 Like

Just wondering: inclBTW=true

Does that mean: including ODE and energiebelasting (2 extra taxes) and ANWBs margin (per kWh or m3)

Or should I manually add these?

When I read this, only the 9/21% VAT is added to the price, so you should add the rest yourself.

image

1 Like