Time throttle filter

I have a water level detector that during a transition time flips on and off more or less every second. I would like to get a more stable reading and found the filter platform and the throttle_time filter that I thought should solve my problem. However, it does not work as I expect. The output of this filter is “on” forever. I thought it should take the sample the first change in the time window and then ignore subsequent changes until the end of the time window, and then take a new sample and so on.

My (filtered) sensor definition looks like this:

- platform: filter
    name: "Filtered low water"
    entity_id: binary_sensor.poolwaterlevel
    filters:
      - filter: time_throttle
        window_size: "0:10"

Right now the poolwater sensor changes value more or less every second. But the filtered low water sensor has never showed any other value than “on”.

I must have misunderstood something or?

The filter platform is for the sensor domain. Not the binary_sensor domain.

How is the binary sensor defined?

If in YAML you can use delayed_on and/or delayed_off.

If it is a discovered sensor you can create a template binary sensor that uses those options.

Sorry, it works as expected. I just had a too narrow time window when I checked the filter data in the History tab…

Edit: @tom_l, saw your remark about delayed_on and delayed_off. Is possible to filter the raw binary sensor with those option? Even if the filter works as expected, the rapid on/off changes of the raw sensor will fill up the database with a lot of noice. I can’t find any other info about delayed_on/delayed_off than GPIO related. In my case the raw sensor is MQTT based.

It won’t stop the states being sent but it will stop your binary sensor reacting. Post your mqtt config for the binary sensor, and what is more important a fast on or off time (the other will be delayed by the filter)?

I use MQTT autodiscovery and this is what I find in HA:

Poolwater (switch.poolwater)
MQTT discovery data:
Topic: homeassistant/switch/mqtt-io-776d370b5ca2409f60dcff963e0e420d0ca557e0/Poolwater/config
Payload
name: Poolwater
availability_topic: gamlahuset/status
payload_available: available
payload_not_available: unavailable
device:
  manufacturer: MQTT IO
  model: v2.2.6
  identifiers:
    - mqtt-io
    - mqtt-io-776d370b5ca2409f60dcff963e0e420d0ca557e0
  name: MQTT IO
unique_id: mqtt-io-776d370b5ca2409f60dcff963e0e420d0ca557e0_rpi_output_Poolwater
state_topic: gamlahuset/output/Poolwater
command_topic: gamlahuset/output/Poolwater/set
payload_on: 'ON'
payload_off: 'OFF'
platform: mqtt

This is not a critical thing for me since I have python script on the remote machine that controls waterfilling. I just thought it would be nice to get rid of that and have everything implemented in HA. But I don’t want to fill up HA database with garbage date. So if I can filter the raw data before actually storing anything in the database, it would be good.

Edit: There is an option to set the poll intervall in MQTT IO that publish the GPIO status on the HA MQTT broker. This seems to be good option to reduce data. There is no need to check waterlevel 10times/s…

It would need to be YAML, unless you can edit the device sending the discovery message to include a delay_on and/or delay_off.