having templates sensors in sensor.yaml is the old way. You should migrate them all according the new way
Read the doc here : Template - Home Assistant
Wich one is displaying 0 ? power consumption grid ? Maybe the sensor you are reading is also at 0 ?
So lets say I consume 1000 watt, get 500 from solar, it should show a red line to 500 red line (use from net)
i consume 1000, get 2000 from solar, it should show -1000 in a red line.
But now i wonder, what’s the difference between those. and what meens % or %0.1f
and in the set PowerConsumption, set SolarPower, do those 2 values only exists here or did it create sensors or can i use these global now?
I think both sensors gives you the same output. In the first version you use the the python code 0.1f, meaning the result is formatted as a float value with one decimal.
The % use used within the template to execute the commands I think. You use it in almost all template definitions.
The second sensor converts the state of the input to float with the | float at the end. Better is to use | float(0) though. That also provides a default value of 0 in case the input is unavailable. Currently this still works without the default value, but will need mandatory in the December release I believe.
To your last question… Those variables are only temporary and usable within your template, not outside of it. I am not 100% sure though…
P.S. I see you also use the SolarEdge integration, you may find other useful templates and examples in my project.
But this one is counting up instead of the “current cost”
is there a way to create something like:
Current cost a hour = kwh price x ‘Power Consumption Grid’
Same for the gas.
So as results I want 4 bars,
1 energy current cost. .
1 energy costs today
1 gas current cost
1 gas cost today
I think you should use the utility_meter integration. This creates a new sensor based on a selected input, and can be reset on an hourly, daily, monthly, yearly basis.
In your case you would create 2 meters which reset hourly and use that for the multiplication. That starts from 0 each hour.
I tried, but that does not work. it still counts, so only at the full hour it shows the energy price.
I think i just manualy set the energy price in it. Example 0.50 cent X current grid power.
Just have to find a way to switch between prices when daytime and negative (back to grid) values
---
# Power Consumption Grid
# Bereken Energie verbruik - Opbrengst Zonnepanelen = netto verbruik
#
sensor:
name: Power Consumption Grid
unit_of_measurement: "W"
icon: "mdi:transmission-tower"
state: >
{% set PowerConsumption = states('sensor.power_consumption_w') | float(0) %}
{% set SolarPower = states('sensor.solaredge_current_power') | float(0) %}
{{ ((PowerConsumption - SolarPower)) | round(1) }}
---
# Power Consumption Grid Negative only = Teruglevering
# Bereken Energie verbruik - Opbrengst Zonnepanelen = Netto Verbruik, show positive only dus alleen Teruglevering
#
sensor:
name: Power Consumption Grid (Neg)
unit_of_measurement: "W"
icon: "mdi:transmission-tower-export"
state: >-
{% set PowerConsumption = states('sensor.power_consumption_w') | float(0) %}
{% set SolarPower = states('sensor.solaredge_current_power') | float(0) %}
{% set PowerConsumptionGridNeg = (PowerConsumption - SolarPower) | int %}
{{ ([-10000, PowerConsumptionGridNeg, 0] |sort) [1] }}
---
# Power Consumption Grid Positive only
# Bereken Energie verbruik - Opbrengst Zonnepanelen = Netto Verbruik, show positive only
#
sensor:
name: Power Consumption Grid (Pos)
unit_of_measurement: "W"
icon: "mdi:transmission-tower-import"
state: >-
{% set PowerConsumption = states('sensor.power_consumption_w') | float(0) %}
{% set SolarPower = states('sensor.solaredge_current_power') | float(0) %}
{% set PowerConsumptionGridPos = (PowerConsumption - SolarPower) | int %}
{{ ([0, PowerConsumptionGridPos, 10000] |sort) [1] }}
---
# Power Consumption in Watt, kWh to W
#
sensor:
name: Power Consumption (W)
unit_of_measurement: "W"
state: "{{ states('sensor.power_consumption')|float * 1000 }}"
icon: "hass:lightning-bolt"
One problem : I presume I have too much data, cause when I put these graphs on my dashboard my computer is in trouble… I’m working with the Slimme Meter (via ESPHome).
Editing the data can be very slow, but on my Raspberry Pi 4b it is no problem…
I do not use ESPHome, just ‘SlimmeLezer’ P1 port.
It should only show data for 4hours or 6 in the big graph?