Good morning Automation does not trigger

Hi there,

I created an automation. This should trigger an Alexa greeting every morning.
So far this has never been triggered. This morning I tested it again, unfortunately it doesn’t work.

What can be the reason?

Here the automation:

alias: Guten Morgen Bad
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: '05:00'
    before: '07:40'
  - condition: template
    value_template: >-
      {{ now() - timedelta(hours=18) > state_attr('automation.guten_morgen_bad',
      'last_triggered')  }}
action:
  - choose:
      - conditions:
          - condition: time
            after: '05:00'
            before: '06:15'
            weekday:
              - mon
        sequence:
          - service: notify.alexa_media_bad
            data:
              message: Guten Morgen Montag
              data:
                type: tts
          - service: media_player.play_media
            data:
              media_content_id: Alexa.Joke.Play
              media_content_type: sequence
            target:
              entity_id:
                - media_player.bad
      - conditions:
          - condition: time
            weekday:
              - tue
            after: '05:00'
            before: '06:15'
        sequence:
          - service: notify.alexa_media_bad
            data:
              data:
                type: tts
              message: Guten Morgen Dienstag
          - service: media_player.play_media
            data:
              media_content_id: Alexa.Weather.Play
              media_content_type: sequence
            target:
              entity_id:
                - media_player.bad
      - conditions:
          - condition: time
            after: '05:00'
            before: '06:15'
            weekday:
              - wed
        sequence:
          - service: notify.alexa_media_bad
            data:
              data:
                type: tts
              message: Guten Morgen Mittwoch
          - service: media_player.play_media
            data:
              media_content_id: Alexa.GoodMorning.Play
              media_content_type: sequence
            target:
              entity_id:
                - media_player.bad
      - conditions:
          - condition: time
            weekday:
              - thu
            after: '05:00'
            before: '06:15'
        sequence:
          - service: notify.alexa_media_bad
            data:
              data:
                type: tts
              message: Guten Morgen Donnerstag
          - service: media_player.play_media
            data:
              media_content_id: Alexa.Weather.Play
              media_content_type: sequence
            target:
              entity_id:
                - media_player.bad
      - conditions:
          - condition: time
            after: '05:00'
            before: '06:15'
            weekday:
              - fri
        sequence:
          - service: notify.alexa_media_bad
            data:
              message: Guten Morgen Freitag
              data:
                type: tts
          - service: media_player.play_media
            data:
              media_content_id: Alexa.TellStory.Play
              media_content_type: sequence
            target:
              entity_id:
                - media_player.bad
      - conditions:
          - condition: time
            weekday:
              - sat
            after: '06:00'
            before: '07:55'
        sequence:
          - service: notify.alexa_media_bad

I’m grateful for any help.

Greetings Werner

Have you tried the “old fashioned” trigger?

trigger:
  - platform: state
    entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_8190c306_ias_zone
    to: 'on'

Furthermore have you checked the “Debug Automation”? Does it really not trigger or is one of the conditions wrong?

1 Like

Hi there,

Yes, I have already integrated the sensor in different ways.
Unfortunately, I don’t know anything about the debug.
Unfortunately I can’t get any further.

Greetings Werner

Unfortunately, I don’t know anything about the debug.

No problem :slight_smile:
There is a extensive documentation about getting started with “Automation Debug” view:
Troubleshooting Automations - Home Assistant (home-assistant.io)

2 Likes
type: tts

is missing in your text messages. Try this way:


          - service: notify.alexa_media_bad
            data:
              message: Guten Morgen Dienstag
              data:
                type: tts

1 Like

Hi there,

The thing with tts is strange. It’s in the user interface and the command runs flawlessly in the test.

I looked at that with the debug. Unfortunately my English is bad.
I’ll keep trying.

Greetings Werner

Is it possible that the following condition is to blame:

condition:
  - condition: template
    value_template: >-
      {{ now() - timedelta(hours=18) > state_attr('automation.guten_morgen_bad',
      'last_triggered')  }}

The problem. The automation has never been executed. It is therefore not possible to compare the 18 hours.

Will now trigger the automation manually. Then I will set the condition to one hour and monitor again.

Greetings Werner

At least I understand debug a little now.

Just note, that manually triggering will not consider the condition. But you can set the state of your binary sensor in Dev Tools → States (Entwicklerwerkzeuge-> Zustände, dort: Status setzen)

1 Like

Yes I did. Now get the following result:

I’m an idiot. It dropped with copying your automation in my editor.
For testing purposes I’ve set the timedelta to 1 minute, and the automation runs flawless when triggering it with one of my motion sensors:


      {{ now() - timedelta(minutes=1) > state_attr('automation.guten_morgen_bad',
      'last_triggered')  }}

1 Like

With this setting it works fine for me. I don’t understand where the mistake was…

That will still fail if the automation has never been triggered. The left hand side of the comparison will evaluate to a datetime object but the right hand side will evaluate to None. I tested it in the Template Editor using an automation that has never been triggered (no value for last_triggered) and the result is:

TypeError: '>' not supported between instances of 'datetime.datetime' and 'NoneType'

Faulty testing procedure, because the suggested template fails for the same reason your original template did.

1 Like

For future reference, this version handles the case where last_triggered has no value. If the automation has never been triggered, default(today_at(), true) supplies a datetime object set to the current day at midnight.

{{ state_attr('automation.guten_morgen_bad', 'last_triggered') | default(today_at(), true) < today_at('05:00') }}


EDIT

Correction. Removed unwanted \u200b character from template.

2 Likes

Great !!!
Thank you all. So now I can implement it.

Greetings Werner

Oh no:
When I enter the following message comes up:

Message malformed: invalid template (TemplateSyntaxError: unexpected char ‘\u200b’ at 63) for dictionary value @ data[‘condition’][0][‘value_template’]

Message malformed: invalid template (TemplateSyntaxError: unexpected char '\u200b' at 63) for dictionary value @ data['condition'][0]['value_template']

\u200b is a “zero-width-space” in Unicode and it’s the 63rd character in the line; it’s just before the | character.

It seems that it was introduced when I copy-pasted the template into the forum post (not sure how). I have removed it from the original example.

Either delete the space before the | character (and optionally replace it with a space) or delete the entire template and copy-paste the revised example posted above.

1 Like

super. Jetzt funktioniert es.

Der erste Live-Einsatz hat wunderbar funktioniert.

Vielen Dank.

1 Like