How to listen to homeassistant.components.rflink events?

Hi All,

I’m trying to find a workaround for the issue with rflink component.
I have an RF opening sensor that sends 'eurodomest_278429_01', 'command': 'on' or 'ev1527_087bd6_0e', 'command': 'on' when I open the door, and 'eurodomest_278429_00', 'command': 'off' or 'ev1527_087bd6_07', 'command': 'on' when I close it.
I created 4 switches to represent these in HA.

Ideally I want to have a switch that reflects the state of my door based on that mess because I need only one source of information, not 4.
I created an input_boolean and turn it on or off using automation on state change of these 4 switches.

The problem is rflink component changes state of corresponding switches automatically, but it is not enough because if the switch is already on and rflink receives another on command, my automation won’t work because there is no change of state (on->on). Same goes to situation with off->off.

So I hope that it is possible to listen to these rflink events and then change state of my input_boolean.
How can I do that?
Or any other ideas how to resolve my issue?

p.s I have a working solution, but it stops working properly if you open/close door within 1 second interval, that’s why I’m keep looking for a better one.

You need to use the event_type: signal_received trigger. Below is an extract from my doorbell automation from an RFXTRX Doorbell

- alias: Doorbell Notification
  trigger:
    - platform: event
      event_type: signal_received
      event_data:
        entity_id: sensor.doorbell_sound

thanks for your help.
unfortunately, it seems like event_type is different in rflink case.
In debug log I can see messages like:
2018-04-06 01:02:10 DEBUG (MainThread) [homeassistant.components.rflink] event of type command: {‘id’: ‘eurodomest_278429_04’, ‘command’: ‘on’}
2018-04-06 01:02:10 DEBUG (MainThread) [homeassistant.components.rflink] passing event to [<Entity 1st floor window tampered detector: off>]

but even if I change event_type to command and replace event_data with id, it does bot trigger anything… :frowning:

Sorry. I’m reading your original post and I’m getting a bit confused…
How many physical sensors do you actually have?
I’m guessing you want to catch their signal and have them displayed in HA.
If you have a single physical sensor, are you trying to say it sends a different message each time you open the door?
Can you share the code that you already have?

Currently I’m trying to set up one Kerui D026 door sensor.

Exactly it sends randomly one of the following two:
‘eurodomest_278429_01’, ‘command’: ‘on’
‘ev1527_087bd6_0e’, ‘command’: ‘on’

But opening is not a problem as I can define eurodomest_278429_01 as an rflink switch and ev1527_087bd6_0e ad its alias.

The problem is closing event because it’s impossible to alias these two as their states are completely opposite :
‘eurodomest_278429_00’, ‘command’: ‘off’
‘ev1527_087bd6_07’, ‘command’: ‘on’

And the event just does not reach my automation if the command and the corresponding switch’s states are the same

That’s basically the root of the problem. Here is the code to overcome it:
configuration.yaml

input_boolean:

1st_floor_window_detector:
name: “1st floor window detector”
initial: off
icon: mdi:door

switches.yaml

- platform: rflink
devices:
  ev1527_087bd6_0e:
    aliases: eurodomest_278429_01
    name: "1st floor window opened detector"
  ev1527_087bd6_07:
    name: "1st floor window closed detector 1"
  eurodomest_278429_00:
    name: "1st floor window closed detector 2"
  ev1527_087bd6_0b:
    aliases: eurodomest_278429_04
    name: "1st floor window tampered detector"

automations.yaml

- id: set_up_rf_detectors

alias: “[int] set up RF detectors”
hide_entity: true
trigger:
platform: homeassistant
event: start
action:

  • service: switch.turn_on
    entity_id: switch.1st_floor_window_closed_detector_2

    KERIU door detector

  • id: 1st_floor_window_opened_detector__off
    alias: “[int] 1st_floor_window_opened_detector__off”
    hide_entity: true
    trigger:

    • platform: state
      entity_id: switch.1st_floor_window_opened_detector
      to: ‘on’
      action:
      • service: input_boolean.turn_on
        entity_id: input_boolean.1st_floor_window_detector
      • delay: 00:00:01
      • service: switch.turn_off
        data_template:
        entity_id: ‘{{ trigger.entity_id }}’
  • id: 1st_floor_window_closed_detector_1__off
    alias: “[int] 1st_floor_window_closed_detector_1__off”
    hide_entity: true
    trigger:

    • platform: state
      entity_id: switch.1st_floor_window_closed_detector_1
      to: ‘on’
      action:
      • service: input_boolean.turn_off
        entity_id: input_boolean.1st_floor_window_detector
      • delay: 00:00:01
      • service: switch.turn_off
        data_template:
        entity_id: ‘{{ trigger.entity_id }}’
  • id: 1st_floor_window_closed_detector_2__on
    alias: “[int] 1st_floor_window_closed_detector_2__on”
    hide_entity: true
    trigger:

    • platform: state
      entity_id: switch.1st_floor_window_closed_detector_2
      to: ‘off’
      action:
      • service: input_boolean.turn_off
        entity_id: input_boolean.1st_floor_window_detector
      • delay: 00:00:01
      • service: switch.turn_on
        data_template:
        entity_id: ‘{{ trigger.entity_id }}’
  • id: 1st_floor_window_tampered_detector__off
    alias: “[int] 1st_floor_window_tampered_detector__off”
    hide_entity: true
    trigger:
    platform: state
    entity_id: switch.1st_floor_window_tampered_detector
    to: ‘on’
    action:

    • delay: 00:00:01
    • service: switch.turn_off
      data_template:
      entity_id: ‘{{ trigger.entity_id }}’

As you can see, it requires plenty of effort to make one sensor to work properly.
I have to mention that without those 1s delays the automation would work strangely or even fail to work because when in response to an event from my sensor I immediately change state of its HA representative switch back (I need to do that otherwise I would not receive any further state changes), rflink component sends a comment back to the sensor and immediately receives (a copy of?) the original event, which turns the HA switch back etc… But if I add a little delay, it works as expected.
And this solution has has a flaw - if one opens and closes the door within that delay, the right state of those 3 HA switches becomes inconsistent and would not reflect the actual state anymore. I can add another automation to call that set_up_rf_detectors once a hour or whatever, but it’s still far from ideal.
That’s why I wanted to receive original events and handle my input_boolean.1st_floor_window_detector appropriately.

Hope it explains something.

Thanks.
For starters it looks like the Kerui isn’t being correctly decoded, check this thread
Also looks like there are actually 2 sensors in the D026: open/close and tamper.
Anyhow, since you managed to do most of the work, we’re almost there with what you’ve done, until a fix is provided.
This is what I would do for now:

  1. I wouldn’t list the sensors as switch, they should be binary_sensor (https://www.home-assistant.io/components/binary_sensor.rfxtrx/)
  2. Keep the aliases to combine both opened sensors into a single one.
  3. For the sensors where you get both on and off commands, keep both as separate sensors
  4. create a template sensor that will read from both these sensor to return a single state:
binary_sensor:
  - platform: template
    sensors:
      window_closed:
        value_template: >
        {{ states.binary_sensor.1st_floor_window_closed_detector_2.state == 'off' or states.binary_sensor.1st_floor_window_closed_detector_1.state == 'on' }}

5.Create a final binary_sensor template to take care of it all:

  - platform: template
    sensors:
      1st_floor_window:
        friendly_name: "1st Floor Window Sensor"
        device_class: window
        value_template: >
          {% if states.binary_sensor.1st_floor_window_closed_detector_2.state == 'off' or states.binary_sensor.1st_floor_window_closed_detector_1.state == 'on' %}off{% elseif states.binary_sensor.1st_floor_window_closed_detector.state == 'on' %}on{% endif %}

You don’t need to display these additional sensors, just display that last one
That should make it easier to do your automations now.
Think the code indentation is correct, I’ve not tested in my setup, but bear this in mind if you get errors

looked into rflink.py and finally got the answer.
first of all, you need to configure the switch to fire events like this
- platform: rflink
devices:
eurodomest_278429_01:
aliases: ev1527_087bd6_0e
name: “1st floor window opened detector”
fire_event: true

then you need to add the following automation:
- id: catch_rflink_event
hide_entity: true
trigger:
- platform: event
event_type: button_pressed
event_data:
entity_id: switch.1st_floor_window_opened_detector
action:

I’m currently in the process of merging three separate automations into one with conditional service_template, it does not let me do the following (errors or doesn’t work):
- id: catch_1st_floor_window_detectors_event
hide_entity: true
trigger:
- platform: event
event_type: button_pressed
event_data:
entity_id: switch.1st_floor_window_opened_detector
- platform: event
event_type: button_pressed
event_data:
entity_id: switch.1st_floor_window_closed_detector_1
- platform: event
event_type: button_pressed
event_data:
entity_id: switch.1st_floor_window_closed_detector_2
action:
service_template: >
{% if {{ trigger.event.data[‘entity_id’] == ‘switch.1st_floor_window_opened_detector’ }} %}
input_boolean.turn_on
{% else %}
input_boolean.turn_off
{% endif %}
entity_id: input_boolean.1st_floor_window_detector

Update: almost there, just a couple of niggles to resolve, anyone? :wink:

2 Likes

I received a couple of the KERUI D026 sensors in today’s mail.
They work with the Sonoff RF bridge. I see 3 separate Data strings being transmitted and I expect to see a 4th one on low battery - I’ll hook one up to my variable power supply later and check it out.

My initial testing is with node-red - simply an MQTT input node connected to a debug output, the MQTT node is subscribed to +/sonoffbr/+ to monitor all the bridge traffic.

The JSON object from the bridge shows 3 different data strings. 1 for tamper, 1 for magnet close (closed) and a third for magnet away (open) these are consistent for each action.

What firmware do you use? I used RF bridge with Espurna, but it was unstable so I switched to Arduino Mega/RFLink connected to RPi via USB to avoid potential connection issues.

I didn’t see anything like that, only 3 states. Oh well…

Please let me know when you have some results.

I’m pretty happy with my current setup, will see how it goes.
Will publish my final config later.

On the Sonoff RF bridge? Tasmota.

The low battery state was sent once when I dropped the power supply voltage to 4.97V.

that’s great news. need to try it as well to set up mine properly
but is it still capable to send an open/close signal when its battery level is say, 5V?

I’ve got a Kerui D026 sensor and want to connect it to home assistant. I can read the rf code from the D026 using rpi_rf on my home assistant pi with a heterodyne antenna. How do I set-up HA to use this code to tell me when the door is open, closed, tampered with, or low on battery? Thanks!

Provided your ha can communicate with it, what I normally do is enable discovery, get the sensor to send data (open close door) and the sensor normally shows up. Then I get the code from the discovery and manually add it in my config

If you have set automatic_add: false, you can also set rflink logger to info to view the events. This can be done without restarting, from services view, calling to logger.set_level with Service Data like:

{
    "rflink": "info",
    "homeassistant.components.sensor.rflink":"debug",
    "homeassistant.components.rflink":"info",
}

You will see traces like:

device_id xiron_4001_bat not known and automatic add disabled: %s'
1 Like

Hi, I set up my Kerui D026 door sensor following this thread and it worked perfect at the first time: Binary sensor base on state of other binary sensors - 433mhz Rflink

When sniffing the sensor signals with Rflink, I could see the sensor uses protocol ev1527 although HA Rflink logger could see Eurodomest protocol.
I set up everything (ON, OFF; Battery with ev1527)

All credits go to typhoon72

what does that mean? could you post your config?

Here is my config as entered in binary_sensors.yaml :

  • 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

  • platform: rflink
    devices:
    ev1527_01e76a_0b:
    name: batterie porte salon
    device_class: battery

Again, all credits go to typhoon72.