Timestamp and icons when sensor status change

Using the Sonoff RF Bridge with Tasmota I receive the RF code from a doorsensor which is shown in my card. So far so good. For now I use this code in configuration.yaml which shows the received RF code:

# DoorTest
sensor DoorTest:
  - platform: mqtt
    name: 'Door'
    icon: mdi:door-open
    state_topic: "tele/SonoffRF1/RESULT"
    json_attributes_topic: "tele/SonoffRF1/RESULT"
    value_template: '{{value_json.RfReceived.Data}}'

I’m struggling to find a solution how to display the door status: Display an icon for door open (mdi door-open) or door closed (mdi door-closed) with the local time the status has changed.

Would be great if someone can help me!


I don’t have an RF Bridge so can’t test this and don’t know much about it, but try this:

  - platform: mqtt
    name: 'Door'
    device_class: door
    state_topic: "tele/SonoffRF1/RESULT"
    json_attributes_topic: "tele/SonoffRF1/RESULT"
    value_template: "{{value_json.RfReceived.Data == '005B27'}}"

This assumes that you receive the code 005B27 when the door is open, and something else when it is closed.

Thanks for helping Tom! Unfortunattely an error is shown (arrow below ==):

can not read an implicit mapping pair; a colon is missed at line 41, column 65:
… n.RfReceived.Data == ‘005B27’}}’

What about:

value_template: "{{value_json.RfReceived.Data | string == '005B27'}}"

If you have more than one device being monitored by your Sonoff RF Bridge, you’ll want to review this post:

It presents two strategies for receiving the data. The first strategy is adequate if you only have a few devices. It provides two examples:

  • Device that sends codes for both on and off states (door is open/closed).
  • Device that sends code for only the on state (door is open).

Taras, I’m a bit confused by this.
Why would anyone want to know only if a door is open, and not want to know when it’s closed ?
I suppose an armed security system could trigger from the open but how do you reset it if you don’t know the doors/windows are shut ?
Just trying to picture a usage scenario :man_shrugging:

Some battery-operated sensor hardware works like that. In an effort to conserve its battery, it only transmits the “active” state (motion detected, something’s open, etc).

@Tom: Your new code is okay and generates no errors, thanks!

@ Mutt: Please see below, it works with my sensor which sends open AND close :wink:

@ Taras: My Google searches were not perfect so I did not find the page your mentioned. The info on that page is correct and it works, thanks! The code I use now:

# TestTaras
binary_sensor TestTaras:
  - platform: mqtt
    name: 'Bathroom Door'
    state_topic: 'tele/SonoffRF1/RESULT'
    value_template: >-
      {% if value_json.RfReceived.Data == '005B2E' %}
      {% elif value_json.RfReceived.Data == '005B27' %}
      {% else %}
        {{states('binary_sensor.bathroom_door') | upper}}
      {% endif %}
    device_class: Door

As shown in the image below it looks perfect. Now I intend to add a local time timestamp (last status change) so any suggestion is welcome.


Glad you got a solution.
With both Tom and Taras on the case - you were bound to though :wink: