-
-
Save klaasnicolaas/ccfd1cd3da62a13b3199ff378480bdbb to your computer and use it in GitHub Desktop.
| - type: custom:apexcharts-card | |
| graph_span: 1d | |
| header: | |
| show: true | |
| title: Electriciteitsprijzen Vandaag (€/kwh) | |
| span: | |
| start: day | |
| now: | |
| show: true | |
| label: Now | |
| yaxis: | |
| - id: price | |
| decimals: 2 | |
| apex_config: | |
| tickAmount: 5 | |
| series: | |
| - entity: sensor.energy_prices_today | |
| name: Price this hour | |
| yaxis_id: price | |
| data_generator: | | |
| return entity.attributes.prices.map((entry) => { | |
| return [new Date(entry.timestamp).getTime(), entry.price]; | |
| }); | |
| type: column | |
| show: | |
| extremas: true | |
| opacity: 0.8 | |
| float_precision: 2 |
| --- | |
| # Today - Hourly energy prices | |
| template: | |
| - trigger: | |
| - platform: homeassistant | |
| event: start | |
| - platform: time_pattern | |
| hours: "*" | |
| action: | |
| - service: energyzero.get_energy_prices | |
| response_variable: response | |
| data: | |
| config_entry: PUT_HERE_YOURS | |
| incl_vat: True | |
| sensor: | |
| - name: Energy prices - Today | |
| device_class: timestamp | |
| state: "{{ now() }}" | |
| attributes: | |
| prices: '{{ response.prices }}' | |
| # Tomorrow - Hourly energy prices | |
| - trigger: | |
| - platform: homeassistant | |
| event: start | |
| - platform: template | |
| value_template: "{{ now() > today_at('14:00') and now().minute == 0 }}" | |
| action: | |
| - service: energyzero.get_energy_prices | |
| response_variable: response | |
| data: | |
| config_entry: PUT_HERE_YOURS | |
| start: "{{ now() + timedelta(days=1) }}" | |
| end: "{{ now() + timedelta(days=1) }}" | |
| incl_vat: True | |
| sensor: | |
| - name: Energy prices - Tomorrow | |
| device_class: timestamp | |
| state: "{{ now() + timedelta(days=1) }}" | |
| attributes: | |
| prices: '{{ response.prices }}' |
The problem is that if you request the energy data including VAT, you get prices with 2 decimal places, if you request the prices excluding VAT, you get them with 5 decimal places.
./Klaas
That's perfect, thanks!
Thx for this awesom chart...
But how do set this chart up if I want to include costs and taxes per kWh?
I have allready setup 2 extra sensors, one for additional costs and one for taxes.
Please advise...
You can add the costs and taxes in the data_generator:
data_generator: >
return entity.attributes.prices.map((entry) => [new
Date(entry.timestamp), ((entry.price*1.21) + 0.15674)]);
My taxes are 21% and the added costs (€0.15674) already have the tax included, otherwise you'd configure it like this : (entry.price+costs)*taxes.
Thx man! My taxes ar also 21% but I pay a little less at ANWB Energy!
But this worked for me...
y data including VAT, you get prices with 2 decimal places, if you request the prices excluding VAT, you get them with 5 decimal places.
You can use the excl VAT prices, and in the return make it like this: return entity.attributes.prices.map((entry) => {
return [new Date(entry.timestamp).getTime(), entry.price *1.21 ];
The calculation is still be done in 3 decimals. ( if used with float_precision: 3 )
Thx man! My taxes ar also 21% but I pay a little less at ANWB Energy!
But this worked for me...
ANWB is around 17ct per Kwh Tax and buy costs. - De inkoopkosten bedragen € 0,0484 per kWh voor stroom en € 0,05911 per m³ voor gas (in 2025), terwijl de energiebelasting voor stroom € 0,12286 per kWh - Later the 4.8 ct will be around 2 ct less.
@MaartenDrenth , https://gist.github.com/klaasnicolaas/ccfd1cd3da62a13b3199ff378480bdbb?permalink_comment_id=4825435#gistcomment-4825435
I like the idea to have both charts in one. Today / Tomorrow.
Your solution gives extra information in the bottom of the chart. Price 0.xxx Tomorrow 0.xxx. The Tomorrow price is the last price of Tomorrow (when after 14.00 today), information not usable. the Price, I don't know which price it is using. I would like to get the Now price overthere, The Tomorrow price to be removed. Any ideas how ?
The trigger and the sensor can be in the template file.
I started with 2 installation on 2 different machines. 1 NUC -prod and LT -play, both created from scratch.
Testing on the play, then when succeeded, copy to the production one.
Installed the apexcharts om the play. Everything worked.
Copy to the prod, I got issues.
Now the setup, I struggled a lot with the inclusion of the trigger+sensor, the Studio Code Server gave indeed a couple of issues, like multipe occurence of:
- missing property "entity_id is missing
- String does not match the pattern of "LEGACY_SYNTAX"
. Still having the error messages. Could not solve the issue.
But it is working like it supposed to.
I followed the newest implementation of HA documentation.
The configuration file can be as simple as possible.
The mentioned sensors with trigger has to be placed in the template.yaml and the configuration.yaml
includes "template: !include template.yaml" (no "").
Configuration.yaml
# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensors.yaml
template: !include template.yaml
Beginning of template.yaml
# This template section contains both today's and tomorrow's sensors.
# It should be the only "template:" block in your configuration.
# strange: in the blocks today and tomorrow the Code editor gives errors
# like: Missing entity_id, and string does not match the pattern of legacy syntax
# within these blocks it can be ignored. This is an ghost issue.
# the process still works
# Today - Hourly energy prices
- trigger:
- platform: homeassistant
event: start
- platform: time_pattern
hours: "*"
action:
- service: energyzero.get_energy_prices
response_variable: response
data:
config_entry: <code>
incl_vat: false
- service: persistent_notification.create
data:
title: "Energy Prices Debug"
message: "{{ response.prices[:4] | map(attribute='price') | list | default([,]) | to_json }}"
sensor:
- name: Energy prices - Today
unique_id: energy_prices_day
device_class: timestamp
state: "{{ now() }}"
attributes:
prices: "{{ response.prices }}"
Does anyone has an idea why the errors are reported by the Studio Code Server ?? And how to solve it?
Hey Klaas, I noticed the precision of the template sensor to grab today's and tomorrow's dynamic prices has a precision of 2 digits. All other providers, I've found, use 3 digit precision. Leading to some rounding issues. Is there any way to raise the precision for the template sensor? I've given it a unique_id and fiddled with the template and checked the python code, but I'm lost :)
Here's an example of how this looks, all other providers are on the same line :
