Hello all,
I do consults at various properties throughout the day, and I’m trying to make a card that shows when I have to leave for my next appointment, like this:
(context for card - that’s an appointment that starts at 20:00, and finishes at 21:00 and it’s 20:59 when I made the screenshot)
Mostly this all works, but I have a couple bugs still and I was hoping someone might point me in the right direction.
My templates/project works great if there is not a current appointment. i.e. nothing on schedule “now”, but looking forward at the next appointment.
My problem is that once an appointment starts my templates still focuses on the current appointment, and I need them to look at the next appointment as soon as the “start time” has passed.
Here is my foundational template. I have others, but all they do is manipulate the event that this one grabs from the schedule.
YAML
- trigger:
- platform: homeassistant
event: start
- platform: time_pattern
hours: "/6"
- trigger: state
entity_id:
- input_button.update_next_event
action:
- action: calendar.get_events
target:
entity_id: calendar.personal_calender
data:
duration:
hours: 168
minutes: 0
seconds: 0
response_variable: agenda
- alias: Find upcoming events with locations
variables:
upcoming: "{{ agenda['calendar.personal_calender']['events'] | rejectattr('location', 'undefined') | list }}"
sensor:
- name: "Next Location"
state: >
{% if upcoming|length > 0 %}
{{ upcoming[0].location }}
{% endif %}
- name: "Next Location Summary"
state: >
{% if upcoming|length > 0 %}
{{ upcoming[0].summary }}
{% endif %}
- name: "Next Location Start"
state: >
{% if upcoming|length > 0 %}
{{ upcoming[0].start }}
{% endif %}
device_class: timestamp
Reading the docs for calendar.get_events
, I thought it is supposed to only grab events that start after now by default, however it seems to include events that are currently occurring. I may misunderstand that one.
I think I need to add something to the if
of each sensor to compare the start time to “now”, but I’m not sure how to approach that and haven’t found a relatable example.
I have a related template question if I may…
- In the above template, what does the [0] after upcoming do?
Thank you!