177 lines
5.7 KiB
YAML
177 lines
5.7 KiB
YAML
blueprint:
|
|
name: Auto AC Control
|
|
description: Auto Turn on Air Conditioning
|
|
domain: automation
|
|
author: Tiziano Trabattoni
|
|
|
|
input:
|
|
temp_threshold:
|
|
name: Temperature Threshold to switch AC on
|
|
description: This threshold is the temperature above which AC must be switched on
|
|
default: 29.0
|
|
selector:
|
|
number:
|
|
min: 25.0
|
|
max: 40.0
|
|
step: 0.5
|
|
unit_of_measurement: celsius
|
|
|
|
temp_hist:
|
|
name: Temperature Histeresys from off to on
|
|
description: This gap is difference between on and off
|
|
default: 2.0
|
|
selector:
|
|
number:
|
|
min: 1.0
|
|
max: 4.0
|
|
step: 0.5
|
|
unit_of_measurement: celsius
|
|
|
|
climate_target:
|
|
name: Termostat Control
|
|
description: Identifies the AC climate to be controlled
|
|
selector:
|
|
entity:
|
|
filter:
|
|
- domain: climate
|
|
|
|
fan_ctrl:
|
|
name: Auto AC controls fan speed
|
|
description: Allow Auto AC to set fan speed accordingly to difference between actual and target temperature
|
|
default: false
|
|
selector:
|
|
boolean: {}
|
|
|
|
override_duration:
|
|
name: Manual Override Duration
|
|
description: Hours to pause automatic control if a manual change is detected
|
|
default: 1
|
|
selector:
|
|
number:
|
|
min: 0.1
|
|
max: 4
|
|
step: 0.1
|
|
unit_of_measurement: hours
|
|
mode: restart
|
|
trace:
|
|
stored_traces: 30
|
|
|
|
variables:
|
|
target_AC: !input climate_target
|
|
target_temp: !input temp_threshold
|
|
target_hist: !input temp_hist
|
|
fan_control: !input fan_ctrl
|
|
override_hours: !input override_duration
|
|
|
|
triggers:
|
|
# Trigger when the room temperature changes
|
|
- trigger: state
|
|
entity_id: !input climate_target
|
|
attribute: current_temperature
|
|
id: temp_change
|
|
# # Trigger instantly when someone manually changes the AC mode
|
|
# - trigger: state
|
|
# entity_id: !input climate_target
|
|
# id: state_change
|
|
|
|
conditions:
|
|
# 1. Verifica di sicurezza sullo stato dell'entità
|
|
- condition: template
|
|
value_template: "{{ trigger.to_state is not none }}"
|
|
# # 2. Se l'automazione sta già eseguendo il "delay" di override, ignora i cambi di temperatura
|
|
# - condition: template
|
|
# value_template: >-
|
|
# {{ not (this.attributes.current == 1 and trigger.id == 'temp_change') }}
|
|
|
|
actions:
|
|
- choose:
|
|
# DETECT MANUAL OVERRIDE: Triggered by state change, but context shows it was NOT the automation itself
|
|
# - conditions:
|
|
# - condition: template
|
|
# value_template: "{{ trigger.id == 'state_change' and trigger.to_state.context.id != context.id }}"
|
|
# sequence:
|
|
# - delay:
|
|
# hours: "{{ override_hours | int(2) }}"
|
|
|
|
# CONDITION 1: Turn AC ON & Adjust Fan
|
|
- conditions:
|
|
- condition: template
|
|
value_template: "{{ state_attr(target_AC, 'current_temperature') | float(0) >= target_temp }}"
|
|
- condition: or
|
|
conditions:
|
|
- condition: state
|
|
entity_id: !input climate_target
|
|
state: "off"
|
|
- condition: state
|
|
entity_id: !input climate_target
|
|
state: "heat_cool"
|
|
- condition: state
|
|
entity_id: !input climate_target
|
|
state: "dry"
|
|
- condition: state
|
|
entity_id: !input climate_target
|
|
state: "fan_only"
|
|
sequence:
|
|
- action: climate.set_hvac_mode
|
|
target:
|
|
entity_id: !input climate_target
|
|
data:
|
|
hvac_mode: cool
|
|
- action: climate.set_swing_mode
|
|
target:
|
|
entity_id: !input climate_target
|
|
data:
|
|
swing_mode: Horizontal
|
|
- if:
|
|
- condition: template
|
|
value_template: "{{ fan_control }}"
|
|
then:
|
|
- action: climate.set_fan_mode
|
|
target:
|
|
entity_id: !input climate_target
|
|
data:
|
|
fan_mode: >-
|
|
{% set curr_temp = state_attr(target_AC, 'current_temperature') | float(0) -%}
|
|
{% set targ_temp = state_attr(target_AC, 'temperature') | float(0) -%}
|
|
{% set diff_temp = curr_temp - targ_temp -%}
|
|
{% if diff_temp >= 4.0 -%}
|
|
5
|
|
{% elif diff_temp >= 3.5 and diff_temp < 4.0 -%}
|
|
4
|
|
{% elif diff_temp >= 3.0 and diff_temp < 3.5 -%}
|
|
3
|
|
{% elif diff_temp >= 1.5 and diff_temp < 3.0 -%}
|
|
2
|
|
{% else -%}
|
|
Auto
|
|
{% endif %}
|
|
else:
|
|
- action: climate.set_fan_mode
|
|
target:
|
|
entity_id: !input climate_target
|
|
data:
|
|
fan_mode: Auto
|
|
|
|
# CONDITION 2: Turn AC OFF (Hysteresis)
|
|
- conditions:
|
|
- condition: template
|
|
value_template: >-
|
|
{{ state_attr(target_AC, 'current_temperature') | float(0) <= (target_temp | float(0) - target_hist | float(0)) }}
|
|
- condition: state
|
|
entity_id: !input climate_target
|
|
state: "cool"
|
|
sequence:
|
|
- action: climate.set_swing_mode
|
|
target:
|
|
entity_id: !input climate_target
|
|
data:
|
|
swing_mode: Horizontal
|
|
- action: climate.set_fan_mode
|
|
target:
|
|
entity_id: !input climate_target
|
|
data:
|
|
fan_mode: Auto
|
|
- action: climate.turn_off
|
|
target:
|
|
entity_id: !input climate_target
|