Zonneplan ONE custom component

Hi @Botap, I am working on this solution but the results are different from the manual calculation. Did’t find the time to figger out why.

  - platform: template
    sensors:
      laagste_prijs_zonneplan_test5:
        friendly_name: "Laagste prijs Zonneplan Test5"
  #      value_template: "{{ (states('sensor.enstso_e_lowest_energy_price_today') | float + (states('sensor.zonneplan_current_electricity_tariff') | float - states('sensor.enstso_e_current_electricity_market_price') | float)) | round(8) }}"
        value_template: "{{ (states('sensor.enstso_e_lowest_energy_price_today') | float + (states('sensor.zonneplan_current_electricity_tariff') | float - states('sensor.enstso_e_current_electricity_market_price') | float)) }}"
        unit_of_measurement: "€/kWh"
        icon_template: mdi:currency-eur

for example, tomorrows Zonneplan lowest price will be 0.2856796 and the calculated lowest price is 0,2856816 €/kWh.

Hi all,
I have the Zonneplan Energy contract, the P1 dongle and the app with P1-data and hourly prices.
But I don’t have Zonneplan solar pane;s and inverter. In that context, is this integration still usefull for me to get the hourly prices and current consumption/production?
Just out of curiosity: Is the integration getting the information from the Zonneplan website, or directly from the dongle?

Thanks!

Yes, and through the API (or: backend of the app. So in your choices: the website).

I also don’t have the Zonneplan inverter, works all fine. Data is retrieved from the “slimme meter” in your “meterkast” by the dongle, sent to the servers of Zonneplan, and from there retrieved by the app and the component.

1 Like

I’ve altered a previously shared graph which now looks more like how it’s shown in the Zonneplan iOS app.

image

type: custom:plotly-graph
title: Dynamische stroomprijs
hours_to_show: 18
time_offset: 12h
fn: |
  $fn ({ hass, vars }) => {
    vars.x = []; vars.y = []; vars.color = []; vars.hover = []
    vars.min = {p: 999,t: null}; vars.max = {p:-999,t:null}
    vars.ymin = 999; vars.ymax = -999
    vars.unit_of_measurement = hass.states['sensor.zonneplan_current_electricity_tariff'].attributes.unit_of_measurement
    vars.now = {t: Date.now(), p: parseFloat(hass.states['sensor.zonneplan_current_electricity_tariff'].state)} 
    vars.now.h = "<b>" + vars.now.p.toFixed(3) + "</b> " + vars.unit_of_measurement + " @now " 
    vars.avg = { p: 0, c: 0 }
    hass.states['sensor.zonneplan_current_electricity_tariff']?.attributes?.forecast?.map(e => {
      var t = new Date(e.datetime).getTime()+1800000 
      var p = e.electricity_price/10000000
      vars.avg.p += p
      vars.avg.c++
      var c = e.tariff_group.replace("low", "#00a964").replace("normal", "#365651").replace("high","#ed5e18")
      if (t>=Date.now()-1800000) {
        if (p<vars.min.p) vars.min = {p,t,c}
        if (p>vars.max.p) vars.max = {p,t,c}
      }
      if (p<vars.ymin) vars.ymin = p
      if (p>vars.ymax) vars.ymax = p
      vars.x.push(t)
      vars.y.push(p)
      vars.color.push(c)
      vars.hover.push(String(new Date(t).getHours()).padStart(2,"0") + "-" + 
        String(new Date((new Date(t).getTime()+3600000)).getHours()).padStart(2,"0") + ": <b>" + 
        p.toFixed(3) + "</b> " + vars.unit_of_measurement)
    })
    vars.min.h = "<b>" + vars.min.p.toFixed(3) + "</b> " + vars.unit_of_measurement + " @ " + new Date(vars.min.t).getHours() + ":00"
    vars.max.h = "<b>" + vars.max.p.toFixed(3) + "</b> " + vars.unit_of_measurement + " @ " +  new Date(vars.max.t).getHours() + ":00"
    vars.avg.p = vars.avg.p / vars.avg.c
    vars.avg.h = "<b>" + vars.avg.p.toFixed(3) + "</b> " + vars.unit_of_measurement + " average"
    // console.log(vars)
  }
layout:
  margin:
    l: 20
    r: 20
    b: 40
  yaxis:
    fixedrange: false
    tickformat: .2f
    range: $fn ({vars}) => [ vars.ymin-0.02, vars.ymax+0.02 ]
    showgrid: false
    visible: false
    showticklabels: true
    showline: false
    title: null
  xaxis:
    tickformat: '%H'
    showgrid: false
    visible: true
    showticklabels: true
    showline: false
    dtick: 3600000
config:
  displayModeBar: false
  scrollZoom: false
entities:
  - entity: ''
    unit_of_measurement: $ex vars.unit_of_measurement
    showlegend: false
    x: $ex vars.x
    'y': $ex vars.y
    marker:
      color: $ex vars.color
    type: bar
    hovertemplate: $ex vars.hover
  - entity: ''
    mode: markers
    textposition: top
    showlegend: true
    name: $ex vars.min.h
    hovertemplate: $ex vars.min.h
    yaxis: y0
    marker:
      symbol: diamond
      color: $ex vars.min.c
      opacity: 0.7
    x:
      - $ex vars.min.t
    'y':
      - $ex vars.min.p
  - entity: ''
    mode: markers
    textposition: top
    showlegend: true
    name: $ex vars.max.h
    hovertemplate: $ex vars.max.h
    yaxis: y0
    marker:
      symbol: diamond
      color: $ex vars.max.c
      opacity: 0.7
    x:
      - $ex vars.max.t
    'y':
      - $ex vars.max.p
  - entity: ''
    name: Now
    hovertemplate: Now
    yaxis: y9
    showlegend: false
    line:
      width: 0.5
      color: gray
      opacity: 1
    x: $ex [vars.now.t, vars.now.t]
    'y':
      - 0
      - 1
7 Likes

Does anyone have the correct code for the lowest price sensor? that tells you between which times the price is lowest.

I received unavailable from my sensor code from ESPhome with display to manually delay electricity consumption for non connected devices


      time_low_coming_short:
        friendly_name: Time lowest price short
        unique_id: time_low_coming_short
        device_class: timestamp
        value_template: >
         {% set dtnow = now().isoformat()[0:26]~"Z" %}
         {% set dtend = (now()+timedelta(hours=6)).isoformat()[0:26]~"Z" %}
         {% set fclist = state_attr('sensor.zonneplan_current_electricity_tariff','forecast')
                         |selectattr('datetime','>=',dtnow)|selectattr('datetime','<=',dtend)|list %}
         {% set plist = fclist|map(attribute='price')|list %}
         {% set ns = namespace(fc2=[]) %}
         {%- for fc in fclist[:-1] -%}
         {%- set ns.fc2 = ns.fc2 + [{'datetime':fc['datetime'],'price':(plist[loop.index0] + plist[loop.index0+1])/2}] -%}
         {%- endfor -%}
         {% set pmin = ns.fc2|map(attribute='price')|list|min %}
         {{ (ns.fc2|selectattr('price','eq',pmin)|first)['datetime'] }}

The name of the attribute ‘price’ has been changed by the Zonneplan component developer to “electricity_price” few months ago. If you change that, it should work.

This works great but if you want to trigger automations based on this its never triggered. The date always shifts forward before the current time matches the cheapest time.

Does anyone know how to resolve this?

Hi @minifranske

Sometimes sensor.zonneplan_p1_electricity_consumption_today_cost shows a very different value when comparing it to the mobile Zonneplan app.

While the app shows 0,76 euros, the sensor’s value is 0.0176131088.


Is Zonneplan delivering the wrong value through its API for this sensor or is there a bug in the integration?

Probably the api published the cost excluding taxes etc?

But to cut a long story short, Why not use the HA energy dashboard instead? It will do this for you, all thats required is a production/consumption sensor and a current price sensor. All of which the zonneplan api provides.

That’s true, but I would also like to place the costs on my own dashboards with power and solar panels information which I use more than the Energy dashboard. But maybe I’ll just use the Energy dashboard for this indeed.

Where does that sensor.zonneplan_cheapest_hours come from? That is not an attribute in my Zonneplan One Component.

I saw the zonneplan card what they are using in the app. I created one in home assistant. Thanks for sharing

afbeelding

1 Like

Would you like to share the code?

I don’t have Zonneplan but i have a Solis Inverter. But if you are a bit handy you can change the sensors. Don’t look a the code it’s still a bit messy and a lot of things double :).

type: custom:stack-in-card
cards:
  - type: horizontal-stack
    cards:
      - square: false
        type: grid
        cards:
          - type: custom:mushroom-title-card
            title: Stroomkosten
            subtitle: vandaag
          - type: custom:mushroom-title-card
            title: >
              € {{ ((states.sensor.verbruik_elektra_dagelijks.state | float *
              0.18646) - (states.sensor.solis_energy_today.state | float *
              0.18646)) | round(2) }}
            card_mod:
              style: |
                .title {
                  text-align: right;
                  font-size: 50px!important;
                  }
        columns: 2
        style: |
          ha-card {
            border: none;
          }
  - type: horizontal-stack
    cards:
      - square: false
        type: grid
        cards:
          - type: custom:mushroom-title-card
            title: VERBRUIK
            subtitle: >-
              {{ states ('sensor.verbruik_elektra_dagelijks') | upper }} kWh x
              18 ct
            card_mod:
              style: |
                .title {
                  font-size: 12px!important;
                  color: rgba(255, 255, 255,0.5)!important;
                  font-weight: 300!important;
                  }
          - type: custom:mushroom-title-card
            title: TERUGLEVERING
            subtitle: |
              {{ states ('sensor.solis_energy_today') }} kWh
            card_mod:
              style: |
                .title {
                  font-size: 12px!important;
                  color: rgba(255, 255, 255,0.5)!important;
                  text-align: right;
                  font-weight: 300!important;
                  }
                .subtitle { 
                  text-align: right!important;
                  color: rgba(255, 255, 255,0.5)!important;
                  }
        columns: 2
        style: |
          ha-card {
            border: none;
          }
card_mod:
  style: |
    ha-card {
      background-color: #00A964;
      --primary-text-color: #FFFFFF;
      --secondary-text-color: #FFFFFF;
      border-radius: 20px;
      padding: 5px 5px;
        }

Hi @ronniebee

I`m trieing for hours to get this nice card to work but no luck, any ideas?

just getting this

image

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: '#228B22'
      - value: 0.25
        color: '#d35400'
      - value: 0.4
        color: '#c0392b'
    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

ApexCharts installed through hacs but this would be te first chart so maybe the problem is in my intergration?

Not sure this is the right place to ask but I seem to have some trouble after installation. Except, there are no errors.
What happens is I do not get the P1 readings. I only see Zonneplan Yield Total
Zonneplan P1 electricity consumption today
Zonneplan P1 electricity returned today

I do have a working P1 connector that shows data using the DSMR Slimme meter integration. Enabling or disabling this integration does not make a difference fot this Zonneplan integration.
Cannot find this issue but perhaps I’m not as good in finding it. Please help.

Most sensors are disabled by default. Are there no disabled sensors shown?

I can’t find any.
Under integrations I see Zonneplan ONE with 1 device. Clicking on that one device I see 5 sensors:

  1. Zonneplan last measured
  2. Zonneplan last measured value
  3. Zonneplan yield today
  4. Zonneplan yield total
  5. Zonneplan first measured.

Do you have the P1 dongle from Zonneplan connected? And are these values visible in the Zonneplan app?

If you have a P1 dongle from Zonneplan (and the contract) you should see a Connect energiemeter device in HomeAssistant.

The values you mention belong to the PV Installatie device (je zonnepanelen :slight_smile: )