It’s not that it isn’t working (well kind of, I just found the statistics
value_min
sensor is kind of useless on a sensor that doesn’t change at a constant rate), it just doesn’t feel right to use an input_number
and on top of that “mirror” it with a template sensor
.
The setup is quite involved (but surely not unique). It’s about using excess PV energy to heat water. To avoid confusion the scripts are python_script
s called as an action of an automation. YAML is so fiddly that there’s no way I would ever write the scripts in YAML, where something that takes two lines in Python becomes 10 lines .
One script (1
) is triggered when there are new data from the solar inverter (every 10s).
Another script (2
) is triggered by a new temperature reading from the water heater (essentially an ESPHome device that also does the relay switching to adjust the heater power level in several steps). That’s also about every 10 seconds but not synchronized with 1
.
Script 1
takes into account the power from/to the grid, the current load on the three phases, the PV voltage, a heater power limit set by script 2
, and the recent power setting (that’s what the statistics sensor should be for) and eventually sets the power level (a number
, not input_number
, in this case as it’s an entity created by ESPHome, but the thing about statistics sensors not being able to use them applies to both types), and respective phases for the ESPHome device.
Script 2
watches the heater temperature and calculates a power level limit depending on absolute temperature and temperature change (with a derivative
sensor). The calculated limit is written into the infamous input_number
, which is in turn read by script 1
.
It is working (unless I mess up; after changes I always have to wait for the next day for the sun to come back to see if it’s still fine or pulls 6kW of expensive electricity from the grid to heat water ), so I don’t want to refactor everything. If a different solution isn’t helpful here, it will be another time, because there’s always the next project, where I want to do things better.
Currently my main gripe switched to the statistics sensor not working the way I though it would, because if a value hasn’t changed it’s kind of ignored, making asking for the minimum of the last 30 seconds for example pointless. But that’s a topic for another hack .