swingerman / ha-dual-smart-thermostat

The `dual_smart_thermostat` is an enhaced verion of generic thermostat implemented in Home Assistant. It uses several sensors and dedicated switches connected to a heater and air conditioning under the hood.
https://github.com/swingerman/ha-dual-thermostat
Apache License 2.0
121 stars 20 forks source link

feat: picks target temperature from preset range if target temp is not set #210

Closed swingerman closed 4 months ago

swingerman commented 4 months ago

Fixes #185

sonarcloud[bot] commented 4 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

T3chArmy commented 4 months ago

@swingerman FYI I was testing the beta3 release and was getting occasional errors spit out.

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/dual_smart_thermostat/managers/environment_manager.py:347
integration: dual_smart_thermostat (documentation, issues)
First occurred: 13:50:31 (3 occurrences)
Last logged: 13:54:26

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/dual_smart_thermostat/climate.py", line 1078, in _async_control_climate
    await self.hvac_device.async_control_hvac(time, force)
  File "/config/custom_components/dual_smart_thermostat/hvac_device/heater_cooler_device.py", line 84, in async_control_hvac
    await self._async_control_heat_cool(time, force)
  File "/config/custom_components/dual_smart_thermostat/hvac_device/heater_cooler_device.py", line 137, in _async_control_heat_cool
    await self.async_heater_cooler_toggle(time, force)
  File "/config/custom_components/dual_smart_thermostat/hvac_device/heater_cooler_device.py", line 147, in async_heater_cooler_toggle
    too_cold, too_hot, tolerance_device = self.is_cold_or_hot()
                                          ^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dual_smart_thermostat/hvac_device/heater_cooler_device.py", line 105, in is_cold_or_hot
    too_cold = self.environment.is_too_cold("_target_temp_low")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dual_smart_thermostat/managers/environment_manager.py", line 347, in is_too_cold
    return target_temp >= self._cur_temp + self._cold_tolerance
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '>=' not supported between instances of 'NoneType' and 'float'

and

2024-06-02 12:33:52.944 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139721372687936] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 239, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2738, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2779, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1047, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 765, in async_handle_set_preset_mode_service
    await self.async_set_preset_mode(preset_mode)
  File "/config/custom_components/dual_smart_thermostat/climate.py", line 1128, in async_set_preset_mode
    await self._async_control_climate(force=True)
  File "/config/custom_components/dual_smart_thermostat/climate.py", line 1078, in _async_control_climate
    await self.hvac_device.async_control_hvac(time, force)
  File "/config/custom_components/dual_smart_thermostat/hvac_device/heater_cooler_device.py", line 87, in async_control_hvac
    await super().async_control_hvac(time, force)
  File "/config/custom_components/dual_smart_thermostat/hvac_device/multi_hvac_device.py", line 148, in async_control_hvac
    await device.async_control_hvac(time, force)
  File "/config/custom_components/dual_smart_thermostat/hvac_device/heater_device.py", line 81, in async_control_hvac
    await self._async_control_device_when_off(time)
  File "/config/custom_components/dual_smart_thermostat/hvac_device/heater_device.py", line 118, in _async_control_device_when_off
    too_cold = self.environment.is_too_cold(self.target_env_attr)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dual_smart_thermostat/managers/environment_manager.py", line 347, in is_too_cold
    return target_temp >= self._cur_temp + self._cold_tolerance
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '>=' not supported between instances of 'NodeDictClass' and 'float'
2024-06-02 12:34:05.610 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139721372687936] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 239, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2738, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2779, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1047, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 765, in async_handle_set_preset_mode_service
    await self.async_set_preset_mode(preset_mode)
  File "/config/custom_components/dual_smart_thermostat/climate.py", line 1128, in async_set_preset_mode
    await self._async_control_climate(force=True)
  File "/config/custom_components/dual_smart_thermostat/climate.py", line 1078, in _async_control_climate
    await self.hvac_device.async_control_hvac(time, force)
  File "/config/custom_components/dual_smart_thermostat/hvac_device/heater_cooler_device.py", line 87, in async_control_hvac
    await super().async_control_hvac(time, force)
  File "/config/custom_components/dual_smart_thermostat/hvac_device/multi_hvac_device.py", line 148, in async_control_hvac
    await device.async_control_hvac(time, force)
  File "/config/custom_components/dual_smart_thermostat/hvac_device/heater_device.py", line 81, in async_control_hvac
    await self._async_control_device_when_off(time)
  File "/config/custom_components/dual_smart_thermostat/hvac_device/heater_device.py", line 118, in _async_control_device_when_off
    too_cold = self.environment.is_too_cold(self.target_env_attr)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dual_smart_thermostat/managers/environment_manager.py", line 347, in is_too_cold
    return target_temp >= self._cur_temp + self._cold_tolerance
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '>=' not supported between instances of 'NodeDictClass' and 'float'

The first one seemed to occur when switching from a preset to preset "None".

Not exactly sure what caused the 2nd set of errors.

Config for reference:

climate:
  - platform: dual_smart_thermostat
    name: Hallway Thermostat
    unique_id: hallway_thermostat
    heater: switch.thermostat_controller_l1
    cooler: switch.thermostat_controller_l2
    fan: switch.thermostat_controller_l3
    target_sensor: sensor.calculated_average_house_temperature
    openings:
        - binary_sensor.office_window_contact
    min_temp: 60
    max_temp: 85
    fan_hot_tolerance: 0.5
    heat_cool_mode: true
    min_cycle_duration:
      seconds: 60
    keep_alive:
      minutes: 3
    away:
      target_temp_low: 68
      target_temp_high: 77
    home:
      target_temp_low: 71
      target_temp_high: 74
    precision: 0.1
    target_temp_step: 0.5

I assume these are likely due to not having a value set in the config outside the presets, in which case I would expect it to maintain the current settings when switching to preset None.

swingerman commented 4 months ago

Thanks for sharing this. I am looking into it.

10der commented 3 months ago

Thanks for sharing this. I am looking into it.

btw

  File "/config/custom_components/dual_smart_thermostat/climate.py", line 949, in _async_control_climate
    await self._async_control_cooling(time, force)
  File "/config/custom_components/dual_smart_thermostat/climate.py", line 1133, in _async_control_cooling
    too_cold = self._is_too_cold()
               ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dual_smart_thermostat/climate.py", line 1470, in _is_too_cold
    return target_temp >= self._cur_temp + self._cold_tolerance
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '>=' not supported between instances of 'NoneType' and 'float'
swingerman commented 2 months ago

@T3chArmy I copied your configuration and was unable to reproduce the issue on my end. Could you provide the exact sequence of actions that led to this error?

T3chArmy commented 2 months ago

I will attempt to reproduce this today. If I recall it had to do with switching the preset and then the mode or something like that. I will follow up in a few hours once I have some down time if I was able to reproduce.