Closed Achronite closed 1 year ago
Another (simpler) option would be to calculate the % in my code from VOLTAGE and report this as a new topic in MQTT, either:
battery/state
or VOLTAGE/percent
or even replace VOLTAGE/state
with the % value
Fairly sure this could be put into a _template
(value or state) of sorts, but I can't get it working and not sure on the exact syntax.
That said, is the simplier option not actually better overall anyway? Well the code has to sit in the app but at least it is 100% abstract from anything upstream so easy to tweak calculations.
mqtt-energenie-ener314rt is already provising a bunch of extra fuctionality over the lib so having this type of stuff built in seems in keeping with that and also has the added benifit of being easilly avalable to anyone using this from MQTT not just HA? - I already use this to feed data into an archiver that has nottihng to do with Home Assistant, along with HA of course.
Something as simple as this should then work for getting it into HA once the code is in the app.
"unit_of_measurement": "%",
"device_class": "battery",
"state_topic": "energenie/3/7575/BATTERY/statel",
At that point, there would be nothing to stop you adding something like
"entity_category": "diagnostic",
"enabled_by_default": false,
To other less critical settings like voltage, and maybe more of the TRV values. Then they will appear as hidden values under the Diagnostic control.
In fact, adding "entity_category": "diagnostic", to the TRV Maintainance but ensuring it is not hidden may also be an idea?
The calculation on battery % seems very much an art rather than science, so I'm not 100% convinced of the value now. If I do add it I'll probably do it via a calculation in my mqtt code; the templates just seem a bit fiddly to work with.
Good idea on the diagnostics, I'll think I'll move a few values under there (ERRORS, ERROR_TEXT, etc) in the next release.
I've decided to add a battery level calculation. I've added it to the eTRV and Whole house energy monitor for now.
This is the calculation I've used based on number of 1.5v batteries in each device and voltage (v)
if (v >= (1.55*batteries)){
charge = 100;
} else if (v <=0 ){
charge = 0;
} else if (v > (1.4*batteries)){
charge = 60.6*v/batteries + 6;
} else if ( v < (1.1*batteries)){
charge = 8.3*v/batteries;
} else {
charge = 9412 - 23449*(v/batteries) + 19240*(v*v/batteries) - 5176*(v*v*v/batteries); // cubic regression
}
Via MQTT Discovery the v0.1.1 implementation reports the voltage of the battery powered devices in Volts with a fixed battery icon. It would be good if the icon reflected the charge state of the battery.
One option is to convert this to a % value, and then make use of the device_class: battery in Home Assistant. This template seems to work for 3V eTRV in the editor:
I'm not sure how best to automatically add and use this template in Home Assistant. Anybody?