Get motion to trigger just once within a time period

Hi all,

I’m really struggling with this.

I want my hue motion sensor to turn my kitchen lights on in the morning as I walk in.

The problem is I just want it to trigger the once. As it stands, it fires every time i move between 03:00 & 09:00am.

Any idea how I could get this to work?

- id: 'morning_motion'
  alias: 'Morning Motion'
  trigger:
    - platform: state
      entity_id: sensor.hall_motion_sensor
      to: 'on'
  condition:
    condition: and
    conditions:
      - condition: time
        before: '09:00:00'
        after: '03:00:00'
      - condition: state
        entity_id: group.family
        state: 'home'
  action:
    - service: notify.pushbullet
      data:
        message: 'Good Morning'
        target: 'device/Google Pixel 2'
    - service: script.good_morning

Use an input_boolean to store if the sensor has already fired.
When the sensor fires the first time, turn it off (or on).
Add a condition to your automation that checks the input_boolean's state.
Add another automation that turns it on (or off) again e.g. each midnight.

I’m using the same principle to have my kitchen-Alexa play it’s “good morning” routine followed by turning on some radio stream every morning I enter the kitchen.

Sebastian

2 Likes

I use this to track when the automation last ran and make sure it does not run again if it ran less than 2 min (120sec) ago:

    - condition: template
      value_template: '{{ (as_timestamp(now()) - as_timestamp(states.automation.morning_motion.attributes.last_triggered | default(0)) | int > 120)}}'
6 Likes

I like the look of that. I guess I could set that time limit to be if it’s not seen motion for a few hours, and then just have the automation run between the hours that I already have set.
Cheers - I’ll have a play with that when I get a chance!

the way I’ve done this for my vacuum is to not trigger again if triggered in the last 6h (6h for you between 03:00 and 09:00)
This way it will only trigger once, not need to add the motion sensor “complication” :wink:

1 Like

This is what I now have and it seems to be working nicely.

All I need to do now is get Google to play the news, or stream a radio station and I’ll be happy :slightly_smiling_face:

- id: 'morning_motion'
  alias: 'Morning Motion'
  trigger:
    - platform: state
      entity_id: sensor.hall_motion_sensor
      to: 'on'
  condition:
    condition: and
    conditions:
      - condition: time
        before: '09:00:00'
        after: '06:00:00'
      - condition: state
        entity_id: group.family
        state: 'home'
      - condition: template
        value_template: '{{ (as_timestamp(now()) - as_timestamp(states.automation.morning_motion.attributes.last_triggered | default(0)) | int > 10800)}}'
  action:
    - service: script.good_morning
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.kitchen_speaker
        volume_level: 0.4
    - service: tts.google_say
      data:
        entity_id: media_player.kitchen_speaker
        message: "Good morning Granger house!"
        language: 'en'

not sure about the news, but for the streaming I use this:

1 Like