Zonneplan ONE custom component

Great work on this intergration, moving to Zonneplan next week, already loving this.

App reports tarriffs deeper into the future then the 8 hrs I seem to get in HA.
Any chance this can be expanded?

The full available forcast is available as attribute of the Zonneplan current electricity tariff sensor.

See also Feature request: prices today and tomorrow · Issue #22 · fsaris/home-assistant-zonneplan-one · GitHub

I evidently need to open my eyes.
Thanks!

I worked on this today.
You only need the current tariff sensor, forecast data exists in the attributes.

You’ll want to install ApexCharts in home assistant via HACS, once completed you can add Custom: ApexChart cards to Lovelace.
I’m currently using this fairly crude bar graph:

image

Code for it:

type: custom:apexcharts-card
graph_span: 26h
span:
  start: day
  offset: +17H
header:
  title: Zonneplan Forecast
  show: true
now:
  show: true
  label: NOW
series:
  - entity: sensor.zonneplan_current_electricity_tariff
    unit: €/kWh
    type: column
    float_precision: 2
    data_generator: |
      return entity.attributes.forcast.map((entry) => {
         return [new Date(entry.datetime), entry.electricity_price / 10000000];
       });
yaxis:
  - id: '1'
    decimals: 2

I’m sure this can be done better, but i’ve got what I need for now and will make this pretty later.

2 Likes

Thx! Just what is was looking for! many thanks… ( have been struggling for some days :slight_smile: )

Schermafbeelding 2022-12-18 om 18.27.43

and code:

type: custom:apexcharts-card
apex_config:
  chart:
    height: 200px
experimental:
  color_threshold: true
graph_span: 30h
span:
  start: day
  offset: +4h
update_interval: +1h
header:
  title: Zonneplan Forecast
  show: true
now:
  show: true
  label: NU
series:
  - entity: sensor.zonneplan_current_electricity_tariff
    color_threshold:
      - value: 0
        color: lightgreen
      - value: 0.25
        color: green
      - value: 0.4
        color: red
    type: column
    float_precision: 2
    data_generator: |
      return entity.attributes.forcast.map((entry) => {
         return [new Date(entry.datetime), entry.electricity_price / 10000000];
       });
yaxis:
  - id: '1'
    decimals: 2
    min: 0.1
1 Like

Was trying to find the Zonneplan integration via HACS. I remember it was there few weeks ago but did not get around to install it. Now i don’t see it anymore. Any know reason for that? Before I add as custom repository, I just want to check

It should still be there.

It’s still on the list https://hacs-repositories.web.app/

1 Like

Thanks for this integration, my contract starts tomorrow so prepping for the transition from Frank Energie.

Question though, my integration shows everything (all entities including the 8hour forecast) except for the gas price- is this a known issue? Could it be because my contract is not yet active?

Whoops. My bad. Typo.

Contract is now active - still “unknown” - also logged at github.

In the mean time I setup a rest sensor which is updated at 6.10 am (and once more at 7.10am in case the data is not yet available).

For those with the same “challenge”:

platform: rest
resource: https://enever.nl/feed/gasprijs_vandaag.php
name: Gas price
scan_interval: 86400
json_attributes: data
value_template: "OK"
platform: template
sensors:
  calculated_gas_price:
    device_class: monetary
    unit_of_measurement: €/m³
    unique_id: “gas_price”
    value_template: '{% for i in states.sensor.gas_price.attributes.data %}{{ i.prijsZP}}{% endfor %}'
    friendly_name: Gas price

Has anyone created a custom sensor that calculates the average price of that day? How could that be done?

In the current_tarrif attributes the details of upcoming (and past) prices are shown. However the ‘last’ time slot is that of 22:00 (see below) while the app shows also 23:00 to 24:00

Is there a reason for this? Is there some kind of offset as the price seems to be the one of 23:00 to 24:00

Last attribute:

- price: 2731696
  electricity_price: 2731696
  tariff_group: normal
  solar_percentage: 0
  solar_yield: 0
  datetime: '2023-01-13T22:00:00.000000Z'
  sustainability_score: 472
  carbon_footprint_in_grams: 1921

Answering my own question: Someone has been very helpful, solution to be found here

That’s GMT/UTC

Ouch. That makes making custom sensors based on the attribute date extremely complicated.

In the end Zonneplan is Dutch. @minifranske Is there anyway this can be made CET?

That should be fine… works with apex; date/time is stored as UTC an HA will automatically show the applied time zone; same should be for template sensors.

I would need to check manual. But take below sensor. It compares with now().date(); Are you sure it then automatically takes 1 hour from the previous day and not just the 23 hours it can find for today?

- platform: template
  sensors:
    avg_energy_price:
      friendly_name: Average current energy price
      value_template: >
        {% set ns = namespace(sum = 0, count = 0) %}
        {% for item in state_attr('sensor.zonneplan_current_electricity_tariff', 'forcast') -%}
          {% if as_datetime(item.datetime).date() == now().date()  %}
            {% set ns.sum = ns.sum + item.price %}
            {% set ns.count = ns.count + 1 %}
          {% endif %}
        {%- endfor %}
        {{ (ns.sum/ns.count/100000) }}

If you change the data generator to below you can also get extremas in the graph:

            return entity.attributes.forcast.map((entry) => {
              return [new Date(entry.datetime).getTime(), entry.price /100000] ;
            });

For the colors in the graph: Instead of a static value to set the color threshold you can also adjust based on (in my case) average.

Example below

  - type: custom:config-template-card
    variables:
      MOVINGAVERAGE: states['sensor.avg_energy_price_cnt']
    entities:
      - ${MOVINGAVERAGE.entity_id}
    card:
      type: custom:apexcharts-card
      apex_config:
        chart:
          height: 200px
          fontFamily: Raleway,sans-serif
        xaxis:
          labels:
            format: HH
        legend:
          show: false
        stroke:
          width: 2
        plotOptions:
          bar:
            columnWidth: 100%
        grid:
          show: true
          borderColor: '#00000030'
          strokeDashArray: 4
          position: back
        dataLabels:
          offsetY: -8
          background:
            opacity: 0.01
            enabled: true
            foreColor: '#CF7524'
            padding: 2
            borderRadius: 4
            borderWidth: 0
          style:
            fontSize: 9px
            color: rgb(200,200,200)
      experimental:
        color_threshold: true
      graph_span: 30h
      span:
        start: day
        offset: +4h
      update_interval: +1h
      header:
        title: Zonneplan Forecast
        show: false
      now:
        show: true
        label: NOW
      series:
        - entity: sensor.zonneplan_current_electricity_tariff
          color_threshold:
            - value: ${MOVINGAVERAGE.state * .75}
              color: '#228B22'
            - value: ${MOVINGAVERAGE.state * 1}
              color: '#d35400'
            - value: ${MOVINGAVERAGE.state * 1.25}
              color: '#c0392b'
          show:
            extremas: true
          type: column
          float_precision: 2
          data_generator: |
            return entity.attributes.forcast.map((entry) => {
              return [new Date(entry.datetime).getTime(), entry.price /100000] ;
            });
      yaxis:
        - id: '1'
          decimals: 1
          min: 0.1
          apex_config:
            tickAmount: 4

This one has an attribute with the last date_time of update:

- platform: template
  sensors:
    zonneplan_gas_prijs:
      friendly_name: "Zonneplan Gasprijs"
      unit_of_measurement: €/m³
      device_class: monetary
      value_template: >-
        {% for i in states.sensor.enever_gasprijs.attributes.data %}
        {{ i.prijsZP }}
        {% endfor %}
      attribute_templates:
        datum: >-
          {% for i in states.sensor.enever_gasprijs.attributes.data %}
          {{ i.datum }}
          {% endfor %}