nielsfaber / scheduler-component

Custom component for HA that enables the creation of scheduler entities
GNU General Public License v3.0
631 stars 41 forks source link

KeyError: 'service' in Scheduler Component after Home Assistant 2024.8.0 Update #372

Closed nima-1102 closed 1 month ago

nima-1102 commented 1 month ago

Checklist

Expected behavior

The Scheduler component should function normally after updating Home Assistant from 2024.7.4 to 2024.8.0.

Actual behavior

After updating Home Assistant from 2024.7.4 to 2024.8.0, the Scheduler component is throwing errors. The error message indicates a KeyError for 'service' in the actions.py file.

Error Log

This error originated from a custom integration.
Logger: homeassistant
Source: custom_components/scheduler/actions.py:441
integration: Scheduler (documentation, issues)
First occurred: 04:44:46 (18 occurrences)
Last logged: 07:19:17
Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/config/custom_components/scheduler/actions.py", line 396, in async_entity_changed
    await self.async_process_queue()
  File "/config/custom_components/scheduler/actions.py", line 479, in async_process_queue
    if self.queue_busy or not self.is_available():
                              ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/scheduler/actions.py", line 441, in is_available
    required_services = [action[CONF_SERVICE] for action in self._queue]
                         ~~~~~~^^^^^^^^^^^^^^
KeyError: 'service'

Steps to Reproduce

  1. Update Home Assistant from version 2024.7.4 to 2024.8.0
  2. Use the Scheduler component
  3. Check Home Assistant logs

Environment

Additional Information

I have multiple Schedulers in production. The error started occurring immediately after the Home Assistant update.

nielsfaber commented 1 month ago

In HA 2024.8 ‘service’ was renamed to ’action’. This is a breaking change (however not communicated as breaking change) done by HA. I did not have the chance yet to update this integration for the changes, at the moment I cannot give any solution other than to roll back to HA 2024.7.

nielsfaber commented 1 month ago

I have updated my local HA version to 2024.8 to test this issue. However for me this error does not occur and the schedules are executing the tasks as they should. Do you experience this issue with all your schedules, or one in particular? Could you try pinpointing it to one (or more) schedule by turning all schedules off and then turning one on?

petebanham commented 1 month ago

I have this issue as well since the latest HA version. I only have one schedule that is controlling climate entities. Happy to test a fix if that helps.

nielsfaber commented 1 month ago

@petebanham Could you share the contents of your scheduler.storage file which is located in the .storage subfolder of the HA configuration directory (the folder which has the configuration.yaml)? With that I could hopefully reproduce exactly the same scenario.

petebanham commented 1 month ago

@petebanham Could you share the contents of your scheduler.storage file which is located in the .storage subfolder of the HA configuration directory (the folder which has the configuration.yaml)? With that I could hopefully reproduce exactly the same scenario.

Here you go:

{
  "version": 3,
  "minor_version": 1,
  "key": "scheduler.storage",
  "data": {
    "schedules": [
      {
        "schedule_id": "9e33a2",
        "timeslots": [
          {
            "start": "00:00:00",
            "stop": "06:00:00",
            "conditions": [],
            "condition_type": null,
            "track_conditions": false,
            "actions": [
              {
                "service": "climate.set_temperature",
                "entity_id": "climate.zone1_climate",
                "service_data": {
                  "hvac_mode": "heat",
                  "temperature": 18.5
                }
              }
            ]
          },
          {
            "start": "06:00:00",
            "stop": "12:00:00",
            "conditions": [],
            "condition_type": null,
            "track_conditions": false,
            "actions": [
              {
                "service": "climate.set_temperature",
                "entity_id": "climate.zone1_climate",
                "service_data": {
                  "hvac_mode": "heat",
                  "temperature": 19.5
                }
              }
            ]
          },
          {
            "start": "12:00:00",
            "stop": "22:10:00",
            "conditions": [],
            "condition_type": null,
            "track_conditions": false,
            "actions": [
              {
                "service": "climate.set_temperature",
                "entity_id": "climate.zone1_climate",
                "service_data": {
                  "hvac_mode": "heat",
                  "temperature": 20
                }
              }
            ]
          },
          {
            "start": "22:10:00",
            "stop": "00:00:00",
            "conditions": [],
            "condition_type": null,
            "track_conditions": false,
            "actions": [
              {
                "service": "climate.set_temperature",
                "entity_id": "climate.zone1_climate",
                "service_data": {
                  "hvac_mode": "heat",
                  "temperature": 18.5
                }
              }
            ]
          }
        ],
        "weekdays": [
          "daily"
        ],
        "start_date": null,
        "end_date": null,
        "repeat_type": "repeat",
        "name": "Heating",
        "enabled": true
      }
    ],
    "tags": []
  }
}
nima-1102 commented 1 month ago

I have updated my local HA version to 2024.8 to test this issue. However for me this error does not occur and the schedules are executing the tasks as they should. Do you experience this issue with all your schedules, or one in particular? Could you try pinpointing it to one (or more) schedule by turning all schedules off and then turning one on?

I have around 60 schedulers, but was able to narrow it down thanks to the logbook. In my basement I have a temperature sensor that switches a dehumidifier on/off when the humidity is < 76% or > 82%. I have 2 schedules for this. Unfortunately, the WiFi reception is not that good there, so the connection seems to break off from time to time, and the error message always appears.

Screenshot from 2024-08-10 09-08-57 Screenshot from 2024-08-10 09-08-44

turned off
06:05:59 - 3 hours ago
became unavailable
06:05:59 - 3 hours ago
turned off
00:56:42 - 8 hours ago
2024-08-10 06:05:59.839 ERROR (Recorder) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
File "/config/custom_components/scheduler/actions.py", line 396, in async_entity_changed
await self.async_process_queue()
File "/config/custom_components/scheduler/actions.py", line 479, in async_process_queue
if self.queue_busy or not self.is_available():
^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/scheduler/actions.py", line 441, in is_available
required_services = [action[CONF_SERVICE] for action in self._queue]
~~~~~~^^^^^^^^^^^^^^
KeyError: 'service'
2024-08-10 06:05:59.839 ERROR (Recorder) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
File "/config/custom_components/scheduler/actions.py", line 396, in async_entity_changed
await self.async_process_queue()
File "/config/custom_components/scheduler/actions.py", line 479, in async_process_queue
if self.queue_busy or not self.is_available():
^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/scheduler/actions.py", line 441, in is_available
required_services = [action[CONF_SERVICE] for action in self._queue]
~~~~~~^^^^^^^^^^^^^^
KeyError: 'service'
2024-08-10 06:05:59.892 ERROR (SyncWorker_62) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
File "/config/custom_components/scheduler/actions.py", line 396, in async_entity_changed
await self.async_process_queue()
File "/config/custom_components/scheduler/actions.py", line 479, in async_process_queue
if self.queue_busy or not self.is_available():
^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/scheduler/actions.py", line 441, in is_available
required_services = [action[CONF_SERVICE] for action in self._queue]
~~~~~~^^^^^^^^^^^^^^
KeyError: 'service'
2024-08-10 06:05:59.893 ERROR (SyncWorker_62) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
File "/config/custom_components/scheduler/actions.py", line 396, in async_entity_changed
await self.async_process_queue()
File "/config/custom_components/scheduler/actions.py", line 479, in async_process_queue
if self.queue_busy or not self.is_available():
^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/scheduler/actions.py", line 441, in is_available
required_services = [action[CONF_SERVICE] for action in self._queue]
~~~~~~^^^^^^^^^^^^^^
KeyError: 'service'
nielsfaber commented 1 month ago

I just made release 3.3.6 of the scheduler-component which should fix the compatibility with HA 2024.8. Thanks @nima-1102 @petebanham for your participation in identifying the issue. I will close the issue (since the issue does not occur for me anymore with the fix), if I'm wrong please let me know.

petebanham commented 1 month ago

Many thanks for sorting so fast. Mine seems fine now.