Trigger notification one day before a

I’m bit confused how to manage my problem:

I’ve a input_select with all 7 days option (in italian)

Domenica (sunday)

I need an automation that send me a notify (for example alexa tts announce) every week, on the day before the select_input is set, at the 20:00 h.

So if i select Lunedi (monday) , i need an automation that trigger at 20:00 on sunday (domenica) every week.

I’m not sure how to map my days that are in italian language to do this check and compare today with tomorrow-1. Any example how to manage days in HA and automations? Thanks

I’d create an automation with a condition that looks like this:

- alias: Switch Onkyo Viera and Sky Off at 02:00
  initial_state: true
    - platform: time_pattern
      hours: 20
      minutes: 0
      seconds: 0
    - condition: template
      value_template: >
        {% set days_list = ["Lunedi","Martedi","Mercoledi","Giovedi","Venerdi","Sabato","Domenica"]
        {{ days_list[as_timestamp(now()) | timestamp_custom("%w")|int] == states("")}}
    - service: tts.google_say
      entity_id: media_player.google_home_mini
        message: 'Notification goes here'

Replace with the name of your input_select

Sorry I don’t have/use Alexa so can’t help with the action, but you get the idea
Disclaimer: this is code untested :wink:

Hi thanks for example. At first view it seem the automation start at the day i’ve selected… But i need that the automation start the DAY BEFORE from what i’ve selected… Beacause i need to notify a message reminder like : “TOMORROW, remember to go…”

it still should work.
as_timestamp(now()) | timestamp_custom("%w")|int will return the day of week, starting at 0 with Sunday.
So for today this would return 3.
days_list[3] (the 4th entry) in the input_select is Giovedi
so if days_list[3] = input_select set to Giovedi (which is tomorrow) then it’ll run the action.
Hope that makes sense.

enter this in your templates editor (replacing input_select name) and check that you have a true if input_select is set to Giovedi

{% set days_list = ["Lunedi","Martedi","Mercoledi","Giovedi","Venerdi","Sabato","Domenica"]
        {{ days_list[as_timestamp(now()) | timestamp_custom("%w")|int] == states("")}}

You’re right sorry. I forgot 0 = sunday. In italy the first day is always monday so i forgot this case… Thank you i’m going to try your code thanks!

Same for me (French national living in UK) yet in this scenario it actually works in our favour :slight_smile:

I offer your a slightly different way. It’s not better than lolouk44’s solution, just a little bit different.

This calculates the current day of the week as an integer value where Sunday=0:

as_timestamp(now()) | timestamp_custom("%w")|int

So does this but Monday=0:


weekday() is defined here.

Return the day of the week as an integer, where Monday is 0 and Sunday is 6. For example, date(2002, 12, 4).weekday() == 2 , a Wednesday

Because it defines Monday=0, we have to shift the elements of days_list to satisfy the needs of your automation (trigger the day before the event). Martedi becomes the zeroth element of the array.

{% set days_list = ["Martedi","Mercoledi","Giovedi","Venerdi","Sabato","Domenica", "Lunedi"] %}

Here’s the, slightly more compact version of, value_template:

      value_template: >
        {% set days_list = ["Martedi","Mercoledi","Giovedi","Venerdi","Sabato","Domenica", "Lunedi"] %}
        {{ days_list[now().weekday()] == states("")}}
1 Like

Potayto / Potahto :smiley:

1 Like