Door sensor - dashboard information, that the door was open even it´s already closed

Hi all,
using the door sensor I would need to know, that the door was opened during the day even for few seconds.
The idea is, that if someone opens the door during the day, it will be shown on the dashboard as the RED TEXT " Door was opened". This information has to stay there until I personally check it.

Then, if possible, if I can click on the icon and reset the status, so the door sensor will be shown in GREEN TEXT door are closed.

I am using these if states for other conditions, but I just need that the information ,that the door was opened will stay there and not return to it´s closed state as someone closes the door.

Entity status

{% if is_state('binary_sensor.senzor_okno_maly_pokoj_iaszone', 'on') %} Door open {% else %} Door closed {% endif %}

Icon color

{% if is_state('binary_sensor.senzor_okno_maly_pokoj_iaszone', 'on') %} red {% else %} green {% endif %}

The following Trigger-based Template Binary Sensor will report on only when the binary_sensor (door) changes to on.

template:
  - trigger:
      - id: 'on'
        platform: state
        entity_id: binary_sensor.senzor_okno_maly_pokoj_iaszone
        from: 'off'
        to: 'on'
      - id: 'off'
        platform: event
        event_type: reset_door_monitor
    sensor:
      - name: Door Monitor 
        state: "{{ trigger.id == 'on' }}"
        attributes:
          last_opened: >
            {{ now().timestamp() | timestamp_custom if trigger.id == 'on' else this.attributes.last_opened | default(as_datetime(0), true) }}

To set it back to off, you have to send an event named reset_door_monitor using the following service call (in a script or button or whatever way you want to reset it).

- event: reset_door_monitor

Note

Initially, this entity’s state will be unknown. Just open the door and it will report a proper state.

1 Like

Hello Taras,
thanks very much for your fast reply.
Unfortunately there is something wrong on my side and it´s not working properly (even if I open the door).
Please see the screenshots from template and config yaml.

Anything wrong that I am doing?


Change this:

        state: "{{ trigger.id }}"

to this:

        state: "{{ trigger.id == 'on' }}"

Where have you put the example? If you have put it into a file called templates.yaml then you should remove the first line from the example, the one containing the key word template:

1 Like

Well it´s working fine now, shows me, that the door was open and the info stays there.
But I am unable to reset the event.
It´s not showimg me the option the the developer tools (service calls):

PLEASE use code tags to post your code. Screenshots greatly reduce the number of people willing to look at your problem.

Since I can’t read from your images, I’ll simply tell you how I did this for an outside door that should hardly ever be used. If the door is opened I set a helper entity, and the dashboard shows the state of that entity- not the door.

It’s not an actual service call so you can’t enter it into Developer Tools > Services (but it can be used in scripts and automations, as shown above).

To test it, go to Developer Tools > Events.

1 Like

Yep, that is working fine.
But how do I assign this event to a button press (mouse click on a button) to reset the status?

GOT IT - made a script a firing this script via the button :slight_smile:

Thanks very much for your help Taras!!!

1 Like