Delay function in automations

Hi,
I added dash, but seem automation not triggered…

Are you sure it must works?

Is the automation defined directly in configuration.yaml? Or is it in another file, and if so, which?

Have you configured sensor.date_time? Do you see it in the STATES tab of the Developer Tools page? Do you also see the automation listed? If you manually trigger the automation, do the actions run as expected?

Have you tried entering the template in the Template Editor to see if it results in when it should?

Hi,
all seem to be OK!

if I start manually this automation all work fine…

I suppose there is problem triggering it…it is unable to calculate 20 hours…?!

It looks like you have sensor.date_time_iso defined, but the automation trigger uses sensor.date_time. Those are not the same.

but I defined both:


  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'date_time_utc'
      - 'date_time_iso'
      - 'time_date'

it must have to work…

Ok, but you didn’t show that in your previous reply, so I couldn’t know that. Now I do. :smiley:

Did you try entering the trigger’s template into the Template Editor, after the time it should have triggered, to see if the template renders the value True?

I found an error in sensor name, now this automation was triggered every time I restart my HA…

nothing…automation to notify not triggered…

this is the actual situation:


# datetime sensor
input_datetime:
# garbage collection addon entry to manage datetime
  only_time_organico:
    name: time_organico
    has_date: false
    has_time: true
    initial: '19:45'
  only_time_indifferenziata:
    name: time_indifferenziata
    has_date: false
    has_time: true
    initial: '19:55'
  datetime_organico:
    name: datetime_organico
    has_date: true
    has_time: true
  datetime_indifferenziata:
    name: datetime_indifferenziata
    has_date: true
    has_time: true



automation:
  alias: "Notifica ritiro indifferenziata"
  trigger:
    platform: numeric_state
    entity_id: sensor.raccolta_indifferenziata_mattino
    value_template: "{{ state.attributes.days }}"
    below: 1
  condition: []
  action:
# Sets date and time to date and time from timestamp (current date and time in this example)
    - service: input_datetime.set_datetime
      data_template:
        entity_id: input_datetime.datetime_indifferenziata
        date: >
          {{ now().timestamp() | timestamp_custom("%Y-%m-%d", true) }}
        time: >
          {{ now().timestamp() | timestamp_custom("%H:%M:%S", true) }}


automation:
- alias: "notifica il giorno dopo il ritiro indifferenziata"
  trigger:
    platform: template
    value_template: "{{ states('sensor.date_time').replace(',', '')|as_timestamp >= state_attr('input_datetime.datetime_indifferenziata', 'timestamp') + 20*60*60 }}"
#  condition: []
  condition:
    - condition: numeric_state
      entity_id: sensor.ha_runtime_in_minutes
      above: 2
  action:
    - service: notify.famiglia
      data:
        message: "Attenzione: oggi è giorno di ritiro indifferenziata."
    - service: notify.alexa_media
      data:
        target: 
          - media_player.echo_dot_di_daniele
        data:
          type: announce
        message: "Attenzione: oggi è giorno di ritiro indifferenziata."

these are value of my entity:

entity change value correctly…

Sorry it’s taken so long to reply.

Looks like input_datetime.datetime_indifferenziata does not have an initial value specified, so it defaults to the Unix Epoch, which is 1970-01-01 00:00:00. This causes the template in the trigger to evaluate to True the first time sensor.date_time changes. At that time sensor.ha_runtime_in_minutes prevents the actions from running.

At this point the trigger will not fire again until the template renders False and then True again. This is just how template triggers work.

Now, when sensor.raccolta_indifferenziata_mattino's attribute days goes below 1, the other automation should change input_datetime.datetime_indifferenziata. At that point the template in the template trigger should evaluate to False. Then, assuming input_datetime.datetime_indifferenziata doesn’t change for a while, 20 hours later the template in the template trigger should evaluate to True and the actions should run. Of course, during that 20 hour period HA must continue to run (without restarting), too.

good news! now all work fine!!!

thanks Phil

1 Like

Hi to everyone [Solved] – Using these values works well ,

I write to ask for help.

I have a automation, that everyday down the cover. But the cover goes all down. I would like that after 10s of trigger the automation, the cover stops.

I test the actions open and stop by separate, and works well, but when i try to add it together in the same automation with delay, it doesn’t work.

Please can someone help me how to do it?

thanks

Excuse my curiosity, but what sensor did you use to remind you to throw the undifferentiated?

Could you please translate this to English for the rest of the users on the forums? These forums are English only. Thanks.

1 Like