You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Smart Thermostat with PID controller for Home Assistant
6
+
Create a virtual thermostat with accurate and reactive temperature control through PID controller.
7
+
[Principle of the PID controller.](https://en.wikipedia.org/wiki/PID_controller)
8
+
Any heater or air conditioner unit with ON/OFF switch or pilot wire can be controlled using a pulse width modulation
9
+
that depends on the temperature error and its variation over time.
5
10
6
-
## PID controller thermostat
11
+

7
12
8
-
### Installation:
13
+
## Installation:
14
+
I recommend using HACS for easier installation.
15
+
16
+
### Install using HACS:
17
+
Go to HACS, select Integrations, click the three dots menu and select
18
+
"Custom repositories". Add the path to the Github repository in the first field, select Integration as category and
19
+
click Add. Once back in integrations panel, click the Install button on the Smart Thermostat PID card to install.
20
+
Set up the smart thermostat and have fun.
21
+
22
+
### Manual installation:
9
23
1. Go to <conf-dir> default /homeassistant/.homeassistant/ (it's where your configuration.yaml is)
10
24
2. Create <conf-dir>/custom_components/ directory if it does not already exist
11
-
3.Clone this repository content into <conf-dir>/custom_components/
25
+
3.Copy the smart_thermostat folder into <conf-dir>/custom_components/
12
26
4. Set up the smart_thermostat and have fun
13
27
14
-
### Usage:
15
-
pid controller will be called periodically.
16
-
If no pwm interval is definde. It will set the state of "heater" 0-"difference"
17
-
Else it will turn off and on the heater proportionally.
18
-
19
-
#### Autotune:
20
-
You can use the autotune feature to set the PID parameters.
21
-
22
-
Issue! I'couldn't yet save the settings to the configuration.yaml file.
23
-
The PID parmaters set by the autotune won't be stored and the process restarts everytime hassio is restarted.
24
-
To save the parameters read log, it will be shown like this:
25
-
LOGGER.info("Set Kp, Ki, Kd. Smart thermostat now runs on PID Controller." self.kp , self.ki, self.kd)
26
-
27
-
### Parameters:
28
-
29
-
#### Still same:
30
-
31
-
* name (Required): Name of thermostat
32
-
* heater (Required): entity_id for heater switch, must be a toggle device. Becomes air conditioning switch when ac_mode is set to True
33
-
* target_sensor (Required): entity_id for a temperature sensor, target_sensor.state must be temperature.
34
-
* min_temp (Optional): Set minimum set point available (default: 7)
35
-
* max_temp (Optional): Set maximum set point available (default: 35)
36
-
* target_temp (Optional): Set initial target temperature. Failure to set this variable will result in target temperature being set to null on startup. As of version 0.59, it will retain the target temperature set before restart if available.
37
-
* ac_mode (Optional): Set the switch specified in the heater option to be treated as a cooling device instead of a heating device.
38
-
* initial_operation_mode (Optional): Set the initial operation mode. Valid values are off or auto. Value has to be double quoted. If this parameter is not set, it is preferable to set a keep_alive value. This is helpful to align any discrepancies between generic_thermostat and heater state.
39
-
* away_temp (Optional): Set the temperature used by “away_mode”. If this is not specified, away_mode feature will not get activated.
28
+
## Configuration:
29
+
The smart thermostat can be added to Home Assistant after installation by adding a climate section to your
30
+
configuration.yaml file.
40
31
41
-
#### Removed:
42
-
43
-
* min_cycle_duration (Optional):
44
-
* cold_tolerance (Optional):
45
-
* hot_tolerance (Optional):
46
-
47
-
#### Edited:
48
-
49
-
* keep_alive (Required): Set a keep-alive interval. Interval pid controller will be updated.
50
-
51
-
#### New:
32
+
### Configuration example:
33
+
#### configuration.yaml
34
+
```
35
+
climate:
36
+
- platform: smart_thermostat
37
+
name: Smart Thermostat Example
38
+
heater: switch.on_off_heater
39
+
target_sensor: sensor.ambient_temperature
40
+
min_temp: 7
41
+
max_temp: 28
42
+
ac_mode: False
43
+
target_temp: 19
44
+
keep_alive:
45
+
seconds: 60
46
+
away_temp: 14
47
+
kp : 75
48
+
ki : 0.001
49
+
kd : 70000
50
+
pwm : 00:15:00
51
+
```
52
52
53
-
* kp (Optional): Set PID parameter, p controll value.
54
-
* ki (Optional): Set PID parameter, i controll value.
55
-
* kd (Optional): Set PID parameter, d controll value.
56
-
* pwm (Optional): Set period time for pwm signal in minutes. If it's not set pwm is disabled.
57
-
* autotune (Optional): Chose a string for autotune settings. If it's not set autotune is disabled.
58
-
tuning_rules
53
+
## Usage:
54
+
The target sensor measures the ambient temperature while the heater switch controls an ON/OFF heating system.
55
+
The PID controller computes the amount of time the heater should remain ON over the PWM period to reach the temperature
56
+
set point, in example with PWM set to 15 minutes, if output is 100% the heater will be kept on for the next 15 minutes
57
+
PWM period. If PID output is 33%, the heater will be switched ON for 5 minutes only.
58
+
59
+
By default, the PID controller will be called each time the target sensor is updated. When using main powered sensor
60
+
with high sampling rate, the _sampling_period_ parameter should be used to slow down the PID controller refresh rate.
61
+
62
+
By adjusting the Kp, Ki and Kd gains, you can tune the system response to your liking. You can find many tutorials for
63
+
guidance on the web. Here are a few useful links:
64
+
*[PID Control made easy](https://www.eurotherm.com/temperature-control/pid-control-made-easy/)
65
+
*[Practical PID Process Dynamics with Proportional Pressure Controllers](
* difference (Optional): Set analog output offset to 0. (default : 100). If it's 500 the output Value can be everything between 0, 500.
71
-
* noiseband (Optional): (default : 0.5), set noiseband (float): Determines by how much the input value must overshoot/undershoot the setpoint before the state changes.
144
+
***noiseband** (Optional): set noiseband for autotune (float): Determines by how much the input value
145
+
must overshoot/undershoot the set point before the state changes (default : 0.5).
146
+
***lookback** (Optional): duration of the signal analysis for the autotune, need to have 5 cycles (temperature crossing
147
+
the set point) included in the analysis period, can be float in seconds, or time hh:mm:ss (default 2 hours).
72
148
73
-
#### configuration.yaml
74
-
```
75
-
climate:
76
-
- platform: smart_thermostat
77
-
name: Study
78
-
heater: switch.study_heater
79
-
target_sensor: sensor.study_temperature
80
-
min_temp: 15
81
-
max_temp: 21
82
-
ac_mode: False
83
-
target_temp: 17
84
-
keep_alive:
85
-
seconds: 5
86
-
initial_operation_mode: "off"
87
-
away_temp: 16
88
-
kp : 5
89
-
ki : 3
90
-
kd : 2
91
-
pwm : 10
92
-
autotune : ziegler-nichols
93
-
difference : 100
94
-
noiseband : 0.5
95
-
```
96
-
### Help
97
149
98
-
The python PID module:
150
+
### Credits
151
+
This code is a fork from Smart Thermostat PID project:
0 commit comments