Duplicate Notifications from single Trigger

I have created the automation below which will take a snapshot and send it to my phone and my wife’s phone when my doorbell camera detects motion. The doorbell is an Amcrest AD410 which is integrated using amcrest2mqtt. The binary_sensor.doorbell_motion has a timeout of approximately 1 minute (e.g. it will trigger “on” and stay on for about 1 minute before turning “off” if there is no motion).

I have found that in some instances I will get two notifications at the same time with the same snapshot (see attached screenshot). It seems to happen randomly (I have not been able to reproduce it at will). Sometimes I will get duplicate notifications and my wife will not, other times both of us will receive duplicates.

Any ideas why we would get duplicate notifications?

alias: Doorbell Motion
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.doorbell_motion
    from: 'off'
    to: 'on'
condition:
  - condition: time
    before: '22:00:00'
    after: '06:00:00'
action:
  - service: camera.snapshot
    data:
      filename: /config/www/tmp/snapshot.jpg
    target:
      entity_id: camera.doorbell_cropped
  - service: notify.mobile_app_pixel_4a
    data:
      message: Front Door
      title: Motion Detected
      data:
        channel: Doorbell
        importance: max
        group: human-detected
        image: /local/tmp/snapshot.jpg
        ttl: 0
        priority: high
  - service: notify.mobile_app_pixel_3a
    data:
      message: Front Door
      title: Motion Detected
      data:
        channel: Doorbell
        importance: max
        group: human-detected
        image: /local/tmp/snapshot.jpg
        ttl: 0
        priority: high
mode: single

A bit more detail: I checked the notification history in the companion app, see attached screenshot. Notice the duplicates at 9:57:43 and 9:20:00.

When it happens, examine the automation’s latest and penultimate traces for clues to its behavior.

1 Like

It happened again today. Motion was detected at 3:31pm, but I did not receive a notification until 4:55pm. The previous trigger has hours before (9:20am).

I received two notifications at this time (4:55pm), one with a snapshot and one without. Below is the trace from this trigger (I am not seeing anything that would help diagnose the problem):

{
  "trace": {
    "last_step": "action/2",
    "run_id": "72eaed2d82c7c4949c1d963a8a4bb731",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2022-04-27T21:31:13.530833+00:00",
      "finish": "2022-04-27T21:31:15.085650+00:00"
    },
    "domain": "automation",
    "item_id": "1650331468375",
    "trigger": "state of binary_sensor.doorbell_motion",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2022-04-27T21:31:13.531022+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.doorbell_motion_chris_2",
              "state": "on",
              "attributes": {
                "last_triggered": "2022-04-27T21:23:04.945318+00:00",
                "mode": "single",
                "current": 0,
                "id": "1650331468375",
                "friendly_name": "Doorbell Motion"
              },
              "last_changed": "2022-04-27T00:00:02.510531+00:00",
              "last_updated": "2022-04-27T21:23:07.298292+00:00",
              "context": {
                "id": "0c58d2e58930867ae4241a0e3085aed7",
                "parent_id": "7c993fa37933eff6f752e092f08465c1",
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "platform": "state",
              "entity_id": "binary_sensor.doorbell_motion",
              "from_state": {
                "entity_id": "binary_sensor.doorbell_motion",
                "state": "off",
                "attributes": {
                  "device_class": "motion",
                  "friendly_name": "Doorbell Motion"
                },
                "last_changed": "2022-04-27T21:23:38.064974+00:00",
                "last_updated": "2022-04-27T21:23:38.064974+00:00",
                "context": {
                  "id": "7b789e400ac8908d9473dacf49da1213",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "binary_sensor.doorbell_motion",
                "state": "on",
                "attributes": {
                  "device_class": "motion",
                  "friendly_name": "Doorbell Motion"
                },
                "last_changed": "2022-04-27T21:31:13.529037+00:00",
                "last_updated": "2022-04-27T21:31:13.529037+00:00",
                "context": {
                  "id": "ee61a6faae3620fa9796b78b9a7d151f",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": null,
              "attribute": null,
              "description": "state of binary_sensor.doorbell_motion"
            }
          }
        }
      ],
      "condition/0": [
        {
          "path": "condition/0",
          "timestamp": "2022-04-27T21:31:13.531155+00:00",
          "result": {
            "after": {
              "__type": "<class 'datetime.time'>",
              "isoformat": "06:00:00"
            },
            "now_time": {
              "__type": "<class 'datetime.time'>",
              "isoformat": "15:31:13.531195"
            },
            "before": {
              "__type": "<class 'datetime.time'>",
              "isoformat": "22:00:00"
            },
            "result": true
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2022-04-27T21:31:13.532356+00:00",
          "changed_variables": {
            "context": {
              "id": "8c19d72cc2af48893524f9c41a792fbf",
              "parent_id": "ee61a6faae3620fa9796b78b9a7d151f",
              "user_id": null
            }
          },
          "result": {
            "params": {
              "domain": "camera",
              "service": "snapshot",
              "service_data": {
                "filename": "/config/www/tmp/snapshot.jpg",
                "entity_id": [
                  "camera.doorbell_cropped"
                ]
              },
              "target": {
                "entity_id": [
                  "camera.doorbell_cropped"
                ]
              }
            },
            "running_script": false,
            "limit": 10
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2022-04-27T21:31:14.211115+00:00",
          "result": {
            "params": {
              "domain": "notify",
              "service": "mobile_app_pixel_4a",
              "service_data": {
                "message": "ID 838",
                "title": "Motion Detected",
                "data": {
                  "channel": "Doorbell",
                  "importance": "max",
                  "group": "human-detected",
                  "image": "/local/tmp/snapshot.jpg",
                  "ttl": 0,
                  "priority": "high"
                }
              },
              "target": {}
            },
            "running_script": false,
            "limit": 10
          }
        }
      ],
      "action/2": [
        {
          "path": "action/2",
          "timestamp": "2022-04-27T21:31:14.665126+00:00",
          "result": {
            "params": {
              "domain": "notify",
              "service": "mobile_app_pixel_3a",
              "service_data": {
                "message": "Front door",
                "title": "Motion Detected",
                "data": {
                  "channel": "Doorbell",
                  "importance": "max",
                  "group": "human-detected",
                  "image": "/local/tmp/snapshot.jpg",
                  "ttl": 0,
                  "priority": "high"
                }
              },
              "target": {}
            },
            "running_script": false,
            "limit": 10
          }
        }
      ]
    },
    "config": {
      "id": "1650331468375",
      "alias": "Doorbell Motion",
      "description": "",
      "trigger": [
        {
          "platform": "state",
          "entity_id": "binary_sensor.doorbell_motion",
          "from": "off",
          "to": "on"
        }
      ],
      "condition": [
        {
          "condition": "time",
          "before": "22:00:00",
          "after": "06:00:00"
        }
      ],
      "action": [
        {
          "service": "camera.snapshot",
          "data": {
            "filename": "/config/www/tmp/snapshot.jpg"
          },
          "target": {
            "entity_id": "camera.doorbell_cropped"
          }
        },
        {
          "service": "notify.mobile_app_pixel_4a",
          "data": {
            "message": "ID {{ range(1, 1000) | random }}",
            "title": "Motion Detected",
            "data": {
              "channel": "Doorbell",
              "importance": "max",
              "group": "human-detected",
              "image": "/local/tmp/snapshot.jpg",
              "ttl": 0,
              "priority": "high"
            }
          }
        },
        {
          "service": "notify.mobile_app_pixel_3a",
          "data": {
            "message": "Front door",
            "title": "Motion Detected",
            "data": {
              "channel": "Doorbell",
              "importance": "max",
              "group": "human-detected",
              "image": "/local/tmp/snapshot.jpg",
              "ttl": 0,
              "priority": "high"
            }
          }
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "8c19d72cc2af48893524f9c41a792fbf",
      "parent_id": "ee61a6faae3620fa9796b78b9a7d151f",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Doorbell Motion",
      "message": "has been triggered by state of binary_sensor.doorbell_motion",
      "source": "state of binary_sensor.doorbell_motion",
      "entity_id": "automation.doorbell_motion_chris_2",
      "context_id": "8c19d72cc2af48893524f9c41a792fbf",
      "when": "2022-04-27T21:31:13.531499+00:00",
      "domain": "automation"
    }
  ]
}

Another occurrence today. Motion was detected and I received two notifications at the same time. Below is the trace from this trigger (again, I am not seeing anything that would help diagnose the problem):

{
  "trace": {
    "last_step": "action/2",
    "run_id": "ace7f85bee3f8af008c434ff6df89d90",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2022-04-28T20:01:52.698385+00:00",
      "finish": "2022-04-28T20:01:54.691584+00:00"
    },
    "domain": "automation",
    "item_id": "1650331468375",
    "trigger": "state of binary_sensor.doorbell_motion",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2022-04-28T20:01:52.698494+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.doorbell_motion_chris_2",
              "state": "on",
              "attributes": {
                "last_triggered": "2022-04-28T18:47:56.354615+00:00",
                "mode": "single",
                "current": 0,
                "id": "1650331468375",
                "friendly_name": "Doorbell Motion"
              },
              "last_changed": "2022-04-28T19:06:40.067013+00:00",
              "last_updated": "2022-04-28T19:06:40.067013+00:00",
              "context": {
                "id": "4e412c6c191caf560132083b482c807a",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "platform": "state",
              "entity_id": "binary_sensor.doorbell_motion",
              "from_state": {
                "entity_id": "binary_sensor.doorbell_motion",
                "state": "off",
                "attributes": {
                  "device_class": "motion",
                  "friendly_name": "Doorbell Motion"
                },
                "last_changed": "2022-04-28T19:36:13.253047+00:00",
                "last_updated": "2022-04-28T19:36:13.253047+00:00",
                "context": {
                  "id": "fb8a08b33ca7b79b6dbc293d6872ed0a",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "binary_sensor.doorbell_motion",
                "state": "on",
                "attributes": {
                  "device_class": "motion",
                  "friendly_name": "Doorbell Motion"
                },
                "last_changed": "2022-04-28T20:01:52.697757+00:00",
                "last_updated": "2022-04-28T20:01:52.697757+00:00",
                "context": {
                  "id": "6ba2344800562c3a4080deb22aef460f",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": null,
              "attribute": null,
              "description": "state of binary_sensor.doorbell_motion"
            }
          }
        }
      ],
      "condition/0": [
        {
          "path": "condition/0",
          "timestamp": "2022-04-28T20:01:52.698595+00:00",
          "result": {
            "after": {
              "__type": "<class 'datetime.time'>",
              "isoformat": "06:00:00"
            },
            "now_time": {
              "__type": "<class 'datetime.time'>",
              "isoformat": "14:01:52.698633"
            },
            "before": {
              "__type": "<class 'datetime.time'>",
              "isoformat": "22:00:00"
            },
            "result": true
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2022-04-28T20:01:52.701156+00:00",
          "changed_variables": {
            "context": {
              "id": "1e0f0c735ce3f0ccbcb653f3c267a1c1",
              "parent_id": "6ba2344800562c3a4080deb22aef460f",
              "user_id": null
            }
          },
          "result": {
            "params": {
              "domain": "camera",
              "service": "snapshot",
              "service_data": {
                "filename": "/config/www/tmp/snapshot.jpg",
                "entity_id": [
                  "camera.doorbell_cropped"
                ]
              },
              "target": {
                "entity_id": [
                  "camera.doorbell_cropped"
                ]
              }
            },
            "running_script": false,
            "limit": 10
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2022-04-28T20:01:53.763619+00:00",
          "result": {
            "params": {
              "domain": "notify",
              "service": "mobile_app_pixel_4a",
              "service_data": {
                "message": "ID 366",
                "title": "Motion Detected",
                "data": {
                  "channel": "Doorbell",
                  "importance": "max",
                  "group": "human-detected",
                  "image": "/local/tmp/snapshot.jpg",
                  "ttl": 0,
                  "priority": "high"
                }
              },
              "target": {}
            },
            "running_script": false,
            "limit": 10
          }
        }
      ],
      "action/2": [
        {
          "path": "action/2",
          "timestamp": "2022-04-28T20:01:54.275724+00:00",
          "result": {
            "params": {
              "domain": "notify",
              "service": "mobile_app_pixel_3a",
              "service_data": {
                "message": "Front door",
                "title": "Motion Detected",
                "data": {
                  "channel": "Doorbell",
                  "importance": "max",
                  "group": "human-detected",
                  "image": "/local/tmp/snapshot.jpg",
                  "ttl": 0,
                  "priority": "high"
                }
              },
              "target": {}
            },
            "running_script": false,
            "limit": 10
          }
        }
      ]
    },
    "config": {
      "id": "1650331468375",
      "alias": "Doorbell Motion",
      "description": "",
      "trigger": [
        {
          "platform": "state",
          "entity_id": "binary_sensor.doorbell_motion",
          "from": "off",
          "to": "on"
        }
      ],
      "condition": [
        {
          "condition": "time",
          "before": "22:00:00",
          "after": "06:00:00"
        }
      ],
      "action": [
        {
          "service": "camera.snapshot",
          "data": {
            "filename": "/config/www/tmp/snapshot.jpg"
          },
          "target": {
            "entity_id": "camera.doorbell_cropped"
          }
        },
        {
          "service": "notify.mobile_app_pixel_4a",
          "data": {
            "message": "ID {{ range(1, 1000) | random }}",
            "title": "Motion Detected",
            "data": {
              "channel": "Doorbell",
              "importance": "max",
              "group": "human-detected",
              "image": "/local/tmp/snapshot.jpg",
              "ttl": 0,
              "priority": "high"
            }
          }
        },
        {
          "service": "notify.mobile_app_pixel_3a",
          "data": {
            "message": "Front door",
            "title": "Motion Detected",
            "data": {
              "channel": "Doorbell",
              "importance": "max",
              "group": "human-detected",
              "image": "/local/tmp/snapshot.jpg",
              "ttl": 0,
              "priority": "high"
            }
          }
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "1e0f0c735ce3f0ccbcb653f3c267a1c1",
      "parent_id": "6ba2344800562c3a4080deb22aef460f",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Doorbell Motion",
      "message": "has been triggered by state of binary_sensor.doorbell_motion",
      "source": "state of binary_sensor.doorbell_motion",
      "entity_id": "automation.doorbell_motion_chris_2",
      "context_id": "1e0f0c735ce3f0ccbcb653f3c267a1c1",
      "when": "2022-04-28T20:01:52.698922+00:00",
      "domain": "automation"
    }
  ]
}

Hi.
Did you find out what caused this? I’m getting duplicate snapshot notifications from my camera all the time.

Unfortunately I never did find the cause.

I found this on the net, it works for me
image: http://yourhomeassistantURI/local/tmp/snapshot.jpg?{{ as_timestamp(now()) }}