I’m working on an ESP hydrometer for home brewing, and what I would like to do is show a button in HA that allows the user to take the Original Gravity at the beginning of the batch, then save it to calculate alcohol % later on.
So far, I have
-a button
-which runs a script
-that turns a global boolean on for 60s, then off
-a template sensor that checks if the boolean is on, then returns the Gravity reading, or else returns nothing, or {}
-the template is then filtered using the throttle_average for the same 60s to even out any noise in the gravity reading
the problem I have is that after the global boolean turns off, the throttle_average starts returning NaN, so I added a heartbeat before it. this…works, but it is working through all the template logic and sending the exact same number to HA repeatedly. Its not just kinda kludgy, this is a battery powered device, sealed inside a pressurized vessel full of beer, I’d like to avoid wasted power. Does anyone know of a better way to do this?
here’s the code I have if the word form isn’t clear
I’d set the original sensor ‘hydro_gravity’ to to take an average over 60 seconds. If not make a template sensor that takes hydro_gravity and averages the value.
If you give the template only an id: and no name: it will be hidden from HA but be available to set the global.
interesting, that does seem a lot simpler, but then it needs another sensor if I want to expose the OG value in HA, maybe I don’t need to. I was trying to avoid having a long integration time for the hydro_gravity value, but I might be able to strike a balance.
I’m glad you got it working. You mentioned that the value was used in calculating the alcohol content. Is that a template sensor in HA? You should be able to add the og percentage as an attribute.
As to the sensor itself that youare getting noisy readings from perhaps this thread might help.