Binary sensor base on state of other binary sensors - 433mhz Rflink

Hi,
Long time HA user, but first time I’ve needed to make a call for help, having exhausted my search capabilities in the forum!. Recently purchased some gs-wds07 sensors (433mhz with Open and Closed state).
I’ve added these into HA as separate binary sensors, then I’m trying to use another binary sensor to determine the overall state (Open or Closed).

Whilst both the Rear Door Open and Rear Door Closed binary sensors update their state correctly when the door sensor is activated, the overall Rear Door Status binary sensor never changes from ‘off’.

The config I’m using for this is below. Is there something obvious that I’m not getting right?

binary_sensor:
  - platform: rflink
    devices:
      rear_door_open:
        name: Rear door open
        off_delay: 1
        aliases:
          - ev1527_05af90_0a
          - selectplus_0506f5_02
      rear_door_closed:
        name: Rear door closed
        off_delay: 1
        aliases:
          - ev1527_05af90_0e
          - selectplus_0506f1_02
  - platform: template
    sensors:
      rear_door:
        friendly_name: Rear door status
        entity_id:
          - binary_sensor.rear_door_open
          - binary_sensor.rear_door_closed
        value_template: >-
          {% if is_state('binary_sensor.rear_door_open', 'on') %}
          on
          {% elif is_state('binary_sensor.rear_door_closed', 'on') %}
          off
          {% endif %}

Thanks!

A bit more trial and error, and I’ve made some changes as below. Mainly changing the value_template to true/false where it was previously on/off.

Now the Rear Door Status sensor reacts to actions from the Open and Closed sensors. However this works fine when I open the door, and when I close it. However on closing it the 'Rear door open` sensor stays on - thus subsequent open and close actions don’t update the Rear Door Status. I’m guessing I need an action to force the ‘Rear Door Open’ to off when ‘Rear Door Closed’ is on. Can this be actioned from within the template sensor?

binary_sensor:
  - platform: rflink
    devices:
      rear_door_open:
        name: Rear door open
        aliases:
          - ev1527_05af90_0a
          - selectplus_0506f5_02
      rear_door_closed:
        name: Rear door closed
        aliases:
          - ev1527_05af90_0e
          - selectplus_0506f1_02
  - platform: template
    sensors:
      rear_door:
        friendly_name: Rear door status
        value_template: >-
          {% if is_state("binary_sensor.rear_door_closed", "on") %}
          false
          {% elif is_state("binary_sensor.rear_door_open", "on") %}
          true
          {% endif %}
        device_class: door

Thanks again :smiley:

Sorted, I got there in the end! :smiley:

For anyone else having the same issues as me, I hope this will be of some help. Adding an off_delay to ‘reset’ the Open and Closed sensors after 1 second, and a further ‘else’ in the value_template to pick up the current state of the overall Rear Door Status has resolved the issue for me.

  - platform: rflink
    devices:
      rear_door_open:
        name: Rear door open
        off_delay: 1
        aliases:
          - ev1527_05af90_0a
          - selectplus_0506f5_02
      rear_door_closed:
        name: Rear door closed
        off_delay: 1
        aliases:
          - ev1527_05af90_0e
          - selectplus_0506f1_02
  - platform: template
    sensors:
      rear_door:
        friendly_name: Rear door status
        value_template: >-
          {% if is_state("binary_sensor.rear_door_open", "on") %}
            true
          {% elif is_state("binary_sensor.rear_door_closed", "on") %}
            false
          {% else %}
            {{ is_state("binary_sensor.rear_door") }}
          {% endif %}
        device_class: door

@ typhoon72
Thank you so much for self-solving ad sharing :smiley:

Works perfect for me and my Kerui D026 door/window sensor.

I have to say that my sensors (of the same type) work well with OMG RF or Pilight.
The only downside so far the battery status is always ok

This worked for me, I was using other names for the sensor but the template sensor wasn’t working. So I just copied your code without changing anything but the sensor aliases and it is working fine. Probably I had some typo… For now my sensor will be called “rear_door” also!

Hi, since update 0.115 my template sensor is no longer working : it sticks to the previous state (open or closed) although the binary sensors are working fine (door open or closed) and I can manually update the template state.

Is anyone experiencing the same issue ?

There was a breaking change in 0.115.x regarding template sensors. Maybe if you show your template ?

Hi Francis,

here is my setup for sensors and template in my binary_sensors.yaml file:

 - platform: rflink
   devices:
     porte_salon_ouverte:
       name: Porte Salon ouverte
       off_delay: 1
       aliases:
         - ev1527_01e76a_0e
     porte_salon_fermee:
       name: Porte Salon fermée
       off_delay: 1
       aliases:
         - ev1527_01e76a_07
 - platform: template
   sensors:
     porte_salon:
       friendly_name: Statut porte Salon
       value_template: >-
         {% if is_state("binary_sensor.porte_salon_ouverte", "on") %}
           true
         {% elif is_state("binary_sensor.porte_salon_fermee", "on") %}
           false
         {% else %}
           {{ is_state("binary_sensor.rear_door") }}
         {% endif %}
       device_class: door

I went through the release notes several times without really getting how templates were affected in my case. Template is one of my (multiple) weak points :sweat_smile:

I’m also having issues with my template sensors since upgrade, my config is similar to yours. Sensor shows as unavailable.

@euchti When you modified the original template, you forgot to edit the else clause.

Little bit late to the discussion here, however I recently upgraded my version of Home Assistant and also faced the same issue. Tried a few different things but in the end I ‘fixed’ it using node-red, which tbh I’ve been migrating a lot of my more complex automations into over the past few months.

I replaced the template sensor with this

- platform: mqtt
  name: Front door
  state_topic: "homeassistant/external_sensors/front_door_status"
  device_class: door

Then in node-red simply send an ‘ON’ or ‘OFF’ payload to the MQTT topic based when the respective door_open or door_closed sensor triggers on.

image

image

image

image

I managed to fix your previous config. It works for me :slight_smile:

 - platform: template
   sensors:
     porte_salon:
       friendly_name: Statut porte Salon
       value_template: >-
         {% if is_state("binary_sensor.porte_salon_ouverte", "on") %}
           true
         {% elif is_state("binary_sensor.porte_salon_fermee", "on") %}
           false
         {% else %}
           {{ is_state("binary_sensor.rear_door", "on") }}
         {% endif %}
       device_class: door