I retrieve events from calendars and need to put them into a sensor(*) which is then retrieved by an unrelated application via a WebSocket connection to HA.
The way I do this today is rather convoluted (but it works)
- I call the
list_events
service and set the response field - I raise an event with this response field contents (
calendarResponseEvent
) - I configured in
configuration.yaml
- trigger:
- platform: event
event_type: calendarResponseEvent
sensor:
- name: calendarW
unique_id: calendarW
state: "{{ trigger.event.data.response.events | count() }}"
attributes:
calendar_response: "{{ trigger.event.data.response }}"
icon: mdi:calendar
This ultimately sets the sensor to the number of calendar entries, and its attributes to the future calendar entries
I will be switching from list_events
to get_events
(list_events
is deprecated) so I decided to simplify all of this because it took me a shameful time to understand what was going on with the calendar sensor (I set it up a year or two ago and forgot in the meantime what I did)
My question: is there a way to directly populate a sensor from within an automation with the content of the answer of a service? (by “directly” I mean within the automation itself). I would create the sensor as a sensor template helper (I think)
(*) any better ideas are welcome