Hi, I have just started using the UK Bin Collection Addon (GitHub - robbrad/UKBinCollectionData: UK Council Bin Collection Data Parser Outputting Bin Data as a JSON) and now trying to get an automation to work so I get notified the day before the bins are due. This isn’t an issue with that addon, rather than I am just new to HA and struggling to understand the automations.
From the developer tools I have the following for the sensor and I was using a trigger to be 7pm each night. The condition needs to be that next_collection is ‘tomorrow’.
Could someone please point me in the right direction? Not looking for a direct answer, just somewhere to help find the solution. Should note that at the moment, I would rather use the GUI instead of YAML while still learning!
Thanks.
It is simply not possible to do it without YAML, but it can be done by adding a template condition to the GUI.
{% set d = state_attr('sensor.home_rubbish','next_collection') %}
{% set p = strptime(d,"%Y-%m-%d") %}
{{ ((p|as_local - timedelta(days=1)).isoformat()) == today_at().isoformat() }}
This condition will evaluate to true 1 day before the date in the next_collection attribute.
As you can see if I manually change the date to 20/12/2023 - it will now evaluate to true
EDITED:
To fix the the date parsing from d/m/Y to Y-m-d
1 Like
This was working but now the template isn’t triggering. When I go into developer tools and look at the template, I get the following:
Looking at the state of that sensor, the template should be triggering today as true:
Am running 2024.1 if that makes any difference.
Thanks.
Got a bit further as seems strptime accepts a default value to added 0. Now getting a tzinfo error with the 3rd line. Anyone know whats going on here?
Thanks.
For future me, this seems to now work:
{% set binDate = strptime(state_attr('sensor.bin_home_recycling','next_collection'),"%Y-%m-%d", now()) %}
{{ ((binDate|as_local - timedelta(days=1)).isoformat()) == today_at().isoformat() }}