Skip to content

Instantly share code, notes, and snippets.

@Didgeridrew
Created November 15, 2023 02:03
Show Gist options
  • Select an option

  • Save Didgeridrew/2894045b54fc79327b326fdba12973fe to your computer and use it in GitHub Desktop.

Select an option

Save Didgeridrew/2894045b54fc79327b326fdba12973fe to your computer and use it in GitHub Desktop.
HA - Use templated attribute dictionary for time trigger
template:
- sensor:
- name: Cat Schedule
state: '{{ now() }}'
attributes:
cat_sched: |
{{ { "07:00": 3,
"11:00": 1,
"15:00": 2,
"21:00": 2,
"23:00": 2 } }}
automation:
- alias: Cat feeder schedule
description: ""
trigger:
- platform: template
value_template: |
{% set cat_sched = state_attr('sensor.cat_schedule','cat_sched') %}
{{ now().strftime('%H:%M') in cat_sched.keys() }}
condition: []
action:
- variables:
time: "{{ now().strftime('%H:%M') }}"
cat_sched: "{{state_attr('sensor.cat_schedule','cat_sched')}}"
- service: persistent_notification.create
data:
message: |
Portion: {{ cat_sched.get(time) }}
Next Event:
{%- set keys = cat_sched.keys()|sort %}
{{- keys|first if time == keys|last
else keys|select('gt', time)|first }}
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment