How do i calculate values from sensor data

hello, i read with a wemos the time difference of the S0 signals of 2 power meters .
the power in watt is the formula P = 1800/sensordata from wemos (sec)

wm05c1 Wr2k5 Wh…/2 … the value displayed is the time between the pulses
How can I arrange that the sensor is showing the result of the formula an not the value from wemos

Create a template sensor and use your formula as the state.

thanks for your answer… I tried a lot but never succeeded ;-(

I created a sensor.yaml with following content

  • platform: template
    sensors:
    sensor_netz_ooe:
    friendly_name: “Power_Netz_OÖ”
    entity_id: sensor.power_netz_ooe
    unit_of_measurement: ‘W’
    value_template: {{ (7200/states(‘sensor.wm05_pv_verteiler_w3a_counter_c1’)|float%) }}

The error when I check the configuration is as follows…

Konfiguration ERROR
Error loading /volume1/@appdata/homeassistant/config/configuration.yaml: invalid key: “OrderedDict([(”(7200/states(‘sensor.wm05_pv_verteiler_w3a_counter_c1’)|float)", None)])"
in “/volume1/@appdata/homeassistant/config/sensor.yaml”, line 34, column 0

Please help! I tried a lot, but without success. Only when I remove all lines from sensor.yaml the config ceck is ok again.

Why are you using the old format for template sensors? The link Florian provided clearly states that it is best practice to use the contemporary format.

Place the following in you configuration.yaml file or in a template.yaml file (with proper modifications) if you have already set one up.

template:
  - sensor:
    - name: "Power Netz OÖ"
      unit_of_measurement: "W"
      state: >
        {{ 7200 / states('sensor.wm05_pv_verteiler_w3a_counter_c1') | float(0) }}
      availability: >
        {{ states('sensor.wm05_pv_verteiler_w3a_counter_c1') | is_number }} 

That has funky quotes in it, change the curly quotes to normal ones and it’ll work

That was hard work for me to get it done, after a lot of syntax errors! Thank YOU for helping!

Now I want to show the new template sensor in the ENERGY DASHBOARD.

Hope this is as well as ???easy??? as the template sensor task …

You need energy measured in kWh. Use the integration integration. There are plenty of examples on the forum.

this worked really fine! i got all the energy sensors as expected.
but they are not avaibale in the energy dashboard. maybe it takes some tiḿe, as is


is stated?


even this morning, i am not able to selct the new template sensors. Any idea?

Found this info… and I changed customize.yaml… and now I’ve to wait again!
Add this to customize.yaml (or its equivalent via Configuration > Customizations):

sensor.solar_today:
last_reset: ‘1970-01-01T00:00:00+00:00’

Cool program! Worked perfect… Thank you!