Hi. I am trying to create a PowerCalc sensor which gives the SOLAR Wh of electricity which is supplied to my hot water cylinder (HWC). The HWC has a solar diverter (with SSR) so the Wh is not simply the rating of the element… I think I need something like this in the configuration.yaml:
- entity_id: sensor.dummy
name: 'HWC Solar Wh'
fixed:
power: "{{states('my_calculated_solar_watts')}}"
I am happy with the below logic to calculate ‘my_calculated_solar_watts’ (the watts from solar) - the problem is where to put the below code, and also is the formatting correct? Can I somehow include the below calculations within the above? Or where can I do these calculations?
sensor.phase_1
and sensor.hwc_watts
are existing HA sensors…
As you can see, a bit of logic is required to give me the watts that has come from solar…
if (states('sensor.phase_1') <= 0){ //all hwc is SOLAR!
return (states('sensor.hwc_watts') | float(0))
}
else{
if (states('sensor.phase_1') - states('sensor.hwc_watts') >= 0){ //No solar used
return (0)
}
else{
if (states('sensor.hwc_watts') > 5){ //return the solar proportion
return ((ABS(states('sensor.phase_1') - states('sensor.hwc_watts') / states('sensor.hwc_watts'))) * states('sensor.hwc_watts') | float (0))
}
else{
return (0)
}
}
}
Thank you for any help!