Python script to update climate devices based on sensors and time.
Install via HACS (recommended) or download the update_climate.py
file from inside the python_scripts directory here to your local python_scripts directory, then reload python_scripts in Home Assistant.
There is a blueprint that simplifies the use of this script. You can import this blueprint using the following URL. Just make sure you keep the blueprint up to date when you update the python script.
https://github.com/Santobert/HA-UpdateClimate/blob/master/blueprints/update_climate.yaml
This python script sets the target temperature according to the specified sensors and time.
The climate entity will be off when:
- The given
sensors_on
is on - The given
sensors_off
is off
In all other cases the hvac_mode
will be heat
.
The target temparature will be set to high_temp
if the sensor_presence
is on or not given and the current time is between heating_from_hour
and heating_to_hour
.
Otherwise the target temperature will be set to low_temp
.
If one of the specifications heating_from_hour
or heating_to_hour
is not given, the target temperature depends only on the sensor_presence
.
Name | Required | Description |
---|---|---|
entity_id | True | The climates enitity_id |
sensor_on | False | The climate will be off when this sensors is on |
sensor_off | False | The climate will be off when this sensors is off |
sensor_presence | False | The climate will switch to active mode if this sensor is on |
heating_from_hour | False | Start time from which heating is to start |
heating_to_hour | False | End time to which the heating is to last |
high_temp | False | Temperature for active hours (Default: 25) |
low_temp | False | Temperature for inactive hours (Default: 20) |
The following is the content of a service call. This example includes all possible parameters. You may not need them all.
service: python_script.update_climate
data:
entity_id: climate.livingroom
sensor_on: binary_sensor.livingroom_window
sensor_off: binary_sensor.livingroom_climate_on
sensor_presence: binary_sensor.someone_at_home
heating_from_hour: 8
heating_to_hour: 17
high_temp: 25
low_temp: 20
The following is the content of an automation.
- id: 0123456789
alias: Climate Livingroom
trigger:
- hours: "*"
minutes: "1"
platform: time_pattern
- entity_id: binary_sensor.presence
platform: state
- entity_id: binary_sensor.livingroom_window
platform: state
- entity_id: input_boolean.livingroom_climate
platform: state
- entity_id: binary_sensor.all_climates_on
platform: state
condition: []
action:
- data:
entity_id: climate.livingroom
sensor_on: binary_sensor.livingroom_window
sensor_off: binary_sensor.livingroom_climate_on
sensor_presence: binary_sensor.someone_at_home
heating_from_hour: 8
heating_to_hour: 17
high_temp: 25
low_temp: 20
service: python_script.update_climate