@rak wrote:
Hi guys,
switching from OH to HA. over the weekend. Steep learning curve behind me and ahead. I am really impressed by HA. One thing I am banging my head around for 6h now and i Need your help.
I have a sensor which gets every minute an update. Its a counter which counts 1/250 kWh and its just a number. I get it from KNX, but that should not matter.
With a sensor template I calculate this into kWh ( a number i can read and see on my meter).
- platform: template sensors: counter_power_kwh: friendly_name: "Strom" unit_of_measurement: 'kWh' value_template: > {{ (states("sensor.counter_power_impulse")|float - 16369685.0) / 250.0 + 35344.6 }}
I have another item which gets updated each time the above one gets updated. Target is to calculate delta kWh and delta T in seconds.
I checked in debugging. When I replace the from_state with a copy paste value from the previous run I get reasonable numbers (480W), however in HA I get 0.0 because from_state is always 0.0.
- platform: template sensors: counter_power_consumption: unit_of_measurement: 'W' value_template: > {% set delta_kWh = (states("sensor.counter_power_kwh")|float) - (states('states.sensor.counter_power_kwh.from_state')|float) %} {% set delta_s = (as_timestamp(now()) - as_timestamp(states.sensor.counter_power_kwh.last_changed)) %} {% if states('states.sensor.counter_power_kwh.from_state')|float == 0.0 %} 0.0 {% else %} {{ (delta_kWh / delta_s) * 1000.0 * 3600.0 }} {% endif %}
Can someone point me into the right direction? I have
- an entity whith increasing kWh
- I want a regular check how much kWh were consumed.
- Say every 6min would be ok.It really does not matter how often.
- with that delta kWh and delta T I can calculate the power consumption.
- I need only delta from sensor (current and previous value).
How can I get this done? Is an automation the right way? How do I set a sensor item from an action?
I am stuck and need some sleep.
Thank you for reading so far.
Regards
Ralf
Posts: 4
Participants: 3