The use case here seems to be catch an integer value that is most common, not to time-smooth a signal, but I could be wrong. I don’t know an easy way to do this, but I would put in a feature request for mode to be added to the statistics sensor. This seems like a straightforward addition.
@123 - yes, have been trying to use filter sensor but have only seen average and median, or first value in a given time period but that doesn’t help unfortunately unless someone knows how I can use it as the documentation is not the clearest
@MatthewFlamm exactly - I was hoping that I could identify the most common vs. time-smooth, averages etc. I may try the statistics sensor with a max age of 10 seconds and see if median works for my purposes (even if variance is high, so long as over 50% of values are the one I am looking for it might work), but yes probably a feature request if no existing capability
I had the same problem, sometimes my supersonic sensor returned incorrect measurements, now the sensor shows only correct results thanks to this query. Just change the sensor name and insert the code into configuration.yaml
Shows the most frequently occurring measurement result from the last 5 minutes
sql:
- name: Szambo state
query: >
SELECT
states.state, COUNT(*) AS category_count
FROM
states
INNER JOIN states_meta ON
states.metadata_id = states_meta.metadata_id
WHERE
states_meta.entity_id = 'sensor.poziom_zapelnienia_zbiornika'
AND last_updated_ts >= strftime('%s', 'now', '-5 minutes')
GROUP BY states.state
ORDER BY
category_count DESC
LIMIT
1;
column: "state"