Automation help: Notify mobiles at certain time if a door sensor changes states on that day

We’ve got a basement door that we sometimes forget to lock up. I’ve searched far and wide and the consensus seems to be that there is no sensor (except some homebrewed magnetic strips or smart door locks which I don’t want) that can easily detect if a door is actually locked instead of simple closed shut.

So I want to create the following simple automation:
IF the basement door sensor has changed state from closed to open at any time in on that day, send mobile notification at 21:00 to mobile phones saying “Basement door has been opened today. Check if it has been actually locked!”

The “if sensor changed from closed->open, send notification” part is easy, I’m trying to figure out how to delay the message to a certain time and check for this state change in certain periods (so not just in the last 24 hours, but from 00:00 to 24:00 of any given day)

Did you ever find a solution for this? I have a very similar situation - I want a notification at a certain time if any of a few doors opened throughout the day.

I can think of a few clunky solutions for this - possibly a helper that gets turned on whenever the door opens, and then the notification automation turns it back off at the end of the day. Or maybe a counter so I know how many times it was opened. Or maybe a SQL query to check state history. But I’ve not found a simple clean solution so far.

I’ve asked around and that’s essentially exactly how I solved it: created a boolean helper “BasementDoorOpenedToday” and 3 automations: first one sets this helper to ON when the sensor’s state changes to open, second one reset this helper to OFF in the night, and third sends checks in the evening if the boolean helper is ON, if yes then sends a reminder notification to mobile phones to check the basement door as it has been opened today

Seems to be working quite stable so far

1 Like

I ended up building the following automation, which is very similar to your approach and I’m reasonably happy with it. The notification template could be improved a bit, but it gets the message across. I created an input counter for each of the 3 doors I’m tracking. By using choose: in combination with trigger ids I was able to do everything in a single automation.

alias: Alert - Doors Opened Today
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.office_door_contact
    from: "off"
    to: "on"
    id: officedooropen
  - platform: state
    entity_id:
      - binary_sensor.dining_room_door_1_contact
    from: "off"
    to: "on"
    id: dining1open
  - platform: state
    entity_id:
      - binary_sensor.dining_room_door_2_contact
    from: "off"
    to: "on"
    id: dining2open
  - platform: time
    at: "21:00:00"
    id: notifyat9
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: officedooropen
        sequence:
          - service: counter.increment
            data: {}
            target:
              entity_id: counter.office_door_counter
      - conditions:
          - condition: trigger
            id: dining1open
        sequence:
          - service: counter.increment
            data: {}
            target:
              entity_id: counter.dining_door_1_counter
      - conditions:
          - condition: trigger
            id: dining2open
        sequence:
          - service: counter.increment
            data: {}
            target:
              entity_id: counter.dining_door_2_counter
      - conditions:
          - condition: trigger
            id: notifyat9
          - condition: or
            conditions:
              - condition: numeric_state
                entity_id: counter.dining_door_1_counter
                above: 0
              - condition: numeric_state
                entity_id: counter.dining_door_2_counter
                above: 0
              - condition: numeric_state
                entity_id: counter.office_door_counter
                above: 0
        sequence:
          - service: notify.all_phones
            data:
              message: >-
                Doors opened today:  {{
                iif(states('counter.office_door_counter')|int(0)>0,'Office
                x'+states('counter.office_door_counter')|string,'') }} {{
                iif(states('counter.dining_door_1_counter')|int(0)>0,'Dining1
                x'+states('counter.office_door_counter')|string,'') }} {{
                iif(states('counter.dining_door_2_counter')|int(0)>0,'Dining2
                x'+states('counter.office_door_counter')|string,'') }}
              data:
                channel: Alerts
                group: Alerts
          - service: counter.reset
            data: {}
            target:
              entity_id:
                - counter.dining_door_1_counter
                - counter.dining_door_2_counter
                - counter.office_door_counter
mode: single
1 Like