[Automation] Motion TTS repeats too often

Issue: Everytime one of the motion sensors starts to detect motion it calls the TTS service. This then repeats the “motion detected” TTS every few seconds while motion it being triggered over and over. I have an automation that gets triggered via 2 Motion Sensors. These have a super short “cooldown”, so I followed other examples and created a timer that keeps the lights on when additional motion is detected and only when both sensors stop detecting motion the “cooldown timer” starts and turns the light off at 2 minutes. So my only hurdle is keeping the lights controlled via the timer, but only have the TTS fire once on initial motion.

alias: May 5th Motion Test
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.back_porch_motion
    to: "on"
    id: BP Motion ON
    from: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 0
    alias: Back Porch Motion DETECTED
  - platform: state
    entity_id:
      - binary_sensor.back_porch_motion
    id: BP Motion OFF
    for:
      hours: 0
      minutes: 0
      seconds: 0
    to: "off"
    alias: Back Porch Motion CLEAR
  - platform: event
    event_type: timer.finished
    id: Timer Finished
    event_data:
      entity_id: timer.motion_cooldown
    alias: Timer Finished event fired
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - BP Motion ON
          - condition: time
            after: "04:00:00"
            before: "08:00:00"
            weekday:
              - sun
              - mon
              - tue
              - wed
              - thu
              - fri
              - sat
        sequence:
          - service: timer.cancel
            target:
              entity_id: timer.motion_cooldown
            data: {}
          - service: light.turn_on
            metadata: {}
            data:
              color_name: green
              brightness: 100
            target:
              device_id:
                - 1df9c727daaa4726bf7ac5cb058d1625
          - delay:
              hours: 0
              minutes: 0
              seconds: 1
              milliseconds: 0
          - service: tts.speak
            target:
              entity_id: tts.google_en_com
            data:
              cache: true
              media_player_entity_id: >-
                media_player.raspiaudio_muse_luxe_bc7a7c_raspiaudio_muse_luxe_bc7a7c
              message: Chloe wants in please
            alias: TTS - Chloe
            enabled: true
        alias: "[0400-0800] Chloe TTS"
      - conditions:
          - condition: trigger
            id:
              - BP Motion ON
          - condition: time
            after: "08:01:00"
            before: "03:59:00"
            weekday:
              - sun
              - mon
              - tue
              - wed
              - thu
              - fri
              - sat
        sequence:
          - service: tts.speak
            target:
              entity_id: tts.google_en_com
            data:
              cache: true
              media_player_entity_id: >-
                media_player.raspiaudio_muse_luxe_bc7a7c_raspiaudio_muse_luxe_bc7a7c
              message: Motion detected on back porch
            alias: TTS - Motion Detected
            enabled: true
          - service: timer.cancel
            target:
              entity_id: timer.motion_cooldown
            data: {}
          - service: light.turn_on
            metadata: {}
            data:
              color_name: green
              brightness: 100
            target:
              device_id:
                - 1df9c727daaa4726bf7ac5cb058d1625
          - delay:
              hours: 0
              minutes: 0
              seconds: 1
              milliseconds: 0
        alias: "[Dave awake] Motion TTS"
      - conditions:
          - condition: trigger
            id:
              - BP Motion OFF
        sequence:
          - service: timer.start
            metadata: {}
            data: {}
            target:
              entity_id: timer.motion_cooldown
      - conditions:
          - condition: trigger
            id:
              - Timer Finished
        sequence:
          - service: light.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: light.0x142d41fffe58913e
mode: single

11. Format it properly

Right now the code is mangled, plz fix it

Figured it out how to post the code so everyone can read it now - thanks.

You can use timer.start to restart the timer, no need to cancel it.
Then you can check if the timer is running, while the timer is running you just do not play the message.
So in your sequence you just add a condition before running the service.

I’ve changed it to use timer.start, but I tried multiple ways to add a condition for the TTS to only fire if the timer was “active”. I’m seeing the motion sensor goes to clear and if it detects movement then the TTS fires again. I tried to trigger the TTS with timer.started event, but that also isn’t working. I’m sure I’m missing something very easy.

Can you post the automation?

I created a new automation and used the office PIR sensor to test. It also announces the TTS message while the timer is still going. The light turns off after the timer finishes and the time extends like it should when it registers more motion after it clears. I did do a work-around by splitting this up into 2 automations that cover the Lights an TTS individually. The TTS has a delay that is greater than the light on time. It would be nice to have 1 automation to do everything. Thanks for taking a look.

alias: 5 MAY MOTION v3
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.athom_athom_presence_sensor_pir_sensor
    to: "on"
    id: PIR DETECTED ON
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.office_motion_timer
    id: Timer Finished
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - PIR DETECTED ON
        sequence:
          - service: timer.start
            metadata: {}
            data: {}
            target:
              entity_id: timer.office_motion_timer
          - service: light.turn_on
            metadata: {}
            data:
              color_name: magenta
            target:
              device_id: 1df9c727daaa4726bf7ac5cb058d1625
          - condition: state
            entity_id: timer.office_motion_timer
            state: active
          - service: tts.speak
            metadata: {}
            data:
              cache: true
              media_player_entity_id: >-
                media_player.raspiaudio_muse_luxe_bc7a7c_raspiaudio_muse_luxe_bc7a7c
              message: Motion Warning
            target:
              entity_id: tts.google_en_com
            enabled: true
      - conditions:
          - condition: trigger
            id:
              - Timer Finished
        sequence:
          - service: light.turn_off
            metadata: {}
            data: {}
            target:
              device_id: 1df9c727daaa4726bf7ac5cb058d1625
mode: single

Right now you have a condition for the sequence. So if that fails it stops the sequence.
But in your case that will still be true. So it will still plsy the message

The timer is active so it just goes its merry way :smiley: Since you always start the timer this will always be active.
So before you start the timer you can use an if then statement and check for idle

action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - PIR DETECTED ON
        sequence:
          - if:
              - condition:  state
                entity_id: timer.office_motion_timer
                state: idle
            then:
              - service: tts.speak
                metadata: {}
                data:
                  cache: true
                  media_player_entity_id: >-
                    media_player.raspiaudio_muse_luxe_bc7a7c_raspiaudio_muse_luxe_bc7a7c
                  message: Motion Warning
                target:
                  entity_id: tts.google_en_com
                enabled: true
          - service: timer.start
            metadata: {}
            data: {}
            target:
              entity_id: timer.office_motion_timer
          - service: light.turn_on
            metadata: {}
            data:
              color_name: magenta
            target:
              device_id: 1df9c727daaa4726bf7ac5cb058d1625

Thanks for the help with this. I’ve learned that if you think that something can be done in HA then it can be. Again thanks. Here is the working Automation if anyone needs this in the future:

alias: 8 MAY MOTION Forum Help
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.athom_athom_presence_sensor_pir_sensor
    to: "on"
    id: PIR DETECTED ON
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.office_motion_timer
    id: Timer Finished
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - PIR DETECTED ON
        sequence:
          - if:
              - condition: state
                entity_id: timer.office_motion_timer
                state: idle
            then:
              - service: tts.speak
                metadata: {}
                data:
                  cache: true
                  media_player_entity_id: >-
                    media_player.raspiaudio_muse_luxe_bc7a7c_raspiaudio_muse_luxe_bc7a7c
                  message: Motion Warning test
                target:
                  entity_id: tts.google_en_com
          - service: timer.start
            metadata: {}
            data: {}
            target:
              entity_id: timer.office_motion_timer
          - service: light.turn_on
            metadata: {}
            data:
              color_name: magenta
            target:
              device_id:
                - 1df9c727daaa4726bf7ac5cb058d1625
                - 3d11f98e02a4730d6db51637efde96c2
      - conditions:
          - condition: trigger
            id:
              - Timer Finished
        sequence:
          - service: light.turn_off
            metadata: {}
            data: {}
            target:
              device_id:
                - 1df9c727daaa4726bf7ac5cb058d1625
                - 3d11f98e02a4730d6db51637efde96c2
mode: single