nielsfaber / scheduler-component

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

After upgrading Scheduler to 3.3.0 Google Nest does not change to Heat according to the scheduler any more (not responding to the scheduler). #328

Closed 730522js closed 2 months ago

730522js commented 5 months ago

Checklist

Expected behavior

Google Nest to change mode from Eco to Heat according to the scheduler

Actual behavior

Google Nest does not change the mode to Heat according to the scheduler, it remains on Eco mode.

I have scheduler active for other climate entities (Daiking heat pumps) and those change their modes according to the Scheduler as expected. I've tested manually and HA is able to control the Google Nest thermostat (no connectivity issue). I haven't changed anything before or after upgrading to Scheduler 3.3.0. I've tried:

Steps to Reproduce

[Explain how to see the behaviour]

730522js commented 5 months ago

I've deleted the Schedule for Google Nest and created it from scratch but still does not work. I've noticed though if I manually set the Google Nest thermostat to heating (during the period in which Scheduler was supposed to set it to heating and at a certain temperature), the Scheduler can successfully continue with the temperature changes according to the predefined temperatures and times, and can successfully change the Google Nest Thermostat from heating to Eco as scheduled.

730522js commented 5 months ago

I think I found another workaround, but interesting to be looked at, perhaps it has something to do with the upgrade to Scheduler 3.3.0. I've attached my Google Nest schedule, problem is at 6PM when the Scheduler should tell Google Nest thermostat to start heating at 22 degrees - this after upgrade to Scheduler 3.3.0 was not happening any more, this was the only thing which was not working properly. Then I've notice if I add another step for Scheduler to change the Preset mode from Eco to None (6PM to 6:10PM), and then to Heating at 22 degrees, it actually works. So it looks like Scheduler can no longer go from Eco to Heating after upgrade to 3.3.0 Regards, John

Screenshot 2024-01-29 at 18 34 43
etamtlosz commented 5 months ago

Similar issue here with my Daikin. My schedule is to have the house on vent mode until midnight, then off. In the morning it should change from off to heating and 22C. At 6:30 the heat turns on, but within a second it jumps to fan only mode, or to whatever mode it was in previously.

I don't think is just Nest related.

image
nielsfaber commented 5 months ago

What scheduler does is:

  1. Set climate entity operation mode to 'heat' (if it is not in mode 'heat') (service climate.set_hvac_mode)
  2. Wait until entity has updated its state to 'heat' (maximum 50 seconds).
  3. Set temperature setting to the chosen value (service climate.set_temperature)

I wouldn't know what is wrong about this that could explain the issues. And I don't see any relation with preset mode or fan mode (this behaviour seems specific to your devices).

I created a script that mimics the behaviour of scheduler (above steps). I would like you ask you to test this in combination with your thermostats and check if it works. The script will log some information in the home assistant log. The code below can be added to the scripts.yaml file (or paste via the UI editor in the yaml mode).

thermostat_test:
  variables:
    entity: climate.my_thermostat # insert entity ID here
    temperature: 20 # choose a setpoint different than current value
    mode: heat
  sequence:
    - service: system_log.write
      data:
        message: "-- Start of script --"
    - choose:
        - conditions:
            - condition: template
              value_template: "{{ is_state(entity, mode) }}"
          sequence:
            - service: system_log.write
              data:
                message: Mode is already {{ mode }}, skipping step
      default:
        - service: system_log.write
          data:
            message: Setting mode to {{ mode }}
        - service: climate.set_hvac_mode
          data_template:
            entity_id: "{{ entity }}"
            hvac_mode: "{{ mode }}"
    - service: system_log.write
      data:
        message: Waiting until {{ entity }} has state {{ mode }}
    - wait_template: "{{ is_state(entity, mode) }}"
      timeout: "00:00:50"
    - service: system_log.write
      data:
        message: Wait for state update completed.
    - choose:
        - conditions:
            - condition: template
              value_template: "{{ state_attr(entity, 'temperature') == temperature }}"
          sequence:
            - service: system_log.write
              data:
                message: Temperature is already {{ temperature }}, skipping step
      default:
        - service: system_log.write
          data:
            message: Setting temperature to {{ temperature }}
        - service: climate.set_temperature
          data_template:
            entity_id: "{{ entity }}"
            temperature: "{{ temperature }}"
    - service: system_log.write
      data:
        message: "-- End of script --"

Please post your findings.

etamtlosz commented 5 months ago

This has been working flawlessly during the last few years, that's why I assumed it is integration related. Weird things started happening after the latest update.

Here's the output of the script 2024-01-31-11-26-030PC2EChLlh

nielsfaber commented 5 months ago

@etamtlosz The script shows the same behaviour as scheduler so that's good, we can reproduce the issue. From the screen capture it appears that the first command (setting the mode to heat) is processed OK. Somehow your climate device seems to jump back to fan mode when changing the setpoint. Your test proves that the behaviour is caused by your device itself. If you would use the dashboard card to perform the same steps, you will likely see the same behaviour.

I don't own the same device so from here I don't know how to make it work. I suggest you to make changes to the script until the response is as it should be. Things to try:

  1. Commenting out the setting of the temperature, to see if only setting operation mode works
  2. Adding a small fixed time delay between the steps
  3. Switching the order, so first setting the setpoint, then the mode
  4. Setting the mode+setpoint simultaneously, so removing the time delay
etamtlosz commented 5 months ago

@730522js can you confirm your situation is similar? I don't want to hijack this issue. If yours something else, please report and I'll open another issue.

730522js commented 5 months ago

@730522js can you confirm your situation is similar? I don't want to hijack this issue. If yours something else, please report and I'll open another issue.

Yes, I can confirm my situation is similar.

etamtlosz commented 5 months ago
  1. Works to set just the mode, it won't revert to the previous mode.
  2. Adding a 1 second delay seems to work
  3. Messes up things, sometimes the temperature set is working but the mode reverts
  4. Didn't manage to test this option
peteh commented 5 months ago

I have the same issue with my heaters. When AUTO is selected as the target mode it will just do nothing.

If I swich it to heat and give a target temperature it actually works.

I don't want to set the temperature explicitly though and prefer using AUTO.

My heaters take about 3-5 seconds the change the mode after selecting a different one.

github-actions[bot] commented 4 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

peteh commented 4 months ago

Afaik still not resolved

peteh commented 4 months ago

Looks like when switching to auto somehow it requires target temperature also for AUTO In Homeassistant 2024.3.1 it actually works if I set a specific target temperature and set to AUTO. However, it does not work without specifying a target temp.

2024-03-15 15:31:53.719 ERROR (MainThread) [homeassistant.util.logging] Exception in async_timer_updated when dispatching 'scheduler_timer_updated': ('363511',)
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 818, in validate_callable
    return schema(data)
           ^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/config_validation.py", line 171, in validate
    raise vol.Invalid(f"must contain at least one of {expected}.")
voluptuous.error.Invalid: must contain at least one of temperature, target_temp_high, target_temp_low.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/scheduler/switch.py", line 251, in async_timer_updated
    await self._action_handler.async_queue_actions(
  File "/config/custom_components/scheduler/actions.py", line 257, in async_queue_actions
    await queue.async_start(skip_initial_execution)
  File "/config/custom_components/scheduler/actions.py", line 389, in async_start
    await self.async_process_queue()
  File "/config/custom_components/scheduler/actions.py", line 589, in async_process_queue
    await async_call_from_config(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 291, in async_call_from_config
    await hass.services.async_call(**params, blocking=blocking, context=context)
  File "/usr/src/homeassistant/homeassistant/core.py", line 2284, in async_call
    processed_data: dict[str, Any] = handler.schema(service_data)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 232, in __call__
    return self._exec((Schema(val) for val in self.validators), v)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 355, in _exec
    raise e if self.msg is None else AllInvalid(self.msg, path=path)
  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 351, in _exec
    v = func(v)
        ^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 276, in __call__
    raise er.MultipleInvalid([e])
voluptuous.error.MultipleInvalid: must contain at least one of temperature, target_temp_high, target_temp_low.
nielsfaber commented 4 months ago

Scheduler only executes a service in HA with given set of parameters. So if an action does not work with your device, the best way to identify the issue is by knowing what service configuration is needed for your thermostat. The actions shown in the card are calculated based on the capabilities advertised by the climate entity, perhaps something is wrong here. I suggest to use the developer tools -> services page to manually try putting your thermostat in the correct setting. You can also check what is done by scheduler by enable the debug logging for the integration. After doing so, you should see extra lines appearing in the HA log at the time the schedule triggers. Please share your findings, it helps me identifying the issue and fix this.

peteh commented 3 months ago

Alright, playing around a bit more, I'm using time slots. SET AUTO, no temp, current state is off:

2024-03-17 22:34:47.477 DEBUG (MainThread) [custom_components.scheduler.switch] Schedule 363511 is starting in a timeslot, proceed with actions 
2024-03-17 22:34:47.477 DEBUG (MainThread) [custom_components.scheduler.actions] [363511]: Executing service climate.set_temperature on entity climate.office_heater
2024-03-17 22:34:47.598 ERROR (MainThread) [homeassistant.util.logging] Exception in async_timer_updated when dispatching 'scheduler_timer_updated': ('363511',)
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 818, in validate_callable
    return schema(data)
           ^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/config_validation.py", line 171, in validate
    raise vol.Invalid(f"must contain at least one of {expected}.")
voluptuous.error.Invalid: must contain at least one of temperature, target_temp_high, target_temp_low.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/scheduler/switch.py", line 251, in async_timer_updated
    await self._action_handler.async_queue_actions(
  File "/config/custom_components/scheduler/actions.py", line 259, in async_queue_actions
    await queue.async_start(skip_initial_execution)
  File "/config/custom_components/scheduler/actions.py", line 406, in async_start
    await self.async_process_queue()
  File "/config/custom_components/scheduler/actions.py", line 606, in async_process_queue
    await async_call_from_config(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 291, in async_call_from_config
    await hass.services.async_call(**params, blocking=blocking, context=context)
  File "/usr/src/homeassistant/homeassistant/core.py", line 2284, in async_call
    processed_data: dict[str, Any] = handler.schema(service_data)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 232, in __call__
    return self._exec((Schema(val) for val in self.validators), v)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 355, in _exec
    raise e if self.msg is None else AllInvalid(self.msg, path=path)
  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 351, in _exec
    v = func(v)
        ^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 276, in __call__
    raise er.MultipleInvalid([e])
voluptuous.error.MultipleInvalid: must contain at least one of temperature, target_temp_high, target_temp_low.

SET AUTO, temperature: 21deg

From Dev console:

set hvac mode to auto on office heater device -> works

service: climate.set_hvac_mode
target:
  device_id: 7706ce9490bae4a3d1e15b7c607273e6
data:
  hvac_mode: auto

set auto mode on entity id --> Changes to AUTO

service: climate.set_hvac_mode
target:
  entity_id: climate.office_heater
data:
  hvac_mode: auto

set temperature on entity and only change hvac --> fails with error that temperature must be set image

service: climate.set_temperature
data:
  hvac_mode: auto
target:
  entity_id: climate.office_heater

set temperature on entity and change hvac and temp --> changes hvac but does not set temperature

service: climate.set_temperature
data:
  hvac_mode: "auto"
  temperature: 22
target:
  entity_id: climate.office_heater

set temperature on entity and temp to 22 without setting hvac --> changes temperature in current hvac mode

service: climate.set_temperature
data:
  temperature: 22
target:
  entity_id: climate.office_heater

So something seems to be not right here. But it looks like using climate.set_hvac_mode followed by a set_temperature call would be the right way to go.

nielsfaber commented 3 months ago

@peteh Thanks for your help investigating this! I can confirm that scheduler was not properly handling the case of setting the mode to auto without setting the temperature (i.e. leaving the checkbox empty). This would result in calling the service climate.set_temperature with no temperature setting but only hvac_mode parameter, which is not allowed in HA. I made a fix for this, in this specific case the service climate.set_hvac_mode will now be executed. This fix is released under v3.3.2.

I don't think this solves the bug that was originally reported here, @730522js / @etamtlosz please state if you're still experiencing issues and what solution/workaround would be helpful. It is not clear to me how to facilitate the support for the Google Nest specifically.

730522js commented 3 months ago

Hi all.

For me I can confirm I experience the behaviour I've initially opened the topic for. I'm still going on the workaround I found (described further below).

So main issue (which was not there before 3.3.0):

Workaround:

So I can conclude:

github-actions[bot] commented 2 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days