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

problems about automation with new version of garbage-collection module #360

Closed pilot1981 closed 2 years ago

pilot1981 commented 2 years ago

Before you submit a new bug report, please check that

Write your question here

Hi, until today I always used these automation to get notification of day for garbage collection at home:

garbage_organico.yaml:

` automation: alias: "Notifica ritiro organico" trigger: platform: numeric_state entity_id: sensor.raccolta_organico_mattino value_template: "{{ state.attributes.days }}" below: 1 condition: [] action:

Sets date and time to date and time from timestamp (current date and time in this example)

- service: input_datetime.set_datetime
  data_template:
    entity_id: input_datetime.datetime_organico
    date: >
      {{ now().timestamp() | timestamp_custom("%Y-%m-%d", true) }}
    time: >
      {{ now().timestamp() | timestamp_custom("%H:%M:%S", true) }}

`

notifica_organico.yaml:

` automation:

Now, I have problem notification happen always the next day at wrong time....what I have to change?

bruxy70 commented 2 years ago

In general, I'd use the time as a trigger, and use the sensor state as a condition. The integration normally updates around the midnight, which is not very practical for getting notifications. So I'd trigger a notification in the morning at specific time, and if the days attribute is 0, send the notification. Or if you want the notification the night before, you can check every day let's say 9pm, and if days is 1, send the notification. Or you can trigger that by other things, like if you come home, or when your alarm clock goes off, when your security system gets deactivated....depending on what is available in your home automation.

pilot1981 commented 2 years ago

Hi, I need to get notification the day before garbage collection at 19 hour...what do you suggest to setup this simple automation?

bruxy70 commented 2 years ago

Set an automation triggered by time (that runs at 19:00) every day, with a condition that days is 1. Then send notification. So it will check every day but only send the notification if the collection is tomorrow. Quite simple :)

pilot1981 commented 2 years ago

I already done it!

trigger: platform: template value_template: "{{ states('sensor.date_time').replace(',', '')|as_timestamp >= state_attr('input_datetime.datetime_organico', 'timestamp') + 196060 }}"

but it don't work anymore...

bruxy70 commented 2 years ago

I do not know what this is supposed to do. Looks quite complicated and heavy. I'd keep the trigger simple.

Why don't you simply do it like that: https://www.home-assistant.io/docs/automation/trigger/#time-string

If you need to make such a complex trigger, I think last year there were some changes in HA in the past in template sensors based on the time, I think they stopped triggering the sensor update based on now(), this is why they introduced the trigger-based templates for that - so if you need that, I'd check that.

In any case, this has nothing to do with the garbage_collection integration or any version update....