How to set notifications when door is left open?

I have door closed sensor set. It works fine. i need to set notification if door is left open for 2 minutes and if not closed after that it should send notifications each minute (30 seconds would be even better).

I tried setting alert in configuration.yaml like this:

alert:
  main_door:
    name: Main door
    message: Main door is left open
    done_message: Main door is closed
    entity_id: binary_sensor.main_door_contact
    state: on
    repeat: 1
    can_acknowledge: false
    skip_first: true
    notifiers:
      - hass_agent_notifier
      - mobile_app

When conditions are met nothing happens. Not even an error… it behaves like I did not set alert at all.

However, when I set automation it works:

alias: Main door is open
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.main_door_contact
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 1
      seconds: 0
action:
  - service: tts.google_say
    data:
      entity_id: media_player.pc
      message: Main door is open
mode: single

This works bit it is triggered just once. I want it to repeat notifications until door is finally closed.

What am I doing wrong?

So you have services notify.hass_agent_notifier and notify.mobile_app?

Well I am not quite shure. I do have these devices and I can send notifications to them by other means.

I did not get to the point to check this for alert. I would expect if services do not exist HA would complain about that? It seems to me that it does not even trigger alert.

Look in Developer tools → Services

I checked. i have those two notifications and few more. I tried them all but nothing happens.

I also tried using

 notifiers:
      - notify.hass_agent_notifier
      - notify.mobile_app

well, the docs say that won’t work.

You have to strip off the notify. part to use it.

For example this uses notify.garage.

Well that was the first I tried.
As no errors show I guess it does not even come to notification part.

I’d set logger either globally for for just alerts to either info or debug and see what you get.

I’d also check that the alert state changes when the sensor is on. If it doesn’t then that’s where to look more closely.

It seems I am dumb. I could not find how to set logger to log alerts.
Finally, I set logger to debug log everything and then manuallz searched.

I found out that there is homeassistant.components.alert in log that shows each time just to log that value of the watched binary entity is changed. And nothing else. Nothing shows in log even after sensor stays open longer than specified time that should trigger alert.

2023-01-18 01:23:58.056 DEBUG (MainThread) [homeassistant.components.alert] Watched entity (binary_sensor.main_door_contact) has changed

Check this out. It is a similar scenario.

Yes that is similar to automation I did and which works but thing is, I want different time for first notification than for the rest. That is complicated part.

With your help and some fiddling around I got it to the point it works kinda like I wanted. Here it is if someone searches for similar solution.

This is in Automations:

alias: Main door open
description: ""

trigger:

  - platform: state
    entity_id:
      - binary_sensor.main_door_contact
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 2
      seconds: 0

action:

  - repeat:

      sequence:

        - service: notify.mobile_app
          data:
            message: Main door is open!
            data:
              ttl: 0
              priority: high
          enabled: true

        - service: notify.mobile_app
          data:
            message: TTS
            data:
              tts_text: Main door is open!
              ttl: 0
              priority: high
          enabled: true

        - delay:
            minutes: 1
          enabled: true

      until:

        - condition: state
          entity_id: binary_sensor.main_door_contact
          state: "off"

mode: single

2 Likes

Shout out for circling back with the solution. This came in handy today. :+1:

I am a retired long-time programmer but new to Home Assistant. After spending the last week trying to get a front door alert to work, searching the web, and pulling my hair out, I got it to work. I hope this helps other new users.

Using Studio Code server:

Step 1: Add to the configuration.yaml (if not already there)

notify: !include notify.yaml
alert: !include alerts.yaml

Step 2: Create two new files in the “Config” directory (if not already there)

notify.yaml
alert.yaml

Step 3: in the alert.yaml add

front_door:
    name: "Alert Front Door"
    message: |
      "Front door has been {{states.lock.touchpad_electronic_deadbolt.state}} 
      for {{ relative_time(states.lock.touchpad_electronic_deadbolt.last_changed) }}"
    done_message: |
      "Front door is now {{states.lock.touchpad_electronic_deadbolt.state}}"
    entity_id: lock.touchpad_electronic_deadbolt
    state: "unlocked"
    repeat:
      - 1
      - 5
      - 15
      - 30
    can_acknowledge: False
# True will skip the first notice 
# False you will get a notice when you unlock the door.
    skip_first: False
    notifiers:
      - tts_dots # What I called this group, 
                      # use whatever you want, 
                      # but it must be the same name as below

Step 4: in the notify.yaml add

- platform: group
  name: tts_dots  # What I called this group, use whatever you want.
  services:
    service: alexa_media
    data:
      message: ${{message}}
        # Front door has been {{states.lock.touchpad_electronic_deadbolt.state}} 
        # for {{ relative_time(states.lock.touchpad_electronic_deadbolt.last_changed) }}
      target:
        - media_player.man_cave_dot  #media_player.{the name I gave my ech dots}
        - media_player.kitchen_dot
      data:
        type: tts
 

Last step: under developer tool:
“Check Configuration”
Restart Home Assistant

Unlock the door and Alexa should tell you the door is unlocked, and remind you
repeat:
- 1 minute
- 5 minutes
- 15 minutes
- 30 minutes and every 30 minutes until the door is locked.

I also, plan on adding messages to be sent to my phone.

For troubleshooting alerts:
Look in the Logbook for:
image
“Alert Front Door turned on”. That tells you the Alert is active.
then go to the “Settings > System > Logs”
if there is an error like this:


click on it for more information.

1 Like

Part 2 - Updated
alert.yaml

front_door:
  name: "Alert Front Door"
#updated to remove " for 0 seconds" from the first message
  message: |
    "Front door has been {{states.lock.touchpad_electronic_deadbolt.state}} 
    {%if relative_time(states.lock.touchpad_electronic_deadbolt.last_changed) == '0 seconds' %}
    .
    {% else %}
    for {{relative_time(states.lock.touchpad_electronic_deadbolt.last_changed)}}. 
    {%endif%}
    "
# end of update
  done_message: |
    "Front door is now {{states.lock.touchpad_electronic_deadbolt.state}}"
  title: "Front Door Unlocked"
  entity_id: lock.touchpad_electronic_deadbolt
  state: "unlocked"
  repeat:
    - 1
    - 5
    - 15
    - 30
  can_acknowledge: False
# True will skip the first notice 
# False you will get a notice when you unlock the door.
  skip_first: False
  notifiers:
    #- tts_dots # what I called this group, use whatever you want.
    - tell_all
# updated - this makes the new notice replace the old notice
  data:
    notification_id: front_door
#end of update

garage_door:
  name: "Alert Garage Door"
# updated
  message: |
    "Garage door has been {{states.cover.ratgdov25i_f393ba_door.state}} 
    {%if relative_time(states.cover.ratgdov25i_f393ba_door.last_changed) == '0 seconds' %}
    .
    {% else %}
    for {{ relative_time(states.cover.ratgdov25i_f393ba_door.last_changed) }}. 
    {%endif%}
    "
#end of update
  done_message: |
    "Graage door is now {{states.cover.ratgdov25i_f393ba_door.state}}"
  title: "Garage Door Open"
  entity_id: cover.ratgdov25i_f393ba_door
  state: "open"
  repeat:
    - 1
    - 5
    - 15
    - 30
  can_acknowledge: False
  # True will skip the first notice 
  # False you will get a notice when you unlock the door.
  skip_first: False
  notifiers:
    - tell_all
# updated
  data:
    notification_id: garage_door 
# This gets passed to persistent_notification
# Without it you get a new notification for each notice.
# With it the new notice replaces the old notice from the same alert.

notify.yaml

- platform: group
  name: tell_all  # what I called this group, use whatever you want.
  services:
    - service: alexa_media
      data:
        target:
          - media_player.man_cave_dot   #send a voice message to echo dots.
          - media_player.kitchen_dot    #media_player.{the name I gave my echo dots}
        data:
          type: tts
    - service: persistent_notification  # Send to Notificatios Panel 
    - service: mobile_app_cell_david    # Send a message to the Cell message bar/popup if turned on 
    - service: mobile_app_cell_connie

- platform: group
  name: tts_dots  # What I called this group, use whatever you want.
  services:
    service: alexa_media
    data:
      target:
        - media_player.man_cave_dot  #media_player.{the name I gave my ech dots}
        - media_player.kitchen_dot
      data:
        type: tts

I planned to add voice notices to my cells but after searching the web for information.
I plan on writing an automation to do it. My plan is:
If this alert is active, wait a few minutes then send one message.

3 Likes

could you assist me in setting this up for use with google hubs plz.

Hi Clay: I do not know anything about Google Hub. Do you have any scripts that send voice messages to Google Hub?

You need cast to use them for TTS, along with TTS for text to speech, and possibly notify.tts if you want to use it with notify services.

I have the cast setup I’m a little confused about the TTS part. Can I use Nabu Casa? and notify.tts

You can use any TTS provider you want, yes.