Your math may benefit a an integration i been working on, alternative energy monitoring and power consumption protection/enforcement. Been running it for few months working out the bugs needed just what you made among a few other things before i start releasing this
also i feel you may benefit from this small read Communicating from Addon to Home Assistant: MQTT vs Registered Integration - #2 by zodyking

