Binary sensor false trigger

Got strange automation behaviour

I have a “GSM modem” project. Simple SIM800l connected to ESM12 and powered by 18650 battery, which is charging if USB connected to charging board
I just include DC detect sensor, to get state of USB connected to charger or not
ESP12 connected to HA with ESPHome

Here is my yaml

  - platform: template
    sensors:
      gsm_power_on:
        friendly_name: "GSM External Power"
        value_template: "{{ states('sensor.gsm_external_power')|float > 0.00 }}" 

While USB plugged it, value of that sensor always above 0V
2020-02-03_23-08-49

However, that binary sensor jumps from true to false, time after time
2020-02-03_23-10-56

Why is that could happen?

First, your sensor is a regular sensor, not a binary_sensor. You might consider making it an actual binary_sensor.

Second, I suspect what is happening is that the state of sensor.gsm_external_power is sometimes, for probably a very short time, not a numeric value. E.g., maybe it is sometimes unavailable or unknown. In that case the |float filter will output its default value, which is 0.0, and then the template will result in False.

Hm… If you talking about ADC sensor.gsm_external_power, then yes, its regular one. But if you look at the second screenshot, you’ll see another “virtual” sensor.gsm_power_on, with True and False states, and it’s actually binary.
I think same display name confused you :slight_smile: Sorry about that

Good point. Coz I have a second automation for sensor.gsm_power_on = False, and it’s triggered as it should, only if I unplug external power.
Will check it, and apply some workaround

No, it’s not a Template Binary Sensor, it’s a “regular” Template Sensor. It just happens to have two states.

Ok, now I got your point. Yes, in terms of HA it’s a template sensor not a binary_sensor, you are right.
But I never told that is binary_sensor :slight_smile:

If you change to a proper binary sensor you can add delay_on or delay_off with a small value to help compensate for these fluctuations.

I have a pool pump that does the same and a delay_off set to 30 seconds cleaned it up.

1 Like

Thanks, will definitely apply that!
I changed that sensor to a true binary already, thanks Phil to point on that :slight_smile:

Btw
Today I unplugged external power, so SIM800l stay powered with battery (directly attached), but charger module decide “there is no power consumption” and switched off, so ESP module been disabled, and in HA all sensors became unavailable, automation did not triggered…
Hm… need to think about how to workaround this scenario…

I want to use “GSM modem” as reserve notification channel, in case internet connection failed or power issue happen, when nobody home.