KWh in EURO but with

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?

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 [€]

Screenshot (131)
Wich one?

Template Sensor

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?

Before put my code to
Entwicklerwerzeuge => Template
To validied it

if i change that (for testing) it shows the actual Watts. So that seems to be right!

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 :v:

  - 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?

Template Sensor


ok

OK, thank you very much!
That works now !

1 Like

@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€ !

see Post 2

? You get Wh or KWh

Test it in Template

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: "€"

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 € :hugs::wink::v:

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€

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…

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 ?