Skip to content

Instantly share code, notes, and snippets.

@allenporter
Last active September 24, 2023 22:38
Show Gist options
  • Save allenporter/0525961046dd8eba6ac2c582319afa74 to your computer and use it in GitHub Desktop.
Save allenporter/0525961046dd8eba6ac2c582319afa74 to your computer and use it in GitHub Desktop.
Trash Sensor
- trigger:
- platform: homeassistant
event: start
- platform: time_pattern
hours: "/6"
action:
- service: calendar.list_events
target:
entity_id: calendar.personal
data:
duration:
hours: 48
minutes: 0
seconds: 0
response_variable: agenda
- alias: Find upcoming events matching trash
variables:
trash_dates: "{{ agenda | selectattr('summary', 'search', 'Trash') | map(attribute='start') | list }}"
sensor:
- name: Trash Pickup
state: >
{% if trash_dates|length > 0 %}
{% set start = strptime(trash_dates[0], "%Y-%m-%d") | as_local %}
{% set delta = start - now() %}
{% else %}
{% set delta = timedelta(days=7) %}
{% endif %}
{% if delta <= timedelta(hours=0) %}
today
{% elif delta <= timedelta(hours=24) %}
tomorrow
{% else %}
off
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment