Virtual binary_sensor that is solely updated from automation?

Hi,

I’m trying to use the codes sent from esphome Sonoff RF Bridge in HA.

I would like to create a binary_sensor for each RF device, with the update method through automation when receiving events. The problem is that I have not found any binary_sensor platform that will allow me that.
I have seen examples with mqtt, but I don’t want to use it.

Any pointers? does this kind of “virtual” binary_sensor platform exist? Is there another way? Should I write a custom component?

Thank you,
Skippy

this maybe?

1 Like

I’ve seen it, but I cannot figure out how to configure it.
I get an event:
‘{
“event_type”: “esphome.rf_code_received”,
“data”: {
“sync”: “30fc”,
“low”: “1b8”,
“high”: “4ce”,
“code”: “xxxxxx”
},
“origin”: “LOCAL”,
“time_fired”: “2020-08-12T08:10:20.222480+00:00”,
“context”: {
“id”: “42cd82ec99bf428f9af48ec3929b6e73”,
“parent_id”: null,
“user_id”: null
}
}’
How would the configuration look like?

Thank you,
Skippy

is there any entity reporting that data in its state?

if not, you can create an input boolean and update value of the boolean by automation.

Thank you for the suggestion.
So, just to make it clear for myself:

  • Create an input_boolean entities for each RF sensor
  • Update the state of the entities from automation
  • I create a binary_sensor with platform template that is updated when the input_boolean is changing state

you said RF sensor, as I said if there is a sensor already reporting the code, you can use template binary sensor to create your binary sensors and skipping step 1-2.

if this is not an option I can’t think anything other way (except node-red), maybe others may suggest something else… good luck!

Ideally, there would be an Event Binary Sensor. You would configure it to listen for events to set its state to on or off. However, it does not exist. What does exist is the MQTT Binary Sensor which can be configured to subscribe to a topic whose payloads set its state to on or off (but you’ve stated you don’t want to use MQTT).

The simplest option is to do what you described:

However, this approach requires the combination of a Input Boolean and a Template Binary Sensor whereas the same result can be achieved with just an MQTT Binary Sensor (i.e. half the quantity of entities if you were to use MQTT). It’s something to consider if you have many sensors to configure.

Should you change your mind about using MQTT, I suggest you consider employing Strategy 2 in this post.

I got to the point where input_boolean works correctly from automation.

Still not working as binary_sensor

binary_sensor:
  - platform: template
    sensors:
      frontdoor_pir:
        friendly_name: "Front Door PIR"
        device_class: motion
        value_template: >-
          {{ is_state('input_boolean.ffffff', True) }}
      spare_pir:
        friendly_name: "Spare PIR"
        device_class: motion
        value_template: >-
          {{ is_state('input_boolean.eeeeee', True) }}

Any ideas on how the template should be?

binary_sensor:
  - platform: template
    sensors:
      frontdoor_pir:
        friendly_name: "Front Door PIR"
        device_class: motion
        value_template: >-
          {{ is_state('input_boolean.ffffff', 'on') }}
      spare_pir:
        friendly_name: "Spare PIR"
        device_class: motion
        value_template: >-
          {{ is_state('input_boolean.eeeeee', 'on') }}

That worked.
Thank you Taras and Serkank

I post the final config here just for everyone else that is using Sonoff RF Bridge with esphome:
configuration.yaml

input_boolean:
  xxxxxx:
    name: Spare Motion Input
    initial: False


binary_sensor:
  - platform: template
    sensors:
      spare_pir:
        friendly_name: "Spare PIR"
        entity_id: input_boolean.xxxxxx
        device_class: motion
        value_template:  "{{ is_state('input_boolean.xxxxxx', 'on') }}"

where xxxxxx is your sensor code received through esphome.rc_code.received event. The event is processed through the following automation (please note that my motion sensor sends only motion on event, not on and off separately as different codes).

automations.yaml

- id: '1597144798301'
  alias: spare input motion
  trigger:
    event_type: esphome.rf_code_received
    platform: event
  condition:
  - condition: template
    value_template: '{{ trigger.event.data.code == ''xxxxxx'' }}'
  action:
  - entity_id: input_boolean.xxxxxx
    service: input_boolean.turn_on
  - delay:
      seconds: 20
  - entity_id: input_boolean.xxxxxx
    service: input_boolean.turn_off
  mode: single

So for each RF sensor connected to the RF bridge one needs:

  • one input_boolean entity
  • one binary_sensor template entity, and
  • one automation.

Actually, it’s possible to have just one automation to handle multiple input booleans.