自定义 Home Assistant 传感器,用于计划垃圾收集 (或其他定期重复发生的事件 - 指定日期每周一次,每隔半周或每月一次)
自定义 Home Assistant 传感器,用于计划垃圾收集 (或其他定期重复发生的事件 - 指定日期每周一次,每隔半周或每月一次)
Home Assistant has introduced local calendars in 2022, in the 2023.1 release they added an option for different recurent events. With this, most of the functionality of this custom helper is supported natively. So I will end developing and supporting this helper in 2023.
The garbage_collection component is a Home Assistant helper that creates a custom sensor for monitoring a regular garbage collection schedule. The sensor can be configured for a number of different patterns:
weekly schedule (including multiple collection days, e.g. on Tuesday and Thursday)every-n-weeks repeats every period of weeks, starting from the week number first_week. It uses the week number - therefore, it restarts each year, as the weeks start from number 1 each year.even-weeks or odd-weeks (technically, it is the same as every 2 weeks with 1st or 2nd first_week)every-n-days (repeats regularly from the given first date). If n is a multiply of 7, it works similar to every-n-weeks, with the difference that it does not use the week numbers (that restart each year) but continues infinitely from the initial date.monthly schedule (nth weekday each month), or a specific weekday of each nth week. Using the period it could also be every 2nd, 3rd etc month.annually (e.g. birthdays). This is once per year. Using include dates, you can add additional dates manually.blank does not automatically schedule any collections - to be used in cases where you want to make completely own schedule with manual_update.You can also configure seasonal calendars (e.g. for bio-waste collection), by configuring the first and last month.
And you can group entities, which will merge multiple schedules into one sensor.
These are some examples using this sensor. The Lovelace config examples are included below.
custom_components/garbage_collection directory
into the custom_components directory of your Home Assistant
installation.garbage_collection helper.garbage_collection helper.Go to Settings/Devices & Services/Helpers, click on the + CREATE HELPER button, select Garbage Collection and configure the helper.
If you would like to add more than one collection schedule, click on the + CREATE HELPER button again and add another Garbage Collection helper instance.
The configuration hapend in 2 steps. In the first step, you select the frequency and common parameters. In the second step you configure additional parameters depending on the selected frequency.
The configuration via configuration.yaml has been deprecated. If you have previously configured the integration there, it will be imported to ConfigFlow, and you should remove it.
| Parameter | Required | Description |
|---|---|---|
Friendly name |
Yes | Sensor friendly name |
Frequency |
Yes | "weekly", "even-weeks", "odd-weeks", "every-n-weeks", "every-n-days", "monthly", "annual", "group" or "blank" |
Icon |
No | Default icon Default: mdi:trash-can |
Icon today |
No | Icon if the collection is today Default: mdi:delete-restore |
Icon tomorrow |
No | Icon if the collection is tomorrow Default: mdi:delete-circle |
Expire After |
No | Time in format format HH:MM. If the collection is due today, start looking for the next occurence after this time (i.e. if the weekly collection is in the morning, change the state from 'today' to next week in the afternoon) |
Verbose state |
No | The sensor state will show collection date and remaining days, instead of number. |
| Obsolete - do the formatting on the dashboard instead. | ||
Default: False |
||
Hidde in calendar |
No | Hide in calendar (useful for sensors that are used in groups) |
Default: False |
||
Manual update |
No | (Advanced). Do not automatically update the status. Status is updated manualy by calling the service garbage_collection.update_state from an automation triggered by event garbage_collection_loaded, that could manually add or remove collection dates, and manually trigger the state update at the end. See the example.Default: False |
Verbose format |
No | (relevant when verbose state is True). Verbose status formatting string. Can use placeholders {date} and {days} to show the date of next collection and remaining days. |
| Obsolete - do the formatting on the dashboard instead. | ||
Default: 'on {date}, in {days} days'When the collection is today or tomorrow, it will show Today or Tomorrow__(currently in English, French, Czech and Italian). |
||
Date format |
No | In the verbose format, you can configure the format of date (using strftime format) |
| Obsolete - do the formatting on the dashboard instead. | ||
Default: '%d-%b-%Y' |
| Parameter | Required | Description |
|---|---|---|
First month |
No | Month three letter abbreviation, e.g. "jan", "feb"... |
Default: "jan" |
||
Last month |
No | Month three letter abbreviation. |
Default: "dec" |
| Parameter | Required | Description |
|---|---|---|
Collection days |
Yes | Day three letter abbreviation, list of "mon", "tue", "wed", "thu", "fri", "sat", "sun". |
| Parameter | Required | Description |
|---|
暂无开放 Issues,或尚未同步最近议题。