Okay,
I know it’s a power (Watt) sensor, that’s the whole point of my argument about integrating it’s value, but we can derive energy from it, as we KNOW the time period over which it’s giving us information.
So I’m not 100% sure that this config is perfect, I hope @petro and @tom_l will jump in to correct any mistakes I make; but here goes.
Create at least 2 input number’s similar to the below (do NOT repeat the input_number: header if you already have one set UNLESS you use packages, if in doubt - ask ! )
So lets assume the heater is on 8 hours a day for 31 days (that should be WAY overkill) = 744 (round up to 750)
input_number:
in_utility_water_heater_wh_month:
name: Water Heater Wh Month
#initial: 0
min: 0
max: 750000
step: 0.1
mode: box
icon: mdi:flash
in_utility_water_heater_kwh_year:
name: Water Heater kWh Year
#initial: 0
min: 0
max: 9000
step: 0.001
mode: box
icon: mdi:flash
This input number will carry across reboots and it will just keep increasing over time, so I’ve set the max value to be 0.75MWh, which should be fine. So this is to be used as a temporary (monthly) watt hour store (step value is set low to improve accuracy - and we’ll convert that to kWh in a mo)
Then we need an auotmation to run every 3 seconds (equal to your sensor update and it doesn’t matter where in it’s cycle)
It then reads the value, divides by 1200 (cos it is averaging over 3 secs not 1 sec (so 1/3 of 3600) and that gives us Wh added over the last 3 secs) So 3000 / 1200 = 2.5 Wh added (as an example)
It would be better to do ALL the calculations in Watts for accuracy but asking an input number to store 9,000,000 is iffy (petro, please correct me, what are the limits on input numbers ? I’ve never seen that in the docs ???)
So (continuing the example) 2.5 Wh times 20 samples a minute times 60 minutes an hour = 3000 Wh (the number we started with, IF the heater were ON that whole period, but now in different units and moderated by the actual sensor reading)
The automation uses time pattern (again syntax may be off as the docs don’t mention * but I’ve seen it used) (thinking about it ‘/3’ would work just as well) : -
automation:
## get last Watt reading and add integration value (cumulative)
- alias: au_utility_water_heater_kwh_update
trigger:
- platform: time_pattern
seconds: '*3'
action:
- service: input_number.set_value
data_template:
entity_id: input_number.in_utility_water_heater_wh_month
value: "{{ (states('input_number.in_utility_water_heater_wh_month') | float) + (states('sensor.pzem_004t_boiler_v3_power') | float) / 1200 }}"
Again be careful not to duplicate the automation: header.
This should give you an incrementing Wh meter from which you can create a sensor to display kWh
This should also be periodically added to the kWh (but divide it by 1000) (AND resetting this one as you don’t want to count values twice !)
It’s bound NOT to work first time; but I’ll keep my fingers crossed ![:roll_eyes: :roll_eyes:](https://community.home-assistant.io/images/emoji/twitter/roll_eyes.png?v=9)
Edit: sorry forgot to add that this passed config check but I can’t test (in anger) as I don’t have a similar entity