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

Date already on the collection schedule #390

Closed a323870 closed 2 years ago

a323870 commented 2 years ago

Before you submit a new bug report, please check that

Describe the bug

Thanks for this addon which I enjoyed very much. I created a sensor with blank frequency, manual update and related automation to add dates. At the run of the new day I get date error already present.

No error when restart ha and the date is addesd.

Am I wrong something? Thanks.

My automation is :

Configuration

{
  "home_assistant": {
    "installation_type": "Home Assistant Core",
    "version": "2022.4.5",
    "dev": false,
    "hassio": false,
    "virtualenv": true,
    "python_version": "3.9.11",
    "docker": false,
    "arch": "aarch64",
    "timezone": "Europe/Rome",
    "os_name": "Linux",
    "os_version": "5.15.32-v8+",
    "run_as_root": false
  },
  "custom_components": {
    "garbage_collection": {
      "version": "4.6",
      "requirements": [
        "python-dateutil>=2.8.2"
      ]
    },
    "authenticated": {
      "version": "0.0.0",
      "requirements": []
    }
  },
  "integration_manifest": {
    "domain": "garbage_collection",
    "name": "Garbage Collection",
    "version": "4.6",
    "documentation": "https://github.com/bruxy70/Garbage-Collection/",
    "issue_tracker": "https://github.com/bruxy70/Garbage-Collection/issues",
    "iot_class": "calculated",
    "dependencies": [],
    "config_flow": true,
    "codeowners": [
      "@bruxy70"
    ],
    "requirements": [
      "python-dateutil>=2.8.2"
    ],
    "is_built_in": false
  },
  "data": {
    "entity_id": "sensor.veritas_ecomobile",
    "state": "il 30/04, tra 11 giorni",
    "attributes": {
      "next_date": "2022-04-30T00:00:00+02:00",
      "days": 11,
      "last_collection": null,
      "last_updated": "2022-04-19T10:00:23.800331+02:00",
      "device_class": "garbage_collection__schedule"
    },
    "config_entry": {
      "entry_id": "03dd234b4afe712057fb1311c6ce4c4e",
      "version": 4.5,
      "domain": "garbage_collection",
      "title": "Veritas EcoMobile",
      "data": {
        "unique_id": "bd66e837-8418-47d1-9fec-1b960fd8a1b3",
        "frequency": "blank",
        "icon_normal": "mdi:trash-can",
        "icon_today": "mdi:delete-restore",
        "icon_tomorrow": "mdi:delete-circle",
        "verbose_state": true,
        "manual_update": true,
        "expire_after": "12:00",
        "verbose_format": "il {date}, tra {days} giorni",
        "date_format": "%d/%m"
      },
      "options": {},
      "pref_disable_new_entities": false,
      "pref_disable_polling": false,
      "source": "user",
      "unique_id": null,
      "disabled_by": null
    }
  }
}

Debug logs

2022-04-18 00:00:03 ERROR (MainThread) [custom_components.garbage_collection.sensor] 2022-01-17 not added to Veritas EcoMobile - already on the collection schedule
2022-04-18 00:00:03 ERROR (MainThread) [custom_components.garbage_collection.sensor] 2022-02-21 not added to Veritas EcoMobile - already on the collection schedule
2022-04-18 00:00:03 ERROR (MainThread) [custom_components.garbage_collection.sensor] 2022-03-21 not added to Veritas EcoMobile - already on the collection schedule
2022-04-18 00:00:03 ERROR (MainThread) [custom_components.garbage_collection.sensor] 2022-04-30 not added to Veritas EcoMobile - already on the collection schedule
2022-04-18 00:00:03 ERROR (MainThread) [custom_components.garbage_collection.sensor] 2022-05-16 not added to Veritas EcoMobile - already on the collection schedule
2022-04-18 00:00:03 ERROR (MainThread) [custom_components.garbage_collection.sensor] 2022-06-20 not added to Veritas EcoMobile - already on the collection schedule
2022-04-18 00:00:03 ERROR (MainThread) [custom_components.garbage_collection.sensor] 2022-07-18 not added to Veritas EcoMobile - already on the collection schedule
2022-04-18 00:00:03 ERROR (MainThread) [custom_components.garbage_collection.sensor] 2022-08-30 not added to Veritas EcoMobile - already on the collection schedule
2022-04-18 00:00:03 ERROR (MainThread) [custom_components.garbage_collection.sensor] 2022-09-19 not added to Veritas EcoMobile - already on the collection schedule
2022-04-18 00:00:03 ERROR (MainThread) [custom_components.garbage_collection.sensor] 2022-10-17 not added to Veritas EcoMobile - already on the collection schedule
2022-04-18 00:00:03 ERROR (MainThread) [custom_components.garbage_collection.sensor] 2022-11-21 not added to Veritas EcoMobile - already on the collection schedule
2022-04-18 00:00:03 ERROR (MainThread) [custom_components.garbage_collection.sensor] 2022-12-19 not added to Veritas EcoMobile - already on the collection schedule
bruxy70 commented 2 years ago

Not sure what's the issue, looks all right. The automation is triggered when the entity is recalculated, and it has blank frequency, so it should not contain any dates - so there should be no conflicts. Did you try the include blueprint? It does exactly the same. https://github.com/bruxy70/Garbage-Collection#include-and-exclude Or you can check the automation in the debug to see when it is called, and if it is called with any dates already added in. Is it only called once? Are you sure you do not have another automation that does the same? It basically says that you are trying to add a date that has already been added previsly. So I guess the date is in, the question is why is it trying to add it multiple times...

a323870 commented 2 years ago

My hypothesis is that at the change of the day for the sensors with "blank" frequency the dates are not reset. In my automation I have 8 garbage sensors, three of which are manually updated. Two are "blank" and one "every-n-weeks" For these sensors I have created automation with "garbage_collection_loaded" event. The sensor with "every-n-weeks" frequency adds the dates when the day changes without mistakes, while the two with "blank" report the date error already present.

For verification I activated the DEBUG and restarted HA. The automations are called up at start-up at 2:00 pm without mistakes and at the change of day at 00:00 with error for sensor "blank"

In the docx details and debug log.

Tanks for any idea Garbage.docx .

bruxy70 commented 2 years ago

Thanks. I have configured that, will see what it does at night. In the meantime, whilst you are in the debug, can you go to Changed Variable and tell me what is in the trigger/event/data/collection_dates. This should show the "calculated" dates that the automation is changing. And since this is "blank", the list should be empty. And I suppose it is not - this is why it reports that the date already exists...

image
a323870 commented 2 years ago

For Ecomobile, "blank"

this: entity_id: automation.veritas_date_aggiuntive_ecomobile state: 'on' attributes: last_triggered: '2022-04-19T12:01:28.858070+00:00' mode: single current: 0 id: veritas_date_aggiuntive_ecomobile friendly_name: Veritas Date Aggiuntive Ecomobile last_changed: '2022-04-19T12:01:08.879366+00:00' last_updated: '2022-04-19T12:01:28.929129+00:00' context: id: 5aa899c2ea9bfeb187899083935538b3 parent_id: 8171e7b4cd022cfbbf753f216a17a3e3 user_id: null trigger: id: '0' idx: '0' platform: event event: event_type: garbage_collection_loaded data: entity_id: sensor.veritas_ecomobile collection_dates:

for "verde" there are caluculated date and not the included date 2022-01-17, 2022-02-21, 2022-12-30

this: entity_id: automation.veritas_date_aggiuntive_verde state: 'on' attributes: last_triggered: '2022-04-19T12:01:28.856670+00:00' mode: single current: 0 id: veritas_date_aggiuntive_verde friendly_name: Veritas Date Aggiuntive Verde last_changed: '2022-04-19T12:01:08.878941+00:00' last_updated: '2022-04-19T12:01:28.897207+00:00' context: id: b01cbada684f2b8890cedae2cb55e508 parent_id: 4a136db018ccbae9adc1870fcda64c08 user_id: null trigger: id: '0' idx: '0' platform: event event: event_type: garbage_collection_loaded data: entity_id: sensor.veritas_verde_ramaglie collection_dates:

could it be given by utc and local time?

bruxy70 commented 2 years ago

I can confirm that I did observe the same issue in testing. Looking for the cause...

a323870 commented 2 years ago

Confirm, New version of sensor.py resolve the problem. Tanks.