本帖最后由 sirakawa 于 2020-12-6 09:38 编辑
定时启动以及自动控制的核心基本下面这2个自动化。
模板一部分循环没搞定所以单独写的。。。。
看其他回答用通用温控器,不过这个主要在于时间段判断,用通用温控器也只是解决了哪个+-0.5度的判断那里。所以还是自己判断了。
其他的大部分的自动化其实不是用来控制暖气,而是用来防止在界面上输入错误的检查。
不过现在这是最近改的,各种检查还都没改完都不好用- -!
顺便,这个是暖气专用,多个温度设定找最高的温度,降温的没法用哈。。。
# ------------------------------------------------------------------------------#
# 定时启动暖气
# 如果当前已经是手动模式,则不执行
# ------------------------------------------------------------------------------#
- alias: "Heating Auto TurnOn By Time"
id: "heating_auto_turnon_by_time"
trigger:
# 每1分钟执行
- platform: time_pattern
minutes: "/1"
seconds: "10"
variables:
# 判断是否需要定时启动,需要启动返回 需要启动的时长,不需要则返回0
openDuration: >-
{# # 初始化 # #}
{% set openDuration = "0" %}
{% if is_state("input_boolean.heating_boolean_timer_exec_switch_1","on") %}
{% if states("input_datetime.heating_time_timer_exec_start_time_1") == (states("sensor.time") + ":00") %}
{% set openDuration = states("input_number.heating_number_timer_exec_open_duration_1") %}
{% endif %}
{% endif %}
{% if is_state("input_boolean.heating_boolean_timer_exec_switch_2","on") %}
{% if states("input_datetime.heating_time_timer_exec_start_time_2") == (states("sensor.time") + ":00") %}
{% set openDuration = states("input_number.heating_number_timer_exec_open_duration_2") %}
{% endif %}
{% endif %}
{% if is_state("input_boolean.heating_boolean_timer_exec_switch_3","on") %}
{% if states("input_datetime.heating_time_timer_exec_start_time_3") == (states("sensor.time") + ":00") %}
{% set openDuration = states("input_number.heating_number_timer_exec_open_duration_3") %}
{% endif %}
{% endif %}
{% if is_state("input_boolean.heating_boolean_timer_exec_switch_4","on") %}
{% if states("input_datetime.heating_time_timer_exec_start_time_4") == (states("sensor.time") + ":00") %}
{% set openDuration = states("input_number.heating_number_timer_exec_open_duration_4") %}
{% endif %}
{% endif %}
{# # 返回结果 # #}
{{ openDuration }}
condition:
# 打开状态
- condition: state
entity_id: input_boolean.heating_boolean_on_off_1
state: "on"
# 自动模式
- condition: state
entity_id: input_boolean.heating_boolean_manual_1
state: "off"
# 没有倒计时
- condition: state
entity_id: input_number.heating_number_open_duration
state: "0.0"
# 判断是否需要定时启动
- condition: template
value_template: "{{ ( openDuration | float > 0.0 ) }}"
action:
# - service: notify.persistent_notification
# data:
# title: "定时启动暖气"
# message: "{{ states('sensor.time') }} 启动暖气 {{ openDuration }} 分"
# 启动暖气
- service: input_number.set_value
data:
entity_id: input_number.heating_number_open_duration
value: "{{ openDuration }}"
# ------------------------------------------------------------------------------#
# 打开暖气
# ------------------------------------------------------------------------------#
- alias: "Heating Mode2 Auto Control"
id: "heating_mode2_auto_control"
trigger:
# 每1分钟执行
- platform: time_pattern
minutes: "/1"
seconds: "19"
# 调整时间/温度执行
- platform: state
entity_id:
- input_boolean.heating_boolean_on_off_1
- input_boolean.heating_boolean_manual_1
- input_boolean.heating_boolean_mode2_group_1_switch_1
- input_boolean.heating_boolean_mode2_group_1_switch_2
- input_boolean.heating_boolean_mode2_group_1_switch_3
- input_boolean.heating_boolean_mode2_group_1_switch_4
- input_boolean.heating_boolean_mode2_group_1_switch_5
- input_boolean.heating_boolean_mode2_group_2_switch_1
- input_boolean.heating_boolean_mode2_group_2_switch_2
- input_boolean.heating_boolean_mode2_group_2_switch_3
- input_boolean.heating_boolean_mode2_group_2_switch_4
- input_boolean.heating_boolean_mode2_group_2_switch_5
- input_datetime.heating_time_mode2_group_1_start_1
- input_datetime.heating_time_mode2_group_1_start_2
- input_datetime.heating_time_mode2_group_1_start_3
- input_datetime.heating_time_mode2_group_1_start_4
- input_datetime.heating_time_mode2_group_1_start_5
- input_datetime.heating_time_mode2_group_2_start_1
- input_datetime.heating_time_mode2_group_2_start_2
- input_datetime.heating_time_mode2_group_2_start_3
- input_datetime.heating_time_mode2_group_2_start_4
- input_datetime.heating_time_mode2_group_2_start_5
- input_datetime.heating_time_mode2_group_1_end_1
- input_datetime.heating_time_mode2_group_1_end_2
- input_datetime.heating_time_mode2_group_1_end_3
- input_datetime.heating_time_mode2_group_1_end_4
- input_datetime.heating_time_mode2_group_1_end_5
- input_datetime.heating_time_mode2_group_2_end_1
- input_datetime.heating_time_mode2_group_2_end_2
- input_datetime.heating_time_mode2_group_2_end_3
- input_datetime.heating_time_mode2_group_2_end_4
- input_datetime.heating_time_mode2_group_2_end_5
- input_number.heating_number_mode2_group_1_temp_1
- input_number.heating_number_mode2_group_1_temp_2
- input_number.heating_number_mode2_group_1_temp_3
- input_number.heating_number_mode2_group_1_temp_4
- input_number.heating_number_mode2_group_1_temp_5
- input_number.heating_number_mode2_group_2_temp_1
- input_number.heating_number_mode2_group_2_temp_2
- input_number.heating_number_mode2_group_2_temp_3
- input_number.heating_number_mode2_group_2_temp_4
- input_number.heating_number_mode2_group_2_temp_5
variables:
# 星期几
varWeekDay: >-
{{ now().isoweekday() }}
# 工作日/休息日
varGroup: >-
{# # 初始化 # #}
{% set numGroup = "0" %}
{# # 工作日 # #}
{% if is_state("input_boolean.heating_boolean_group_1_week_" + varWeekDay | string,"on") %}
{% set numGroup = "1" %}
{% endif %}
{# # 休息日 # #}
{% if is_state("input_boolean.heating_boolean_group_2_week_" + varWeekDay | string,"on") %}
{% set numGroup = "2" %}
{% endif %}
{# # 返回数据 # #}
{{ numGroup }}
# 温度
varTemperature: >-
{# # 初始化 # #}
{% set numTemp = 0.0 %}
{# # 循环5个时间段 # #}
{# # 时间段启动 # #}
{% if is_state("input_boolean.heating_boolean_mode2_group_" + varGroup | string + "_switch_1","on") %}
{# # 开始<结束 # #}
{% if states("input_datetime.heating_time_mode2_group_" + varGroup | string + "_start_1") < states("input_datetime.heating_time_mode2_group_" + varGroup | string + "_end_1") %}
{# # 开始<=现在时间<结束 # #}
{% if states('sensor.time') >= (state_attr("input_datetime.heating_time_mode2_group_" + varGroup | string + "_start_1",'timestamp') | int | timestamp_custom('%H:%M', False)) %}
{% if states('sensor.time') < (state_attr("input_datetime.heating_time_mode2_group_" + varGroup | string + "_end_1",'timestamp') | int | timestamp_custom('%H:%M', False)) %}
{# # 如果设定温度更高 # #}
{% if states("input_number.heating_number_mode2_group_" + varGroup | string + "_temp_1") | float > numTemp | float %}
{# # 设定温度 # #}
{% set numTemp = states("input_number.heating_number_mode2_group_" + varGroup | string + "_temp_1") | float %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{# # 时间段启动 # #}
{% if is_state("input_boolean.heating_boolean_mode2_group_" + varGroup | string + "_switch_2","on") %}
{# # 开始<结束 # #}
{% if states("input_datetime.heating_time_mode2_group_" + varGroup | string + "_start_2") < states("input_datetime.heating_time_mode2_group_" + varGroup | string + "_end_2") %}
{# # 开始<=现在时间<结束 # #}
{% if states('sensor.time') >= (state_attr("input_datetime.heating_time_mode2_group_" + varGroup | string + "_start_2",'timestamp') | int | timestamp_custom('%H:%M', False)) %}
{% if states('sensor.time') < (state_attr("input_datetime.heating_time_mode2_group_" + varGroup | string + "_end_2",'timestamp') | int | timestamp_custom('%H:%M', False)) %}
{# # 如果设定温度更高 # #}
{% if states("input_number.heating_number_mode2_group_" + varGroup | string + "_temp_2") | float > numTemp | float %}
{# # 设定温度 # #}
{% set numTemp = states("input_number.heating_number_mode2_group_" + varGroup | string + "_temp_2") | float %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{# # 时间段启动 # #}
{% if is_state("input_boolean.heating_boolean_mode2_group_" + varGroup | string + "_switch_3","on") %}
{# # 开始<结束 # #}
{% if states("input_datetime.heating_time_mode2_group_" + varGroup | string + "_start_3") < states("input_datetime.heating_time_mode2_group_" + varGroup | string + "_end_3") %}
{# # 开始<=现在时间<结束 # #}
{% if states('sensor.time') >= (state_attr("input_datetime.heating_time_mode2_group_" + varGroup | string + "_start_3",'timestamp') | int | timestamp_custom('%H:%M', False)) %}
{% if states('sensor.time') < (state_attr("input_datetime.heating_time_mode2_group_" + varGroup | string + "_end_3",'timestamp') | int | timestamp_custom('%H:%M', False)) %}
{# # 如果设定温度更高 # #}
{% if states("input_number.heating_number_mode2_group_" + varGroup | string + "_temp_3") | float > numTemp | float %}
{# # 设定温度 # #}
{% set numTemp = states("input_number.heating_number_mode2_group_" + varGroup | string + "_temp_3") | float %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{# # 时间段启动 # #}
{% if is_state("input_boolean.heating_boolean_mode2_group_" + varGroup | string + "_switch_4","on") %}
{# # 开始<结束 # #}
{% if states("input_datetime.heating_time_mode2_group_" + varGroup | string + "_start_4") < states("input_datetime.heating_time_mode2_group_" + varGroup | string + "_end_4") %}
{# # 开始<=现在时间<结束 # #}
{% if states('sensor.time') >= (state_attr("input_datetime.heating_time_mode2_group_" + varGroup | string + "_start_4",'timestamp') | int | timestamp_custom('%H:%M', False)) %}
{% if states('sensor.time') < (state_attr("input_datetime.heating_time_mode2_group_" + varGroup | string + "_end_4",'timestamp') | int | timestamp_custom('%H:%M', False)) %}
{# # 如果设定温度更高 # #}
{% if states("input_number.heating_number_mode2_group_" + varGroup | string + "_temp_4") | float > numTemp | float %}
{# # 设定温度 # #}
{% set numTemp = states("input_number.heating_number_mode2_group_" + varGroup | string + "_temp_4") | float %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{# # 时间段启动 # #}
{% if is_state("input_boolean.heating_boolean_mode2_group_" + varGroup | string + "_switch_5","on") %}
{# # 开始<结束 # #}
{% if states("input_datetime.heating_time_mode2_group_" + varGroup | string + "_start_5") < states("input_datetime.heating_time_mode2_group_" + varGroup | string + "_end_5") %}
{# # 开始<=现在时间<结束 # #}
{% if states('sensor.time') >= (state_attr("input_datetime.heating_time_mode2_group_" + varGroup | string + "_start_5",'timestamp') | int | timestamp_custom('%H:%M', False)) %}
{% if states('sensor.time') < (state_attr("input_datetime.heating_time_mode2_group_" + varGroup | string + "_end_5",'timestamp') | int | timestamp_custom('%H:%M', False)) %}
{# # 如果设定温度更高 # #}
{% if states("input_number.heating_number_mode2_group_" + varGroup | string + "_temp_5") | float > numTemp | float %}
{# # 设定温度 # #}
{% set numTemp = states("input_number.heating_number_mode2_group_" + varGroup | string + "_temp_5") | float %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{# # 返回数据 # #}
{{ numTemp }}
# Service
varService: >-
{# # 初始化 # #}
{% set varService = "" %}
{# # 有设定温度 # #}
{% if varTemperature | float > 0.0 %}
{# # 判断是否启动燃气炉 # #}
{% if states('sensor.heating_temperature') | float < ( varTemperature | float - 0.5 ) %}
{% set varService = "turn_on" %}
{% endif %}
{# # 判断是否关闭燃气炉 # #}
{% if states('sensor.heating_temperature') | float > ( varTemperature | float + 0.5 ) %}
{% set varService = "turn_off" %}
{% endif %}
{% endif %}
{# # 返回结果 # #}
{{ varService }}
condition:
# 打开状态
- condition: state
entity_id: input_boolean.heating_boolean_on_off_1
state: "on"
# 自动模式
- condition: state
entity_id: input_boolean.heating_boolean_manual_1
state: "off"
# 暖气关闭
# - condition: state
# entity_id: switch.cooking_room_heating
# state: "off"
# 判断是否需要控制暖气
- condition: template
value_template: >-
{# # 初始化 # #}
{% set isHeating = False %}
{# # 需要打开 and 暖气现在关闭 # #}
{% if varService == 'turn_on' and is_state("switch.cooking_room_heating","off") %}
{% set isHeating = True %}
{% endif %}
{# # 需要关闭 and 暖气现在打开 # #}
{% if varService == 'turn_off' and is_state("switch.cooking_room_heating","on") %}
{% set isHeating = True %}
{% endif %}
{# # 返回结果 # #}
{{ isHeating }}
action:
# - service: notify.persistent_notification
# data:
# title: "var"
# message: "Group:{{ varGroup }} Temp:{{ varTemperature }} Service:{{ varService }}"
- service: "switch.{{ varService }}"
data:
entity_id: switch.cooking_room_heating
|