I want a more complicate automation. I want to get the alert 30, 20 and 10 days before the expiry date. I do not want to create more datetime helpers to do that. I want to use a single automation.
One way would be to create three template sensors that are the value of the input_datetime minus 10 days, 20 days & 30 days. Then you could add those to the time trigger:
template:
sensor:
- name: Mot Mercedes minus 10 days
state: >
{{ (states.input_datetime.mot_mercedes.attributes.timestamp - 10*24*60*60) | timestamp_local }}
device_class: timestamp
- name: Mot Mercedes minus 20 days
state: >
{{ (states.input_datetime.mot_mercedes.attributes.timestamp - 20*24*60*60) | timestamp_local }}
device_class: timestamp
- name: Mot Mercedes minus 30 days
state: >
{{ (states.input_datetime.mot_mercedes.attributes.timestamp - 30*24*60*60) | timestamp_local }}
device_class: timestamp
automation:
- trigger:
- platform: time
at:
- input_datetime.mot_mercedes
- sensor.mot_mercedes_minus_10_days
- sensor.mot_mercedes_minus_20_days
- sensor.mot_mercedes_minus_30_days
...