One minute before date input

good evening,
there is a way to start an automation one minute before an hour set with input datetime without creating a new input datetime

You can do that with AppDaemon using this https://appdaemon.readthedocs.io/en/dev/AD_API_REFERENCE.html#appdaemon.adapi.ADAPI.run_at

Thanks for the help Humberto,
but I wouldn’t know how to apply this command in HA

Sorry

You don’t say if the input_datetime has both date & time. You’re also pretty vague on what values the input_datetime may be set to, and how to use it (i.e., just the hour? the whole value? …???) Maybe something like:

- trigger:
    platform: template
    value_template: >
      {{ states('sensor.date_time') ==
         (state_attr('input_datetime.x', 'timestamp') - 60)
         |timestamp_custom('%y-%m-%d, %H:%M') }}

This would trigger one minute before the date/time set in the input_datetime, assuming it has both date and time, and effectively ignoring the seconds.

1 Like

You’re right, Humberto.
input datetime I use it only as time.
in practice I should create a new automation that starts a minute earlier based on the automation of which I added the code below:

- alias: Chiusura tapparelle ogni giorno dopo il tramonto 
  trigger:
    platform: state
    entity_id: sun.sun
    to: 'below_horizon'
    for:
      minutes: "{{ states('input_number.offset_dopo_tramonto') | int }}"

I have tryed this but dosen’t work:

- alias: Avviso 1 minuto prima della apertura tapparelle
  trigger:
  - platform: template
    value_template: >
      {{ states('sensor.date_time') ==
         (state_attr('input_datetime.opshutfestivi', 'timestamp') - 60)
         |timestamp_custom('%H:%M') }}

I said:

Is that true?

…
only time

Then that means my suggestion wouldn’t work. I do see you modified it, but incorrectly. In this case, sensor.date_time is not the correct sensor to use. You should use sensor.time instead. Also the values for timestamp_custom need to be changed. Try:

- alias: Avviso 1 minuto prima della apertura tapparelle
  trigger:
  - platform: template
    value_template: >
      {{ states('sensor.time') ==
         (state_attr('input_datetime.opshutfestivi', 'timestamp') - 60)
         |timestamp_custom('%H:%M', false) }}

And don’t forget you need to define sensor.time.

1 Like

Yeah !!
this work Phil … many many thanks

1 Like