ScratMan / HASmartThermostat

Smart Thermostat with PID controller for HomeAssistant
338 stars 49 forks source link

Configure Guidelines for a Zigbee Thermostat #29

Closed jetbalsa closed 2 years ago

jetbalsa commented 2 years ago

Currently Running v2021.11.9-beta2

Looking to configure a existing Zigbee Thermostat for use with the HASmartThermostat.

Looks like its having some issues handling how to gets the current temp.

I have attached a screenshot of how the Thermostat is currently listed in devtools image

The logs show the following

2021-11-29 13:50:42 DEBUG (MainThread) [custom_components.smart_thermostat.climate] PID Gains: kp = 75.0, ki = 0.001, kd = 70000.0
2021-11-29 13:50:44 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Unable to update from sensor: could not convert string to float: 'heat'
2021-11-29 13:50:44 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Received new temperature sensor input at timestamp 1638211844.2949722 (before None): None (before None)
2021-11-29 13:50:44 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Unable to update from sensor: could not convert string to float: 'heat'
2021-11-29 13:53:15 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Unable to update from sensor: could not convert string to float: 'heat'
2021-11-29 13:53:15 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Received new temperature sensor input at timestamp 1638211995.5093408 (before 1638211844.2949722): None (before None)

and here is the config I'm using:

climate:
  - platform: smart_thermostat
    name: Smart Thermostat
    heater: climate.homehvac_1d6a2c0b_fan_thermostat
    target_sensor: climate.homehvac_1d6a2c0b_fan_thermostat
    min_temp: 44.6
    max_temp: 89.6
    ac_mode: False
    target_temp: 69
    unique_id: homesmartthermostat
    keep_alive:
      seconds: 60
    away_temp: 65
    kp: 75
    ki: 0.001
    kd: 70000
    pwm: 00:15:00

(Update: Looks like complicated templates are going to be required for this)

jetbalsa commented 2 years ago

Ok, I think I have a solution and this is for anyone with a complicated Thermostat

First you need to set a switch for turning on and off your HVAC

in configuration.yaml add something like this. Here its pulling from my attributes. Also Its forcing the temp really high on the thermostat to force it on. then setting it real low when its off. but also this prevents in case of a failure a complete freeze of the building.

switch:
  - platform: template
    switches:
      homehvac:
        friendly_name: "HomeHVACSwitch"
        value_template: "{{ is_state_attr('climate.homehvac_1d6a2c0b_fan_thermostat', 'hvac_action', 'heating') }}"
        turn_on:
          service: climate.set_temperature
          target:
            entity_id: climate.homehvac_1d6a2c0b_fan_thermostat
          data:
            temperature: 87
            target_temp_high: 87
            target_temp_low: 87
            hvac_mode: heat
        turn_off:
          service: climate.set_temperature
          target:
            entity_id: climate.homehvac_1d6a2c0b_fan_thermostat
          data:
            temperature: 60
            target_temp_high: 60
            target_temp_low: 60
            hvac_mode: heat

the next template is for getting the temp, This one is rather easy. Goes right into configuration.yaml again

template:
  - sensor:
      - name: "Thermostat Temp"
        unit_of_measurement: "°F"
        state: >
          {{ state_attr('climate.homehvac_1d6a2c0b_fan_thermostat', 'current_temperature') }}

here is what my logs look like now

021-11-29 14:47:58 DEBUG (MainThread) [custom_components.smart_thermostat.climate] PID Gains: kp = 75.0, ki = 0.001, kd = 70000.0
2021-11-29 14:47:58 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Unable to update from sensor: could not convert string to float: 'unknown'
2021-11-29 14:47:58 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Received new temperature sensor input at timestamp 1638215278.512626 (before None): None (before None)
2021-11-29 14:48:02 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Received new temperature sensor input at timestamp 1638215282.3274984 (before 1638215278.512626): 70.2 (before None)
2021-11-29 14:48:02 INFO (MainThread) [custom_components.smart_thermostat.climate] Obtained temperature 70.2 with set point 72.0. Smart thermostat active.
2021-11-29 14:48:02 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 100.00 (error = 1.80, dt = 3.81, p=135.00, i=0.00, d=-0.00)
2021-11-29 14:50:21 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Received new temperature sensor input at timestamp 1638215421.2212958 (before 1638215282.3274984): 70.7 (before 70.2)
2021-11-29 14:50:21 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 0.00 (error = 1.30, dt = 138.89, p=97.50, i=0.00, d=-251.99)
2021-11-29 14:50:21 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning off switch.homehvac
2021-11-29 14:50:21 INFO (MainThread) [custom_components.smart_thermostat.climate] Turning off switch.homehvac
2021-11-29 14:50:58 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning off switch.homehvac
2021-11-29 14:50:58 INFO (MainThread) [custom_components.smart_thermostat.climate] Turning off switch.homehvac
2021-11-29 14:51:58 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning off switch.homehvac
2021-11-29 14:51:58 INFO (MainThread) [custom_components.smart_thermostat.climate] Turning off switch.homehvac
2021-11-29 14:52:58 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning off switch.homehvac
2021-11-29 14:52:58 INFO (MainThread) [custom_components.smart_thermostat.climate] Turning off switch.homehvac
2021-11-29 14:53:03 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Received new temperature sensor input at timestamp 1638215583.0485651 (before 1638215421.2212958): 71.2 (before 70.7)
2021-11-29 14:53:03 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 0.00 (error = 0.80, dt = 161.83, p=60.00, i=0.00, d=-216.28)
2021-11-29 14:53:03 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning off switch.homehvac
2021-11-29 14:53:03 INFO (MainThread) [custom_components.smart_thermostat.climate] Turning off switch.homehvac

It looks to be working as it has turned on and off my thermostat now. I hope this helps in the future and maybe some docs written for it.

Finally, Here is my final config for smart thermostat

climate:
  - platform: smart_thermostat
    name: Smart Thermostat
    heater: switch.homehvac
    target_sensor: sensor.thermostat_temp
    min_temp: 44.6
    max_temp: 89.6
    ac_mode: False
    target_temp: 69
    unique_id: homesmartthermostat
    keep_alive:
      seconds: 60
    away_temp: 65
    kp: 75
    ki: 0.001
    kd: 70000
    pwm: 00:15:00
ScratMan commented 2 years ago

Hello, you found the solution by yourself. 👍

Just be careful, your sensor is updated very often (from 3 seconds to 180 seconds), so the derivative part is switching from strongly positive to strongly negative, switching the thermostat between on 100% and off 0% continuously.

You should use the sampling_period parameter to slow down the sampling to 5 minutes at least, and adjust the Kp, Kp and Kd gains to match the speed of your heating system.