How to take Median Value of Ultrasonic Sensor Input?

Hi,

I have been trying to Get stable Reading for My Ground tank Water Level Measurement.But ultrasonic sensor output sometimes swings…more than 10% of its value.

i want to eliminate such scenario by taking Median value of last 10 inputs ( inputs might be same i.e 53,53,53,53,53,53,53…53).

Can someone help me with code for openhab rules which might help me ?

I have been using Grafana & rrd4j for storing persistence value.

is any workaround available ? for median value from ESP Sensor Value (Tasmota Firmware).

An easy way would be using rrd4j to do that.
Look how you configured the rrd4j archives (or do you use the default?).
The archive 2 and following compute their values from the minute-wise readings, that computing could be an average. By configuring an archive that condenses 10 readings into 1 you could get what you want.

BTW: I like the setup of rrd4j with Grafana and NOT InfluxDB.

I think this can be handled in Grafan as well. I can’t get to my Grafana right now for some reason but when you add the data to the graph, one of the fields lets you define a function that will let you smooth spikes like these.

Look at the Selection/Aggregation Functions section of InfluxDB+Grafana persistence and graphing for a good explanation.

I bet many would appreciate a tutorial on how to set that up. Since rrd4j is an embedded database it isn’t immediately clear how one would connect Grafana to it.

1 Like