I have 4 sensors for my garbage collection (general waste, glass, paper, plastic). Each of them outputs number of days until next collection.
In my dashboard I would like to display the next garbage collection and what is being collected. My jinja2 isnt very fluid so I haven’t been able to figure out how to find the lowest number of the 4 and at the same time output what is being collected.
Can anyone help me bring this code over the line so {{ list|min }} outputs for example 7 Rest.
I split them up in two strings like this {{ (stuff | min(attribute='0'))[0] }} and {{ (stuff | min(attribute='0'))[1] }}
But sometimes two different types might be collected on the same day. Do you have any ideas how I can easily display two of {{ (stuff | min(attribute='0'))[1] }} if they land on the same day?
My automation sends a notification for one or more collections, such as “Collection of garden waste and recycling today” or “Collection of household waste tomorrow”.
I have 3 time based triggers for the automation.
3 am, update sensors (id: update sensors)
4pm, notify of tomorrows collections (id: tomorrow)
7am, notify of todays collections (id: today)
The actions:
choose:
- conditions:
- condition: trigger
id: update sensors
sequence:
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.bin_collection_green_days #updating one scrape sensor updates all
default:
- variables:
# 'collections' will look like "waste" or "garden waste and recycling"
# The sensors entity names are used
collections: |-
{{
[
states.sensor.bin_collection_green_days,
states.sensor.bin_collection_recycling_days,
states.sensor.bin_collection_waste_days
]
|selectattr('state','in',['1' if trigger.id == 'tomorrow' else '0'])
|map(attribute='name')
|join(' and ')
|lower
}}
- condition: template
value_template: "{{ collections|length > 0 }}"
- service: notify.notify_residents
data:
message: Collection of {{ collections }} {{ trigger.id }}