@Herbert01 (Werner) posted a new topic, subject "Good morning from Alexa - but only once a day". It read:

   Hi there,
    
    We have a motion detector and an echo dot in the bathroom. I would like to ensure that Alxa always sends a “Good morning” early when the motion detector is triggered for the first time. But only once a day.
    
    I've tried the following, but I'm stuck with the “only once a day” constraint:
    [code] 
        alias: Bad Guten Morgen
        description: ''
        trigger:
          - type: motion
            platform: device
            device_id: 66dfc7837dc98ce07e01289bfdf5195f
            entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_8190c306_ias_zone
            domain: binary_sensor
        condition:
          - condition: time
            after: '04:00'
            before: '07:00'
          - condition: and
            conditions:
              - condition: state
                entity_id: automation.bad_guten_morgen
                state: ''
                attribute: last_triggered
        action:
          - service: notify.alexa_media_bad
            data:
              message: Guten Morgen
        mode: single
        
        
    [/code]
    
    Can someone help me.
    
    Thank you already.
    
    Greetings Werner

To which @Didgeridrew (Drew) replied

    There are a couple ways to rate-limit an automation.
    
    1\. Using a Template Condition
    [code] 
        alias: Bad Guten Morgen
        description: ''
        trigger:
          - type: motion
            platform: device
            device_id: 66dfc7837dc98ce07e01289bfdf5195f
            entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_8190c306_ias_zone
            domain: binary_sensor
        condition:
          - condition: time
            after: '04:00'
            before: '07:00'
          - condition: template
            value_template: "{% set triggered = state_attr('automation.ztest_never_triggered', 'last_triggered') | default( now() - timedelta(hours=18), true) %}
        {{ now() - triggered > timedelta(hours = 18) }}"
        action:
          - service: notify.alexa_media_bad
            data:
              message: Guten Morgen
        mode: single
        
    [/code]
    
    2\. Using a State Condition with a Boolean Helper
    [code] 
        alias: Bad Guten Morgen
        description: ''
        trigger:
          - type: motion
            platform: device
            device_id: 66dfc7837dc98ce07e01289bfdf5195f
            entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_8190c306_ias_zone
            domain: binary_sensor
        condition:
          - condition: time
            after: '04:00'
            before: '07:00'
          - condition: state
            entity_id: input_boolean.alexa_bad_guten_morgen
            state: 'off'
        action:
          - service: notify.alexa_media_bad
            data:
              message: Guten Morgen
        mode: single
        
    [/code]
    
    For #2 you would also need to set up a boolean helper and a second automation to reset the boolean every day. It's a bit more work, but if you prefer this method you can have one automation that resets any number of helpers overnight.
    
    EDIT: Template updated to avoid ‘None' error from lack of last_triggered

So @123 (Taras) replied

    I like your first example, the one relying on `last_triggered`, because it has no dependency on a helper and uses available time information.
    
    I think this template condition would also do the trick. The last time the automation triggered must be prior to the start of the desired time range.
    [code] 
            value_template: "{{ state_attr(this.entity_id, 'last_triggered') < today_at('04:00') }}"
        
    [/code]
    
    If `last_triggered` is after today's start time then it means the automation has already been executed today and the condition will prevent it from running again (today).

To which @Herbert01 (Werner) replied

    Hi there,
    
    thank you very much for the good contributions. I chose Verion 1 @Didgeridrew. Seems to be working great. I will be able to use the version from @123 in another project.
    
    Thank you and have a nice weekend.
    
    Greetings Werner


{'source': 'discourse', 'url': 'https://community.home-assistant.io/t/good-morning-from-alexa-but-only-once-a-day/388373', 'title': 'Good morning from Alexa - but only once a day', 'views': 196, 'has_accepted_answer': True, 'word_count': 428, 'like_count': 5, 'reply_count': 1, 'participant_count': 3, 'posts': 4, 'tags': '', 'author': '@Herbert01 (Werner)', 'participants': '@Herbert01 (Werner), @Didgeridrew (Drew), @123 (Taras)', 'image_url': [None], 'created_at': '2022-02-04T09:39:14.653Z', 'last_posted_at': '2022-02-04T15:30:01.141Z'}