#calendar get_events migration and understanding what i'm doing

1 messages · Page 1 of 1 (latest)

hollow kernel
#

calendar get_events migration and some question around optimising the results/understanding the logic

#
    - name: "agenda item 1"
      unique_id: agenda_item_1
      state: >
        {% if states("sensor.agenda_item") | int > 0 %}
          {{ "- " }}{{ state_attr("sensor.agenda_item", "events")[0].summary }}
        {% else %}
          niks vandaag
        {% endif %}

    - name: "agenda item 2"
      unique_id: agenda_item_2
      state: >
        {% if states("sensor.agenda_item") | int > 1 %}
          {{ "- " }}{{ state_attr("sensor.agenda_item", "events")[1].summary }}
        {% else %}
          empty
        {% endif %}

    - name: "agenda item 3"
      unique_id: agenda_item_3
      state: >
        {% if states("sensor.agenda_item") | int > 2 %}
          {{ "- " }}{{ state_attr("sensor.agenda_item", "events")[2].summary }}
        {% else %}
          empty
        {% endif %}

    - name: "agenda item 4"
      unique_id: agenda_item_4
      state: >
        {% if states("sensor.agenda_item") | int > 3 %}
          {{ "- " }}{{ state_attr("sensor.agenda_item", "events")[3].summary }}
        {% else %}
          empty
        {% endif %}

- trigger:
    - platform: time_pattern
      hours: /1
  action:
    - service: calendar.get_events
      data:
        start_date_time: "{{ today_at() }}"
        duration:
          hours: 24
      target:
        entity_id: calendar.family
      response_variable: raw_events
    - variables:
        scneduled_events: "{{ raw_events['calendar.family'] }}"
  sensor:
    - name: "agenda_item"
      unique_id: agenda_item
      state: "{{ scheduled_events.events | count() }}"
      attributes:
        events: "{{ scheduled_events.events }}"
#

i hope this is correct... anyways, let me explain the question now... 🙂

#

i have an epaper display (in esphome) where i read out 4 (max) events that i want to display. Let's not get into the "why" 😉

#

i want to read out our family agenda and put the events in a variable like: agenda_item1, ...

#

so that i can easily match them in esphome without putting the logic there.

#

i had it working with list_events, but that's deprecated, so i'm looking for a "target" solution that works. anybody that can shed light on what i'm doing (wrong)?

#

or... how i can even TEST this

#

or maybe even better: It's how it should be... but that would look weird that this is not "optimizable"...

hollow kernel
#

nobody?

#

i will ask the first part only then, as that is the one that doesn't work anymore...

#
- trigger:
    - platform: time_pattern
      hours: /1
  action:
    - service: calendar.get_events
      data:
        start_date_time: "{{ today_at() }}"
        duration:
          hours: 24
      target:
        entity_id: calendar.family
      response_variable: raw_events
    - variables:
        scneduled_events: "{{ raw_events['calendar.family'] }}"
  sensor:
    - name: "agenda_item"
      unique_id: agenda_item
      state: "{{ scheduled_events.events | count() }}"
      attributes:
        events: "{{ scheduled_events.events }}"
#

can someone shed light why this doesn't create a sensor called "agenda_item"?

#

i've been searching for a few days already

hollow kernel
#

i'm now at this... however it still doesn't work... any clues?:

#
- trigger:
    - platform: time_pattern
      hours: /1
  action:
    - service: calendar.get_events
      data:
        start_date_time: "{{ today_at() }}"
        duration:
          hours: 24
      target:
        entity_id: calendar.family
      response_variable: scheduled_events
  sensor:
    - name: "agenda_item"
      unique_id: agenda_item
      state: "{{ scheduled_events.['calendar.family'].events | count() }}"
      attributes:
        events: "{{ scheduled_events.['calendar.family'].events }}"
hollow kernel
#

SOLVED!

#

for those who care:

#
- trigger:
    - platform: time_pattern
      minutes: /1
  action:
    - service: calendar.get_events
      data:
        start_date_time: "{{ today_at() }}"
        duration:
          hours: 24
      target:
        entity_id: calendar.family
      response_variable: agenda
  sensor:
    - name: "agenda item 1"
      unique_id: agenda_item_1
      state: >
        {% if agenda['calendar.family'].events | count() > 0 %}
          {{ "- " }}{{ agenda['calendar.family'].events[0].summary }}
        {% else %}
          niks vandaag
        {% endif %}
    - name: "agenda item 2"
      unique_id: agenda_item_2
      state: >
        {% if agenda['calendar.family'].events | count() > 1 %}
          {{ "- " }}{{ agenda['calendar.family'].events[1].summary }}
        {% else %}
          empty
        {% endif %}
    - name: "agenda item 3"
      unique_id: agenda_item_3
      state: >
        {% if agenda['calendar.family'].events | count() > 2 %}
          {{ "- " }}{{ agenda['calendar.family'].events[2].summary }}
        {% else %}
          empty
        {% endif %}
    - name: "agenda item 4"
      unique_id: agenda_item_4
      state: >
        {% if agenda['calendar.family'].events | count() > 3 %}
          {{ "- " }}{{ agenda['calendar.family'].events[3].summary }}
        {% else %}
          empty
        {% endif %}