Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 106305

Read Calendar Event Summary To Determine Garbage Type

$
0
0

The city I live in has rotating garbage pickup. Week 1 will be recycling and week 2 will be refuse (non-recyclables). The city publishes a Google calendar so I was able to bring this into HA (created new calendar on Google and integrated that).

I’ve read many posts on here that have been life savers and I’ve been able to get to a place where I can count the number of calendar entries and if there is 1, then it is the garbage rotation schedule. If nore than 1 then the city calendar is broken and if there is no calendar entry then do nothing.

The goal of this automation is to drive a color-coded garbage truck image on my dashboard so the kids know which they have to take care of that day (blue and grey trucks).

Here is the code I have so far that imports the calendar events.

NOTE: The notify mobile device is just being used for testing and will be removed once in production. I also count the calendar entries as a way to trap for errors once this is in production (more than 1 entry means the city calendar is fubar).

alias: Check Garbage Type
description: ""
triggers:
  - at: "01:00:00"
    trigger: time
  - trigger: homeassistant
    event: start
conditions: []
actions:
  - target:
      entity_id: calendar.the_fam
    data:
      start_date_time: "{{ today_at('00:00') + timedelta(days=1) }}"
      end_date_time: "{{ today_at('00:00') + timedelta(days=2) }}"
    response_variable: calendar_events_var
    action: calendar.get_events
  - data:
      message: >
        {% set calendar_events =
        calendar_events_var['calendar.the_fam']['events'] %}

        {% if calendar_events | count == 1 %}
          You have the following events happening tomorrow:
          {% set calendar_events = calendar_events_var['calendar.the_fam']['events'] %}
          {%- for event in calendar_events -%}
          - {{ event.summary }} at {{ (event.start | as_datetime ).strftime('%H:%M') }}
          {% endfor %}
        {% endif %}
    action: notify.mobile_app_slysiphone
  - action: input_boolean.toggle
    data: {}
    enabled: true
    target:
      entity_id: input_boolean.garbage

The goal is…

  • On a day where there is no garbage, I will display a “Welcome” banner on the dashboard.
  • On a day where there is garbage pickup, I want to display the appropriate color truck (blue or grey).

Where I am hung-up is that I need to read the contents of the event summary to determine which image to display. I wonder if someone here who has been at this longer than my 30 days can help me solve this issue. I need to be able to read the event summary text to determine which color. I am able to send myself a notification that inludes the events so I know it is successfully pulling those. The event summary for each is…

  • “Recycling and organics” for blue bin days
  • “Organics and garbage” for grey bin days

I suppose the simplest approach would be to flip a toggle and use the toggle state to determine the banner to display as I’ve shown in my code.

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 106305

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>