HI Guys, I’m using a pressure sensor in a water tank to indicate the level of the water.
The sensor outputs a voltage that equates to the water level, which is connected to the otherwise spare Analog input on a Shelly Uni that’s installed in the door control on the other side of the shed, to provide a sensor with a voltage reading.
I’ve created a template sensor which takes that voltage as its input and calculates a basic % number between 1 and 100 to indicate the level of water in the tank. So far, so good.
Problem is, there is some interference coming from goodness knows where which causes the voltage reading to jump up by a volt or two for several seconds, quite often. I have no idea if its the pressure transducer, or the Analog input on the Shelly, or some random radio signal hitting the wire between the two. But it throws my measurement of the water level off, depending on exactly what moment you look at it - as per the sample graph below…
I"m taking the baseline of the graph as the accurate reading, and all the spikes as interference.
I don’t want to use an average (mean) - as this will still give a false high reading most of the time, but it seems that a “modal” reading for the previous say 5 minutes, would be more often than not about right.
I have been round in circles for some time and not found anything that looks like making this work. My templating skills are rudimentary at best - but I’m hoping there is just some stat function I don’t know about that can adjust the template to read the modal number…
{{ (states('sensor.shed_door_control_adc') | float / 5 * 100 ) }}
I’m guessing this shouldn’t be too hard, but it has managed to allude me so far. Any clues?
Cheers,
Pcal