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

Error when Holiday in Week blueprint runs #370

Closed kaizersoje closed 2 years ago

kaizersoje commented 2 years ago

Before you submit a new bug report, please check that

Describe the bug

Getting an error when the Holiday in week automation runs. I have pasted the details below. This is the automation

alias: Holiday in week - General Waste
description: ''
use_blueprint:
  path: bruxy70/holiday_in_week.yaml
  input:
    garbage_collection_entity: sensor.general_waste
    holiday_entity: calendar.garbage_collection_holidays

Configuration

"home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2022.2.9",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.9.7",
    "docker": true,
    "arch": "aarch64",
    "timezone": "Australia/Sydney",
    "os_name": "Linux",
    "os_version": "5.10.92-v8",
    "supervisor": "2022.01.1",
    "host_os": "Home Assistant OS 7.4",
    "docker_version": "20.10.9",
    "chassis": "embedded",
    "run_as_root": true
  },
  "integration_manifest": {
    "domain": "garbage_collection",
    "name": "Garbage Collection",
    "version": "4.5",
    "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.general_waste",
    "state": 2,
    "attributes": {
      "next_date": null,
      "days": null,
      "last_collection": "2022-02-22T14:13:57.738021+11:00",
      "last_updated": null,
      "device_class": "garbage_collection__schedule"
    },
    "config_entry": {
      "entry_id": "94d40f0a9614548f61c3603f4c92f696",
      "version": 4.5,
      "domain": "garbage_collection",
      "title": "General Waste",
      "data": {
        "unique_id": "55bef063-822a-4381-9910-b25ff64666b5",
        "frequency": "weekly",
        "icon_normal": "mdi:trash-can",
        "icon_today": "mdi:delete-restore",
        "icon_tomorrow": "mdi:delete-circle",
        "expire_after": "16:00",
        "verbose_format": "on {date}, in {days} days",
        "date_format": "%d-%b-%Y",
        "collection_days": [
          "tue"
        ],
        "first_month": "jan",
        "last_month": "dec",
        "manual_update": true
      },
      "options": {},
      "pref_disable_new_entities": false,
      "pref_disable_polling": false,
      "source": "user",
      "unique_id": null,
      "disabled_by": null
    }
  }
}

Debug logs

Template variable error: 'dict object' has no attribute 'event' when rendering '{{ trigger.event.data.collection_dates | count }}'
Holiday in week - General Waste: Error rendering Holiday in week - General Waste repeat count template: UndefinedError: 'dict object' has no attribute 'event'
bruxy70 commented 2 years ago

I can't replicate that, works fine here. I assume you followed the instructions, right? image

kaizersoje commented 2 years ago

Yes that's right

kaizersoje commented 2 years ago

I guess the only difference was I was using a different holidays entity first and then changed it to this one

kaizersoje commented 2 years ago

Deleted the automation and created it again. Still getting the same error after the automation runs.

image

bruxy70 commented 2 years ago

That should not matter. It complains that it does not get the event data, which it should if it was triggered by the event. So I can't explain that. If you tried to run the automation manually, then this will happen. But you don't, so I do not know why is that. You could debug the automation and see if it actually got the event data or not. But I really can't understand why it would not... image

kaizersoje commented 2 years ago

Actually, I did manually trigger it. Could that be the reason why?

kaizersoje commented 2 years ago

Triggered the automation manually. That probably is the reason why the issue occurred.

kaizersoje commented 2 years ago

I did not trigger the automation manually now. But now getting a different error.

- Holiday in week - General Waste: Repeat at step 2: Error executing script. Unexpected error for call_service at pos 2: list.remove(x): x not in list
- Holiday in week - General Waste: Error executing script. Unexpected error for repeat at pos 2: list.remove(x): x not in list
- While executing automation automation.holiday_in_week_general_waste

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 372, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 575, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1630, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1667, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/config/custom_components/garbage_collection/__init__.py", line 146, in handle_offset_date
    await entity.remove_date(collection_date)
  File "/config/custom_components/garbage_collection/sensor.py", line 548, in remove_date
    self._collection_dates.remove(collection_date)
ValueError: list.remove(x): x not in list
bruxy70 commented 2 years ago

365