Binary sensor template delay off when the state is "Not equal to"

I have a RF motion sensor that sends the code “13679510” when motion is detected.
How can I set a binary sensor template to be ON every time the sensor sends the code and go off if after 10 seconds I do not receive that code?
I tried this, but it’s always on:

binary_sensor:
  - platform: template
    sensors:
      motion_sensor_rf_1:
        friendly_name: "Motion Sensor RF 1"
        delay_off:
          seconds: 10
        value_template: >-
          {{ states('sensor.rf_receiver') != '13679510' }}

or

          {{ states('sensor.rf_receiver') != 13679510}}

or

          {{ states('sensor.rf_receiver')|int != 13679510}}

“sensor.rf_receiver” is a MQTT sensor containing the RF code received.

Hi,

I’m not sure if I understand this correctly (from the docs):

delay_off
(time)(Optional)The amount of time the template state must be not met before this sensor will switch to off.

What happen if you change the “!=” to “==” ?

hello there @PetrolHead, actually it wouldn’t work I guess.
That’s because the RF receiver keeps receiving random number/codes on the 433 Mhz frequency.
Only when I receive that code it means that some motion has been detected, so the binary sensor goes “ON”.
If i remove the delay off, after 1 second or 2 I will receive some different other code that will trigger the binary sensor “OFF”, but I don’t want it to go off for at least 10 seconds. If in those 10 seconds I receive the “Motion Detected” code again, the binary code remains “ON” for other 10 seconds.
I’ll try to change the != with == just for test purpouse anyway :wink:

At the moment I am using a timer but the binary sensor template used in that way would be perfect if you have many RF Motion Sensor in the house, so you have not to use a timer for every single one

ok. obviously it goes ON if I use == but it’s not the way I want it to work… :slight_smile:

oh, ok, I misunderstood the example in the documentation:

binary_sensor:
  - platform: template
    sensors:
      washing_machine:
        friendly_name: "Washing Machine"
        delay_off:
          minutes: 5
        value_template: >-
          {{ states('sensor.washing_machine_power')|float > 0 }}

I thought that the “value_template: >-…” was the condition to be off… stupid me…

It’s a variant of “Double Negative” in the documentation, i think, makes it difficult to understand.

1 Like