mega-hz
(Wolfram)
September 11, 2024, 2:27pm
1
Hi there,
i have a Template wich calculates measured KWh of a ShellyPlug into Euro.
- platform: template
sensors:
raum_1_energy_cost:
value_template: >
{% set energy_kwh = states('sensor.shellyplusplugs_c82e18086ea4_switch_0_energy')|float %}
{{ '%0.2f'|format(energy_kwh * 0.455) }}
unit_of_measurement: "€"
That works fine, but i need a change of it:
I want to calculate the cost ONLY if import Power of the grid!
So my thoughts:
Using the actual Power in Watts of the ShellyPlug instead of the KWh,
make own KWh calculation and euro but ONLY if sensor.import_power is 1.
Reason is: I want to know how much money my electric heater cost when the PV is empty and the Power comes from the grid.
instead of
sensor.shellyplusplugs_c82e18086ea4_switch_0_energy
it should be
sensor.shellyplusplugs_c82e18086ea4_switch_0_power
for actual Power. Sensor for importing Power is
sensor.import_power
For storing values or preset them i have a input_number in configruations.yaml:
input_number:
raum_1_euro:
name: raum_1_euro
min: 0
max: 100000
step: 0.001
unit_of_measurement: "€"
initial: 0
Can somebody help me to set this up please?
apreick
September 11, 2024, 3:07pm
2
Create helper template sensor (UI) Power-Sensor [W]
{% if states('sensor.import_power')|float(0) |round(0) ==1 %}
{{ states('sensor.shellyplusplugs_c82e18086ea4_switch_0_power')|float(0) |round(0)}}
{% else %}
0
{% endif %}
then create another helper (UI) integral sensor (Riemann left) with the upper one [Wh]
And then your € sensor [€]
mega-hz
(Wolfram)
September 11, 2024, 5:40pm
5
i am sorry, those helpers are new for me, dont know what to put into those fields.
Can it be done under Sensors - Platfom Template in configuration.yaml?
or can you show me a step by step?
apreick
September 11, 2024, 6:42pm
6
Before put my code to
Entwicklerwerzeuge => Template
To validied it
mega-hz
(Wolfram)
September 11, 2024, 6:45pm
7
if i change that (for testing) it shows the actual Watts. So that seems to be right!
apreick
September 11, 2024, 6:51pm
8
The helper input_power is not 1 => than you get 0
And
Put also this to Template
{{ states(‘sensor.shellyplusplugs_c82e18086ea4_switch_0_power’)}}
Edit: you was to fast
mega-hz
(Wolfram)
September 11, 2024, 6:59pm
9
- platform: template
sensors:
raum_1_energy_cost:
value_template: >
{% set energy_kwh = states('sensor.shellyplusplugs_c82e18086ea4_switch_0_energy')|float %}
{{ '%0.2f'|format(energy_kwh * 0.455) }}
unit_of_measurement: "€"
raum_1_import_watts:
value_template: >
{% if states('sensor.import_power')|float(0) |round(0) ==1 %}
{{ states('sensor.shellyplusplugs_c82e18086ea4_switch_0_power')|float(0) |round(0)}}
{% else %}
0
{% endif %}
Would this be ok in configuration.yaml?
mega-hz
(Wolfram)
September 11, 2024, 7:35pm
12
OK, thank you very much!
That works now !
1 Like
mega-hz
(Wolfram)
September 11, 2024, 8:18pm
13
@the riemann:
wich one is the right one?
trapz, left or right?
while testing after nearly an hour @1000W it show 0.09€, but 1 KWh is define with 0.455€ !
mega-hz
(Wolfram)
September 12, 2024, 12:50pm
16
i get KWh
and KWh to EURO:
- platform: template
sensors:
raum_1_energy_cost:
value_template: >
{% set energy_kwh = states('sensor.raum_1_import_energy')|float %}
{{ '%0.2f'|format(energy_kwh * 0.455) }}
unit_of_measurement: "€"
apreick
September 12, 2024, 2:23pm
17
Can you create a Screenshot from the Diagramm from the energy Sensor?
However, you can already see the 0.21 kWh (Screenshot) in the “display accuracy”
But these * 0.455 are 0.09 €
mega-hz
(Wolfram)
September 12, 2024, 5:36pm
18
yes, but i have to wait until our Battery is empty and we import power from grid.
Then i will let run the heating (1000W) for 1 hour, that should be 1KWh = 0.45€
mega-hz
(Wolfram)
September 12, 2024, 7:31pm
19
I found the error!
I used sensor.import_power (of the pv-inverter) but that was the wrong one!
That sensor gives the actual imported power in Watts!actual value is 4600W
Instead i now use the binary_sensor.importing_power, that one hast 0 and 1
So wait and see…
mega-hz
(Wolfram)
September 12, 2024, 8:08pm
20
so, after one hour of 1000W i still get wrong € values:
started @ 0.12€
now: 0.13€
there must be something wron with the KWh helper i think.
it shows 0.29KWh but after one hour of 1000W it must be 1.29 or so!
Or is my calculation for cost wrong?
- platform: template
sensors:
raum_1_energy_cost:
value_template: >
{% set energy_kwh = states('sensor.raum_1_import_energy')|float %}
{{ '%0.2f'|format(energy_kwh * 0.455) }}
unit_of_measurement: "€"
maybe is there a helper also for KWh → EURO ?