HI,
I have the following 4 sensors:
sensor.trash_gft:
hidden: true
sensor.trash_papier:
hidden: true
sensor.trash_plastic_verpakkingsafval:
hidden: true
sensor.trash_restafval:
hidden: true
template_sensors calculate the collection date for these:
- platform: template
sensors:
trash_restafval_date:
friendly_name: 'Restafval'
value_template: '{{ as_timestamp(states.sensor.trash_restafval.state)
| timestamp_custom("%A %d %B") }}'
trash_plastic_verpakkingsafval_date:
friendly_name: 'Plastic'
value_template: '{{ as_timestamp(states.sensor.trash_plastic_verpakkingsafval.state)
| timestamp_custom("%A %d %B") }}'
trash_gft_date:
friendly_name: 'Gft'
value_template: '{{ as_timestamp(states.sensor.trash_gft.state)
| timestamp_custom("%A %d %B") }}'
trash_papier_date:
friendly_name: 'Papier'
value_template: '{{ as_timestamp(states.sensor.trash_papier.state)
| timestamp_custom("%A %d %B") }}'
separate automations warn if one of the trash collects is at hand the next day, with trash_name hard coded in the automation.
automation:
- alias: 'Trash - Restafval'
trigger:
- platform: time
hours: 20
minutes: 0
seconds: 0
condition:
- condition: template
value_template: '{{ now().strftime("%Y-%m-%d") ==
(as_timestamp(states.sensor.trash_restafval.state) -
(24*3600)) | timestamp_custom("%Y-%m-%d") }}'
action:
- service: notify.notify
data_template:
message: 'Het is vandaag - {{ now().strftime("%Y-%m-%d") }}.
Restafval wordt morgen opgehaald!.'
I was wondering if it would be possible to create 1 automation, where the name of the trash sensor is automatically imported somehow, and creates a persistent notification for today’s trash {{trash_name}} collection:
- alias: 'Today: Trash'
trigger:
- platform: time
hours: 07
minutes: 0
seconds: 0
condition:
- condition: template
value_template: '{{ now().strftime("%Y-%m-%d") ==
(as_timestamp(states.sensor.trash_{{trash_name}}.state)
| timestamp_custom("%Y-%m-%d") }}'
action:
- service: notify.notify
data_template:
message: 'Het is vandaag - {{ now().strftime("%Y-%m-%d") }}.
{{trash_name}} wordt opgehaald!.'
- service: persistent_notification.create
data_template:
message: 'Today - {{ now().strftime("%Y-%m-%d") }}.
{{trash_name}} is collected!.'
Hope you can have a look,
Thanks,
Marius