I’m trying to follow along with a simplified approach of what is outlined above, however even though I’ve managed to get the sensor available to HA, the value I get always seems to be “unknown”
Ultimately I want to get to the same point as is outlined above, with multiple sensors for days until each garbage pick up, however for now I’ll settle for just one working. I’ve pulled this back to the most simple case I could to try and get it to work.
For completeness, I’m calling my templates.yaml
file from my configuration.yaml
file in the normal way:
template: !include templates.yaml
In my templates.yaml
file I have my garbage collection sensor I’m trying to build. One thing I’d note is that I do have some other sensors defined in here - I don’t think this is an issue but worth noting (I’ve removed most of them for brevity, but have kept one as an example just to highlight the structure of what I’m getting):
- sensor:
- name: Front Bedroom Humidity
state: "{{ state_attr('climate.bedroom', 'current_humidity') }}"
unit_of_measurement: '%'
icon: mdi:water-percent
- trigger:
- platform: time
at: "00:00:00"
action:
- service: calendar.get_events
data:
start_date_time: "{{today_at()}}"
duration:
days: 15
target:
entity_id: calendar.garbage_cycle
response_variable: agenda
sensor:
- name: "Waste Green"
state: >
{% set midnight = today_at() %}
{% set event = agenda["calendar.garbage_cycle"].events | selectattr('summary', 'search', 'Green Waste')
| map(attribute='start') | map('as_datetime') | first %}
{% set delta = (event - midnight).days %}
{{ delta }}
unit_of_measurement: "Days"
icon: mdi:leaf
Once I configure this, restart HA or reload the template entities, I get the sensor.waste_green
entity available. However it’s state is always unknown
. I’ve confirmed the service is correct from the dev tools and returns data like the below:
calendar.garbage_cycle:
events:
- start: "2024-05-23"
end: "2024-05-24"
summary: Green Waste
description: Green waste information
- start: "2024-05-23"
end: "2024-05-24"
summary: Recycling
description: Recycling Bin
- start: "2024-05-30"
end: "2024-05-31"
summary: General Waste
description: General waste red bin
- start: "2024-05-30"
end: "2024-05-31"
summary: Green Waste
description: Green waste information
I thought maybe the trigger hadn’t run, however I just set it to be a few minutes from my current time, let it run well past that but unfortuantely the trigger didn’t run then and update.
Any thoughts or help would be super appreciated.