Automation triggers, actions not executed

Hi everybody,

can you please take a look at my automation below and tell me what’s wrong with it?

It is supposed to trigger after 05:00:00, then turn on a boolean; this boolean will be off at that time, because it gets turned off by that automation at 03:00:00.

Then, when the boolean turns on, some actions are supposed to be executed. The automation triggers, but nothing happens; however, if I go to the automation editor and manually run the actions, they do work. So why won’t they run when the automation is triggered?

Thank you for your input :slight_smile:

alias: Guten Morgen
description: ""
trigger:
  - platform: time
    at: "03:00:00"
    alias: 03:00 Uhr Boolean Aus
    id: aus
  - alias: Boolean Ein
    platform: state
    entity_id:
      - input_boolean.guten_morgen
    to: "on"
    id: gutenmorgen
    from: "off"
  - platform: state
    entity_id:
      - binary_sensor.unten_kueche_presence_presence
    from: "off"
    to: "on"
    id: kuechemotion
    alias: Küche Motion
condition: []
action:
  - if:
      - condition: trigger
        id:
          - aus
    then:
      - service: input_boolean.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: input_boolean.guten_morgen
    alias: Boolean Aus
  - alias: Boolean Ein
    if:
      - condition: trigger
        id:
          - gutenmorgen
    then:
      - service: cover.set_cover_position
        data:
          position: "{{ states(\"input_number.unten_wohnzimmer_rollo_auf\") }}"
        target:
          entity_id: cover.unten_wohnzimmer
      - service: cover.set_cover_position
        data:
          position: >
            {{
            states('input_number.unten_arbeitszimmer_rollerblinds_alle_morgens_hoch')
            | int }}
        target:
          entity_id:
            - cover.unten_arbeitszimmer_rollorblinds_vorne
            - cover.unten_arbeitszimmer_rollorblinds_mitte
      - service: cover.set_cover_position
        data:
          position: "{{ states(\"input_number.unten_arbeitszimmer_rollo_auf\") }}"
        target:
          entity_id: >-
            cover.unten_arbeitszimmer_vorne, cover.unten_arbeitszimmer_mitte,
            cover.unten_arbeitszimmer_strasse
      - service: cover.set_cover_position
        data:
          position: >
            {{ states('input_number.unten_kuche_rollerblinds_morgens_hoch') |
            int }}
        target:
          entity_id: cover.unten_kueche_rollerblinds
      - service: cover.set_cover_position
        data:
          position: |
            {{ states('input_number.unten_kueche_rollo_auf') | int }}
        target:
          entity_id: cover.unten_kueche
  - alias: Küche Motion
    if:
      - condition: and
        conditions:
          - condition: trigger
            id:
              - kuechemotion
          - condition: time
            after: "05:00:00"
            before: "00:00:00"
    then:
      - service: input_boolean.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: input_boolean.guten_morgen
mode: single

Look at the automation trace to see what’s happening.

I suspect this:

          - condition: time
            after: "05:00:00"
            before: "00:00:00"

will always be false.

1 Like

Thank you!

I didn’t want a before 00:00:00 at all; I thought that I had deleted those numbers, but it seems like the zeros get inserted automatically when there is nothing there. So I removed that line via yaml, so hopefully it’ll work tomorrow morning.

I think you should make it 23:59:59.
00:00:00 is usually the start of the day, and I assume nothing means 00:00:00 also.

1 Like

If the purpose of your input boolean is to make sure the automation only runs once per day, then this is probably simpler.

Triggers from kitchen motion, only proceeds if:

  • it’s after 05:00
  • the last automation run date isn’t the same as today’s date.

I’m using a shorthand template condition for the last run check. The 0|as_datetime is the default value to use if the automation has never run before.

alias: Guten Morgen
description: ""
trigger:
  - platform: state
    entity_id: binary_sensor.unten_kueche_presence_presence
    from: "off"
    to: "on"
condition:
  - condition: time
    after: "05:00"
  - "{{ (this.attributes.last_triggered|as_datetime(0|as_datetime)).date() != now().date() }}"
action:
  - service: cover.set_cover_position
    data:
      position: "{{ states('input_number.unten_wohnzimmer_rollo_auf') }}"
    target:
      entity_id: cover.unten_wohnzimmer
  - service: cover.set_cover_position
    data:
      position: "{{ states('input_number.unten_arbeitszimmer_rollerblinds_alle_morgens_hoch') }}"
    target:
      entity_id:
        - cover.unten_arbeitszimmer_rollorblinds_vorne
        - cover.unten_arbeitszimmer_rollorblinds_mitte
  - service: cover.set_cover_position
    data:
      position: "{{ states('input_number.unten_arbeitszimmer_rollo_auf') }}"
    target:
      entity_id:
        - cover.unten_arbeitszimmer_vorne
        - cover.unten_arbeitszimmer_mitte
        - cover.unten_arbeitszimmer_strasse
  - service: cover.set_cover_position
    data:
      position: "{{ states('input_number.unten_kuche_rollerblinds_morgens_hoch') }}"
    target:
      entity_id: cover.unten_kueche_rollerblinds
  - service: cover.set_cover_position
    data:
      position: "{{ states('input_number.unten_kueche_rollo_auf') }}"
    target:
      entity_id: cover.unten_kueche
mode: single
1 Like

Thank you! That looks interesting and I’ve learned the 0|as_datetime method.

Leaving out “00:00:00” did not work, so I’ll see what this does tomorrow :slight_smile:

The as_datetime filter converts an ISO-format date string or a UNIX timestamp to a datetime object.

If your automation has run before, then this.attributes.last_triggered will have an ISO-format date string, and it’ll be able to convert it just fine.

If it hasn’t run before, then this.attributes.last_triggered will be None, and the as_datetime filter will not be able to turn that into a datetime object.

For situations like that, it also takes a default value to use when conversion fails. This default value must also be a datetime object, and in this situation we do want the automation to run so the date must not be today’s date.

0|as_datetime says “convert the UNIX timestamp 0 to a datetime object”, which will be back in 1970:

and we use that as the default datetime object: quick and easy to create, and a long time ago.

1 Like