Using a template binary sensor, but how can I ignore short periods of unavailable states in the source sensor?

I have a template binary sensor which is indicating whether my washing machine is running or not. It does this by interpreting the power measured from an energy monitoring plug (TP-link HS110). It looks like this:

template:
 - binary_sensor:
    - name: "Washing Machine"
      device_class: running
      state: "{{ states( 'sensor.energy_monitor_plug_current_consumption' )|float > 1 }}"
      delay_on:
         seconds: 5
      delay_off:
         minutes: 15

The problem is that these plugs are notorious (see here and here) for having issues where they intermittently lose connection and show “unavailable”. In my case the plug seems to lose connection and regain it after about 5 seconds:

This then leads to my template binary sensor also triggering spuriously:

How can I avoid this? Is there a way to say “only allow the washing machine binary template sensor to go to state unavailable if the source sensor (energy plug) has been unavailable for at least 1 minute” ? I basically want to ignore short periods of unavailable states in the source sensor.

Hi teeeeee,

Add an availability check in the sensor. Then it will not post some wild numbers or zeros, it will report a gap in data, Probably the best you can hope for with that hardware.

Without a default value, the float function will cause an error whenever the source goes unavailable… add a default.

template:
 - binary_sensor:
    - name: "Washing Machine"
      device_class: running
      state: "{{ states('sensor.energy_monitor_plug_current_consumption') | float(0) > 1 }}"
      delay_on:
         seconds: 5
      delay_off:
         minutes: 15

Can you guys show a examples?

@Sir_Goodenough I assume you are talking about this setting? As far as I can see, it allows only to set True/False. But I would like the binary sensor to still go unavailable (so I know there is a problem), but to only do it if it’s been unavailable for some time.

yes, that’s true or false that there is data available. If you also add the default, it will show the default at that point when data is not available.
Search in the Docs for template examples or here in the forums.

Is it something like this I’m looking for?

availability: >
        {{ is_number(states('sensor.energy_monitor_plug_current_consumption')) }}

Or this?

availability: >
        {{ has_value(states('sensor.energy_monitor_plug_current_consumption')) }}

Apologies for the seemingly simple question.

Can anyone help with this? Adding a default value for the float didnt help.

Do i need something like the “availability” parameter above?

Thanks