HELP Needed on My First Automation using a very simple binary entity

Hey All… Just learning here.
One of my first Automatons, and when I close the front door Alexa says “The Front Door was just closed” But then only a few seconds later says “The front door was opened” and finally again “The Front Door was just closed” … ??? . Doesn’t seem to matter if the door stays open for a long time.
The goal is to say it just one time…

I don’t seem to have the same problem when the front door is opened. That announcement is identical except the entity and announcement. It says just one time…“the front door was just opened”
Any suggestions?? Thanks

alias: Front Door Closed
description: Tells Alexa to say the front door is closed
trigger:

  • platform: state
    entity_id:
    • binary_sensor.front_door
      from: “on”
      to: “off”
      condition: []
      action:
  • service: notify.alexa_media_echo_dot_ver_4
    data:
    message: The Front Door was just Closed
    title: Front Door Closed
    data:
    type: tts
  • stop: “”
    mode: single

This one seems to work when opening the front door…

alias: Front Door Opened
description: Front Door Opened sends message to Alexa
trigger:

  • platform: state
    entity_id:
    • binary_sensor.front_door
      from: “off”
      to: “on”
      condition: []
      action:
  • service: notify.alexa_media_echo_dot_ver_4
    data:
    message: The Front Door was just Opened
    title: Front Door Opened
    data:
    type: tts
  • stop: “”
    mode: single

What type/brand/model of sensor are you using?
What does the history of the door sensor look like…?
Does the history or logbook show it bouncing between off/on/off?

This is an “Envisalink integration” to a DSC Security System.
I don’t see any errors in the log.
The contact sensor is hard wired to the DSC panel, and the Envisalink allows self monitoring and with the integration I have 6 different doors that I can monitor.
The
(entity_id:
binary_sensor.front_door) is just one of six different entities I can monitor.
Which if I understand is either an Off or On state.
That said I’m a beginner here. And I thought this would be a simple start for me.
Note: If I open the door I get one correct message on Alexa that the door was opened. However if I close it. I get the door was closed and then about 30 seconds later , door open and then door closed.

I’ve posted both automations on my first post.

It’s a standard magnetic reed contact switch used in millions of Security Systems used in homes not even automated.
Has nothing to do with the switch itself. The switch has no logic or electronics. It’s Either on or off.
And the history log shows that automation going on or off as expected. Likely something with The Envisalink or even the Alexa integration.
Thanks for your help, but Thinking I should take this question to the Envisalink forum here as this is related to the Envisalink interface and not the contact switch. Your time truly appreciated :+1:

Try adding in the state change ‘for 2 seconds’.
It might be that in the act of closing, for a minimal fraction of time the sensor jump between the 2 states

Can you assist on his this is done?
Where in this code should it be placed?

platform: state
entity_id:
    binary_sensor.front_door
    from: “on”
    to: “off”
    condition: []
    action:
service: notify.alexa_media_echo_dot_ver_4
data:
message: The Front Door was just Closed
title: Front Door Closed
data:
type: tts
stop: “”
mode: single
platform: state
entity_id:
    binary_sensor.front_door
    from: “on”
    to: “off"
    for:
      hours: 0
      minutes: 0
      seconds: 2
    condition: []
    action:
service: notify.alexa_media_echo_dot_ver_4
data:
message: The Front Door was just Closed
title: Front Door Closed
data:
type: tts
stop: “”
mode: single
platform: device
device_id: X
entity_id: binary_sensor_X
domain: binary_sensor
for:
  hours: 0
  minutes: 0
  seconds: 2

What I do wonder is why they hell you did 2 automations for 1 thing.
I did the same when stuck understanding to documentation about automation.
I then thought to have a look at the blueprints and found this:

And 2 of them were easy enough for my limited brain to get the sense.
Finally looking at the blueprint code + the result the blueprint created allowed me to handcode the below lines.
1 automation handling both ways … this was something new to me.
and it worked lots better but what I manually coded prior to that. I ended up with a 30-40 line automation which did work … but the more lines the more chances for an error. :slight_smile:

Perhaps this gives and idea about how to modify your code.
I wouldn’t go for multiple automations dealing with the very same entities in the opposite way since you never know at which point the second gets started … perhaps while the first one isn’t done yet?

  trigger:
  - platform: state
    entity_id: sensor.button1
    from: 'off'
    to: 'on'
  action:
  - service: homeassistant.turn_on
    target:
      entity_id: switch.plug1
  - wait_for_trigger:
    - platform: state
      entity_id: sensor.button1
      from: 'on'
      to: 'off'
  - service: homeassistant.turn_off
    target:
      entity_id: switch.plug1
  mode: single

Your two automations consolidated:

alias: Front Door Announcement
description: Tells Alexa to say the front door is opened or closed
trigger:
  - id: 'closed'
    platform: state
    entity_id: binary_sensor.front_door
    from: 'on'
    to: 'off'
    for:
      seconds: 2
  - id: 'opened'
    platform: state
    entity_id: binary_sensor.front_door
    from: 'off'
    to: 'on'
    for:
      seconds: 2
condition: []
action:
  - service: notify.alexa_media_echo_dot_ver_4
    data:
      message: "The Front Door was just {{ trigger.id }}"
      title: "Front Door {{ trigger.id | title }}"
      data:
        type: tts
mode: single
2 Likes

Please do not create duplicate posts, just edit this one. Thanks.

Yes. I think I understand this. Well sort of.
Sometimes I think I’m going into areas I know nothing about and usually copy and paste others yaml code into my setup. But enjoying the challenge and truly appreciate the help here.
Could you explain why the delay is needed?
Does the Envisalink integration tend to duplicate a binary change?
Curious why it’s stable only when opening the door? But closing it causes Alexa to repeat the message.

for:
      hours: 0
      minutes: 0
      seconds: 2
    condition: []

It may not be needed.

If the door sensor has any “bounce” (i.e. it indicates on/off/on in rapid succession) then the for serves to ignore that hiccup. The “for 2 seconds” means “I need to see an uninterrupted on state for at least 2 seconds before I’ll trigger”.

You can test it with and without the for. If there’s no difference in behavior, simply remove the for.

LoL… now that’s very interesting.
Thank you.
I’m just a total beginner here for a 71 year old man. But can’t wait to try this all in one automation. Thanks again. :+1:

2 Likes

Thank you for your explanation. Totally helped :+1::sunglasses:

This is great. Thank you so much.
I disabled both my separate entry level integrations and pasted yours in.
Works perfectly.!!! :+1::sunglasses:

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic is resolved. This helps other users find answers to similar questions.

You marked your own post with the Solution tag but that’s not how it’s meant to be used (your selected post contains no information explaining how to resolve the original problem).

As author of this topic, you get to choose one post, out of the entire thread, that best serves to answer/resolve your original question/problem. By marking that one post with the Solution tag, it leads other users to it and discover the topic’s resolution.

For more information, refer to guideline 21 in the FAQ.