bruxy70 / Garbage-Collection

🗑 Custom Home Assistant sensor for scheduling garbage collection (or other regularly re-occurring events - weekly on given days, semi-weekly or monthly)
MIT License
382 stars 90 forks source link

How to use calendar trigger for collection reminder? Is this a HA bug? #407

Closed alexeiw123 closed 2 years ago

alexeiw123 commented 2 years ago

Before you submit a new bug report, please check that

Write your question here

I have a notification for bin day that I'd like to trigger form the calendar notification. With testing I have been unable to achieve this, my test triggers are below, these were built using the UI. I suspect I've stumbled across a big with either the trigger, the offset or how it handles all day calendar events. I thought I'd start here in case it's specific to this integration.

trigger:
  - platform: calendar
    event: start
    offset: '-6:0:0'
    entity_id: calendar.garbage_collection
  - platform: calendar
    event: start
    offset: '0:0:0'
    entity_id: calendar.garbage_collection

I am able to to successfully trigger a notification using a template trigger, but this presents it's own issues for repeat notifications when HA reboots.

trigger:
  - platform: template
    value_template: |
      {% if state_attr('calendar.garbage_collection','start_time') != none %}
        {% set start = state_attr('calendar.garbage_collection','start_time')|as_datetime|as_local %}
        {{ start - now() < timedelta(hours=12) }}
      {% endif %}
bruxy70 commented 2 years ago

Given the garbage collection entity state always change on midnight, working with templates and offsets seems quite complicated overkill to me. You already know when the state is going to change - midnight. So just create a simple automation triggered at the time you want to receive the notification (so instead of offset -6 hours, trigger it at 18:00). And in the condition just check that the collection is due tomorrow (days == 1 or state == 1).

alexeiw123 commented 2 years ago

Given the garbage collection entity state always change on midnight, working with templates and offsets seems quite complicated overkill to me. You already know when the state is going to change - midnight. So just create a simple automation triggered at the time you want to receive the notification (so instead of offset -6 hours, trigger it at 18:00). And in the condition just check that the collection is due tomorrow (days == 1 or state == 1).

That makes a lot of sense. I thought my way was easy then encountered an issue and just got tunnel vision to that method. This will be much simpler. I think there is a bug here but most likely not with this integration.