jeroenterheerdt / HAsmartirrigation

Smart Irrigation custom component for Home Assistant
MIT License
301 stars 47 forks source link

calling smart_irrigation.reset_all_buckets within an automation does not work as expected. #309

Closed genesispc closed 7 months ago

genesispc commented 7 months ago

What happened?

I have the following automation that I have used in the past to run my sprinklers. However, I have noticed that the buckets would not reset at the end. I have since removed the call to the script that starts the irrigation, and set the timeout to 10 seconds, so I can test the bucket resetting. The automation is as follows:

alias: Irrigation system schedule description: >- Run irrigation system daily, 60 mins after sunrise as long as rain sensor has been off for 15 mins trigger:

How to reproduce

Automation with service call containing.

service: smart_irrigation.reset_all_buckets data: {} home-assistant_smart_irrigation_2023-10-17T21-52-20.044Z.log

Relevant log output

2023-10-18 07:51:18.889 INFO (MainThread) [custom_components.smart_irrigation] Reset all buckets service called
2023-10-18 07:51:18.894 DEBUG (MainThread) [custom_components.smart_irrigation] calling register start event from async_update_zone_config
2023-10-18 07:51:18.898 ERROR (MainThread) [homeassistant.components.automation.irrigation] Irrigation system schedule: Error executing script. Unexpected error for call_service at pos 2: 
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 704, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 666, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2012, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2049, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/smart_irrigation/__init__.py", line 1072, in handle_reset_all_buckets
    await self._async_set_all_buckets(0)
  File "/config/custom_components/smart_irrigation/__init__.py", line 1008, in _async_set_all_buckets
    await self.async_update_zone_config(zone_id=zone.get(const.ZONE_ID),data=data)
  File "/config/custom_components/smart_irrigation/__init__.py", line 907, in async_update_zone_config
    self.register_start_event()
  File "/config/custom_components/smart_irrigation/__init__.py", line 920, in register_start_event
    self._track_sunrise_event_unsub()
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1558, in async_detach
    assert self._unsub_sun is not None
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
2023-10-18 07:51:18.916 ERROR (MainThread) [homeassistant.components.automation.irrigation] While executing automation automation.irrigation
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 655, in async_trigger
    await self.action_script.async_run(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1578, in async_run
    return await asyncio.shield(run.async_run())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 420, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 470, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 493, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 704, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 666, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2012, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2049, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/smart_irrigation/__init__.py", line 1072, in handle_reset_all_buckets
    await self._async_set_all_buckets(0)
  File "/config/custom_components/smart_irrigation/__init__.py", line 1008, in _async_set_all_buckets
    await self.async_update_zone_config(zone_id=zone.get(const.ZONE_ID),data=data)
  File "/config/custom_components/smart_irrigation/__init__.py", line 907, in async_update_zone_config
    self.register_start_event()
  File "/config/custom_components/smart_irrigation/__init__.py", line 920, in register_start_event
    self._track_sunrise_event_unsub()
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1558, in async_detach
    assert self._unsub_sun is not None
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

Which version are you running?

1.2.3

Diagnostics file

Additional information

No response

genesispc commented 7 months ago

Ignore this. I think it is a duplicate... will try 2023.9.3-beta5.