I’m trying to figure out a way to start an automation; I want the trigger to be if the state has tomorrow’s date. If you know how to do it, please feel free to share it with me
The state of which entity?
What format is it in?
Look in Developer Tools → States to get the true untranslated state.
Probably a template trigger:
trigger:
- platform: template
value_template: >
{{ (states('sensor.YOUR_ENTITY')|as_datetime).date() ==
(now()+timedelta(days=1)).date() }}
but as Tom says, without knowing the format of your entity we are guessing.
Ok, thanks, @tom_l and @Troon.
I hadn’t considered using Developer Tools → States, which could help me figure this out.
This automation triggers when it’s today’s date. It then creates an event on Google Calendar for garbage collection (plastic, residual waste, glass and metal, paper) and for mail delivery.
For future improvements, I’ll try to figure out how to not only check today’s date but maybe also 10 days ahead and create an event on Google Calendar for that day. However, that will be a later task.
Here is my automation for those who want to know. I use the following integrations:
- “Når kommer posten” (When does the mail arrive)
- “Min renovasjon” (My waste collection)
- Google Calendar
alias: Lage event i google kaleneder
description: post og restavfall
trigger:
- alias: glass og metall
platform: template
value_template: >-
{{ (states('sensor.glass_og_metall') |regex_match('\\d{2}/\\d{2}/\\d{4}'))
and (states('sensor.glass_og_metall') == (now().strftime('%d/%m/%Y')
|string).split(' ')[0]) }}
id: glass og metall
- alias: matavfall
platform: template
value_template: >-
{{ (states('sensor.matavfall') |regex_match('\\d{2}/\\d{2}/\\d{4}')) and
(states('sensor.matavfall') == (now().strftime('%d/%m/%Y')
|string).split(' ')[0]) }}
id: matavfall
- alias: papir
platform: template
value_template: >-
{{ (states('sensor.papir') |regex_match('\\d{2}/\\d{2}/\\d{4}')) and
(states('sensor.papir') == (now().strftime('%d/%m/%Y') |string).split('
')[0]) }}
id: papir
- alias: posten
platform: template
value_template: >-
{{ (states('sensor.posten_sensor_next')|as_datetime).date() ==
(now()+timedelta(days=0)).date() }}
id: posten
- alias: restavfall
platform: template
value_template: >-
{{ (states('sensor.restavfall') |regex_match('\\d{2}/\\d{2}/\\d{4}')) and
(states('sensor.restavfall') == (now().strftime('%d/%m/%Y')
|string).split(' ')[0]) }}
id: restavfall
condition: []
action:
- choose:
- conditions:
- condition: trigger
id:
- matavfall
sequence:
- service: google.create_event
target:
entity_id: calendar.posten
data:
in:
days: 0
summary: Matavfall
description: Matavfall
- conditions:
- condition: trigger
id:
- restavfall
sequence:
- service: google.create_event
target:
entity_id: calendar.posten
data:
in:
days: 0
summary: Restavfall
description: Restavfall
- conditions:
- condition: trigger
id:
- glass og metall
sequence:
- service: google.create_event
target:
entity_id: calendar.posten
data:
in:
days: 0
summary: Glass og Metall
description: Glass og Metall
- conditions:
- condition: trigger
id:
- papir
sequence:
- service: google.create_event
target:
entity_id: calendar.posten
data:
in:
days: 0
summary: Papir
description: Papir
- conditions:
- condition: trigger
id:
- posten
sequence:
- service: google.create_event
target:
entity_id: calendar.posten
data:
summary: posten
description: posten
in:
days: 0
mode: single