Template Sensor Configuration for Calendar Events

I split my configuration the way I mentioned previously.

It doesn’t work, though and I’ll need more help.

What I’ve done:

  1. Created a garbage calendar (called poubelle) with a recurring event for food garbage, the next one being on the 7th at 2:30 PM and the following one on the 14th:

  1. Checked that calendar.get_events worked and that in the next 14 days I have two Poubelle verte:


(Note: I used 336 hours because the GUI doesn’t propose days but I imagine that’s not the issue in the yaml since it worked for people here before)

  1. Created /homeassistant/template.yaml and written this code:
# Creating a sensor for the next Poubelle verte event
- trigger:
  - platform: time_pattern
    seconds: /10
  action:
    - service: calendar.get_events
      target:
        entity_id: calendar.poubelles
      data:
        duration:
          days: 14
      response_variable: waste_events
    - variables:
        all_events: "{{ waste_events['calendar.poubelles'].events }}"
        food_ev: "{{ all_events | selectattr('summary', 'search', 'Poubelle verte', true) }}"
  sensor:
  - name: Poubelle verte template
    state: |
      {{ food_ev | list | count() }}
    attributes:
      scheduled_events: |
        {{ food_ev | list }}
      next_collection_date: |
        {{ (food_ev | first).start }}
      countdown: |
        {{ int((as_timestamp((food_ev | first).start) - as_timestamp(today_at('00:00')))/86400)}}

  1. Used the developer tools to check and reload all yaml configuration.

  2. Used the developer tools to check the state of sensor.poubelle_verte_template and observe that it is Unknown:

EDIT: I should probably have created a new topic and referenced this one. Is it ok to continue here, though?