MQTT trigger toggle automation when it shouldn't

I have this automation that sends a notification when a PIR motion sensor is triggered with at least 2 minutes gap between each triggers.

- alias: 'Speaker - Backyard'
  trigger:
    platform: mqtt
    topic: home/433toMQTT
    payload: !secret 433_motion_backyard
  action:
    - service: automation.turn_off
      entity_id: automation.speaker__backyard
    - service: notify.office_livingroom
      data:
        message: "Someone is at the backyard."
    - delay:
        minutes: 2
    - service: automation.turn_on
      entity_id: automation.speaker__backyard

However, it doesn’t work as intended.

When the PIR sensor is triggered, it sends the notification multiple times and the automation will turn back on when the PIR sensor is triggered on the second time even though it is only seconds apart.

That means, I would be bombarded by the notifications when someone is moving around in the backyard.

I may be captain obvious here but automation.speaker__backyard isn’t turning off/on your automation. Just for the giggles, can your rename your alias to something without dashes or underscores - say like ‘giggles’. Then your entity_id would be automation.giggles. Try that.

Also action items are worked in the order given… Might want to do the notify first and then turn off the automation.

I worked this out for a 433mhz pir today just to test it out.

  - alias: OfficePres
    trigger:
      platform: mqtt
      topic: home/433toMQTT
      payload: '#######' 
    action:
      - service: script.turn_on
        entity_id: script.officemot
      - service: automation.turn_off
        entity_id: automation.officepres
      - delay: 
          minutes: 2
      - service: automation.turn_on
        entity_id: automation.officepres

Here are my scripts for it if anyone is interested:

  officemot:
    alias: Office Motion
    sequence:
      # Cancel ev. old timers
      - service: script.turn_off
        data:
          entity_id: script.officetimeoff
      - delay:
          seconds: 5
      - service: homeassistant.turn_on
        data:
          entity_id: group.office
      # Set new timer
      - service: script.turn_on
        data:
          entity_id: script.officetimeoff

  officetimeoff:
    alias: "Turn off office after 5 minutes"
    sequence:
      - delay:
          minutes: 5
      - service: homeassistant.turn_off
        data:
          entity_id: group.office

Thanks to @enricfp1 for the configuration example.

2 Likes