RF 433Mhz Door sensor with on and off codes

Hi
I am trying to setup a sensor to see the state of a door whether it is opened or closed. I am using 433Mhz RF sensors with on and off code.
I have already receiving two unique codes through RPi RF Receiver.
My question is how I can setup a sensor to show the state of the door lock. I use binary sensor but it only allow me to use one code either on or off.
Since RF receiver keep receiving codes from other devices, the hassio sensor must change its state when the code received from door sensor and not other sensors.
Thant mean once state has change to on, the sensor has to hold to state of sensor until off code receive.
Can anyone help on this.
regards
Udaya

Use a template sensor.

Thanks juan11perez,
Below is my config.
sensors:
front_doorlock:
friendly_name: “Front Doorlock”
value_template: >-
{% if is_state(‘rf.sensor’, ‘113210’) %}
Door unlocked
{% elif is_state(‘rf.sensor’, ‘113205’) %}
Door locked
{% else %}
{% endif %}

This is working but the issue is sensor could not hold the state until next code from door sensor. Because rf.sensor receiving codes from other sensors meantime. Do you have any idea how I can ignore the other codes and only response to the code from door sensor and hold the state.

something like this
IF rf.sensor.state = 113210
THEN door unlocked
ELSE IF rf.sensor.state = 113205
THEN door locked
ELSE hold the previous state
END IF

sorry, dont follow. Whatever is the last code received, that’s the state the sensor will show.

thanks, any idea to fix this

You need to add in your else section the current state of the sensor, so that if neither of the sensor values is detected, the current state is maintained.

I don’t have the syntax at the moment, but that’s the principal.

Edit: I think

{% else %}
   {{ states("front_doorlock") }}
{% endif %}

Thanks. good hint. I will try

Out of interest, what sensors do you use ?

https://www.gearbest.com/access-control/pp_593451.html

1 Like

Thank you @udayaw!

  front_doorlock:
    friendly_name: "Front Doorlock"
    value_template: >-
      {%- if is_state('sensor.rf_receiver.state', '13527306') -%}
        Door Unlocked
      {%- elif is_state('sensor.rf_receiver.state', '13527310') -%}
        Door Locked
      {%- else -%}
        {{ is_state('sensor.front_doorlock') }}
      {%- endif %}

Above code not generating an error. However, no value shows on the sensor. What I am missing??

should be

states('sensor.front_doorlock')

Thanks. still no luck. sensor state is still unknown.

I found the way to do it.

https://community.home-assistant.io/t/broadlink-s1c-kit-sensors-in-ha-using-python-and-mqtt/19886/108

I hope it is not too late to ask. I would like to add more door sensor to my ha. Is this wirelss door magnetic strip for goldgen security gs works and can add in to ha? Is the communication between the door status and ha is by using mqtt follows from your latest post?

I do have broadlink rm pro and broadlink s1c / I found that broadlink door sensor from broadlink itself is x2 price from the door sensor you posted.

1 Like

The communication is 433 mhz codes, you need a decoder to convert codes to mqtt for homeassistant actions.

Don’t forget these sensors also report dead battery, and tamper codes.
You should template all 4 modes.

From a customer review on banggood

Has 4 functions: 2018-09-08 05:08:16
This sensor has 4 functions as described in the offer: - Activate and - Deactivate (others often do not provide this) via the internal reed relay - Anti-tamper switch function via an extra switch on the rear side. - Low voltage alert function (try it with a weak battery). All those 4 states are transmitted by separate codes which are different in the last hexnumber: close: “E”, Open: “A”, Battery: “6”, Tamper: “7” Works for example with RF-Link and Sonoff RF Bridge. Don’t know how long the AAA Battery lasts, but they are easy to replace.

FYI, in order for the tamper function to work you need to add a switch inside on the cheap ones they are selling now. The PWB has a place for the switch, but it’s not there. You could however use that missing switch to be an input from something else, so that is cool. Close that circuit, or open it, not sure, and you will I’m sure get a code 7.

Hi

I got this sensor https://goo.gl/7giu6R but I am confused.

The codes I am seeing in this post are in format:
12345678 (short numeral).

But my codes read by my Broadlink RM pro is like:
“shE0ABAAAcsRLBEsLg8RLS0PESwvDy8QLg8RLRAtESwRLBEsESwuEBEsEC0RLBEsLg8SLC4PES0AAAAA”

RM Pro can read different codes (open/close) but even stranger I get different codes for the same state (ex. open). Not very different, just a couple of letters /numbers.
The beginning of the code doesn’t change , for open is always starts with “sh
”

Anyone has any idea if it is normal?

Try this code:

  • platform: mqtt
    name: “Front door”
    payload_on: “xxx on code xxx”
    payload_off: “xxx off code xxx”
    device_class: door
    state_topic: “tele/sonoff_bridge/RESULT”
    value_template: ‘{{ value_json.RfReceived.Data }}’