# ------------------------------------------------------------------------------#
# 倒计时 打开手动加热
# ------------------------------------------------------------------------------#
- alias: Heating Turn On Manual By Timer Change
id: heating_turn_on_manual_by_timer_change
trigger:
# 改变倒计时时间
- platform: numeric_state
entity_id: input_number.heating_number_open_duration
above: "0.0"
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"
# 倒计时不是0
- condition: numeric_state
entity_id: input_number.heating_number_open_duration
above: "0.0"
action:
# 备份手动温度
- service: input_number.set_value
data_template:
entity_id: input_number.heating_number_save_temp_manual
value: >-
{{ states("input_number.heating_number_temp_manual_1") }}
# 手动温度设置为最大
- service: input_number.set_value
data:
entity_id: input_number.heating_number_temp_manual_1
value: "30"
# 打开手动模式
- service: input_boolean.turn_on
data:
entity_id: input_boolean.heating_boolean_manual_1
# ------------------------------------------------------------------------------#
# 倒计时 关闭手动加热
# ------------------------------------------------------------------------------#
- alias: Heating Turn off Manual By Timer To Zero
id: heating_turn_off_manual_by_timer_to_zero
trigger:
# 清零倒计时时间
- platform: state
entity_id: input_number.heating_number_open_duration
to: "0.0"
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: "on"
# 倒计时是0
# - condition: state
# entity_id: input_number.heating_number_open_duration
# state: "0.0"
# 备份温度大于0
- condition: numeric_state
entity_id: input_number.heating_number_save_temp_manual
above: "0.0"
action:
# 还原手动温度
- service: input_number.set_value
data_template:
entity_id: input_number.heating_number_temp_manual_1
value: >-
{{ states("input_number.heating_number_save_temp_manual") }}
# 清空备份温度
- service: input_number.set_value
data:
entity_id: input_number.heating_number_save_temp_manual
value: "0"
# 关闭手动模式
- service: input_boolean.turn_off
data:
entity_id: input_boolean.heating_boolean_manual_1
# ------------------------------------------------------------------------------#
# 关闭手动模式时还原温度和清空倒计时
# 关闭手动模式的处理,无法调用 倒计时 关闭手动加热,因为手动模式已经关闭
# ------------------------------------------------------------------------------#
- alias: Heating Reset Timer By Turn Off Manual
id: heating_reset_timer_by_turn_off_manual
trigger:
# 关闭手动模式
- platform: state
entity_id: input_boolean.heating_boolean_manual_1
to: "off"
condition:
# 温控打开状态
- condition: state
entity_id: input_boolean.heating_boolean_on_off_1
state: "on"
# 备份温度大于0
- condition: numeric_state
entity_id: input_number.heating_number_save_temp_manual
above: "0.0"
action:
# 还原手动温度
- service: input_number.set_value
data_template:
entity_id: input_number.heating_number_temp_manual_1
value: >-
{{ states("input_number.heating_number_save_temp_manual") }}
# 清空备份温度
- service: input_number.set_value
data:
entity_id: input_number.heating_number_save_temp_manual
value: "0"
# 清空倒计时
- service: input_number.set_value
data:
entity_id: input_number.heating_number_open_duration
value: "0"
# ------------------------------------------------------------------------------#
# 倒计时 关闭手动加热
# ------------------------------------------------------------------------------#
- alias: Heating Turn Off Manual By Timer Limit
id: heating_turn_off_manual_by_timer_limit
trigger:
# 每1分钟执行
- platform: time_pattern
minutes: "/1"
seconds: "12"
condition:
# 手动模式打开
- condition: state
entity_id: input_boolean.heating_boolean_manual_1
state: "on"
# 倒计时大于0
- condition: numeric_state
entity_id: input_number.heating_number_open_duration
above: "0"
# 超过设定时间
- condition: template
value_template: >-
{{ (as_timestamp(now()) - as_timestamp(states.input_boolean.heating_boolean_manual_1.last_changed)) | int >= states("input_number.heating_number_open_duration") | int * 60 }}
action:
# # 还原手动温度
# - service: input_number.set_value
# data_template:
# entity_id: input_number.heating_number_temp_manual_1
# value: >-
# {{ states("input_number.heating_number_save_temp_manual") }}
# # 清空倒计时
# - service: input_number.set_value
# data:
# entity_id: input_number.heating_number_open_duration
# value: "0"
# # 关闭手动模式
# - service: input_boolean.turn_off
# data:
# entity_id: input_boolean.heating_boolean_manual_1
#
# 清空倒计时,自动调用 倒计时 关闭手动加热
- service: input_number.set_value
data:
entity_id: input_number.heating_number_open_duration
value: "0"
# ------------------------------------------------------------------------------#
# 手动模式 手动模式关闭后不会自动关闭燃气炉,等温度到达当天设定的温度后燃气炉才会关闭
# ------------------------------------------------------------------------------#
- alias: Heating Turn On Off Schedule Manual
id: "heating_turn_on_off_schedule_manual"
trigger:
# 每1分钟执行
- platform: time_pattern
minutes: "/1"
seconds: "13"
# 变更手动温度
- platform: state
entity_id: input_number.heating_number_temp_manual_1
# 手动模式
- platform: state
entity_id: input_boolean.heating_boolean_manual_1
to: "on"
variables:
varService: >-
{# # 初始化 # #}
{% set varService = "" %}
{# # 低温 # #}
{% if states('sensor.heating_temperature') | float < ( states('input_number.heating_number_temp_manual_1') | float - 0.5 ) %}
{% if is_state("switch.cooking_room_heating","off") %}
{% set varService = "turn_on" %}
{% endif %}
{% endif %}
{# # 高温 # #}
{% if states('sensor.heating_temperature') | float > ( states('input_number.heating_number_temp_manual_1') | float + 0.5 ) %}
{% if is_state("switch.cooking_room_heating","on") %}
{% 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: "on"
# 判断是否需要操作燃气炉
- condition: template
value_template: "{{ varService == 'turn_on' or varService == 'turn_off' }}"
# {# # 初始化 # #}
# {% set isHeating = false %}
# {% set varService = "" %}
# {# # 低温 # #}
# {% if states('sensor.heating_temperature') | float < ( states('input_number.heating_number_temp_manual_1') | float - 0.5 ) %}
# {% if is_state("switch.cooking_room_heating","off") %}
# {% set isHeating = true %}
# {% endif %}
# {% endif %}
# {# # 高温 # #}
# {% if states('sensor.heating_temperature') | float > ( states('input_number.heating_number_temp_manual_1') | float + 0.5 ) %}
# {% if is_state("switch.cooking_room_heating","on") %}
# {% set isHeating = true %}
# {% endif %}
# {% endif %}
# {# # 返回结果 # #}
# {{ isHeating }}
action:
# 打开暖气
- service: "switch.{{ varService }}"
data:
entity_id: switch.cooking_room_heating
# ------------------------------------------------------------------------------#
# 手动温度 0度时候自动设置22度
# ------------------------------------------------------------------------------#
- alias: Heating Set Initialize Value Manual Temp
id: "heating_set_initialize_value_manual_temp"
trigger:
# 系统启动时
- platform: homeassistant
event: start
# 温控打开时
- platform: state
entity_id: input_boolean.heating_boolean_on_off_1
condition:
# 温控打开状态
- condition: state
entity_id: input_boolean.heating_boolean_on_off_1
state: "on"
# 手动温度是0度
- condition: state
entity_id: input_number.heating_number_temp_manual_1
state: "0"
action:
- service: input_number.set_value
data:
entity_id: input_number.heating_number_temp_manual_1
value: "22"
# ------------------------------------------------------------------------------#
# 星期设置 未开启 自动开启
# ------------------------------------------------------------------------------#
- alias: Heating Set Initialize Value On Week All Close
id: "heating_set_initialize_value_on_week_all_close"
trigger:
# 系统启动时
- platform: homeassistant
event: start
# 温控打开时
- platform: state
entity_id: input_boolean.heating_boolean_on_off_1
# 每1分钟执行 在温度检查之前执行
# - platform: time_pattern
# minutes: '/1'
# seconds: '58'
condition:
# 温控打开状态
- condition: state
entity_id: input_boolean.heating_boolean_on_off_1
state: "on"
# 全打开的自动化执行10秒后才执行
# - condition: template
# value_template: >-
# {% if state_attr('automation.heating_set_initialize_value_on_week_all_open','last_triggered') == 'None' %}
# true
# {% else %}
# {{ (as_timestamp(now()) - as_timestamp(state_attr('automation.heating_set_initialize_value_on_week_all_open','last_triggered')) | int > 10 }}
# {% endif %}
action:
# 周1 同时打开
- service: >-
{% if is_state('input_boolean.heating_boolean_group_1_week_1','off') and
is_state('input_boolean.heating_boolean_group_2_week_1','off') %}
input_boolean.turn_on
{% else %}
script.none
{% endif %}
data_template:
entity_id: input_boolean.heating_boolean_group_1_week_1
# 周2 同时打开
- service: >-
{% if is_state('input_boolean.heating_boolean_group_1_week_2','off') and
is_state('input_boolean.heating_boolean_group_2_week_2','off') %}
input_boolean.turn_on
{% else %}
script.none
{% endif %}
data_template:
entity_id: input_boolean.heating_boolean_group_1_week_2
# 周3 同时打开
- service: >-
{% if is_state('input_boolean.heating_boolean_group_1_week_3','off') and
is_state('input_boolean.heating_boolean_group_2_week_3','off') %}
input_boolean.turn_on
{% else %}
script.none
{% endif %}
data_template:
entity_id: input_boolean.heating_boolean_group_1_week_3
# 周4 同时打开
- service: >-
{% if is_state('input_boolean.heating_boolean_group_1_week_4','off') and
is_state('input_boolean.heating_boolean_group_2_week_4','off') %}
input_boolean.turn_on
{% else %}
script.none
{% endif %}
data_template:
entity_id: input_boolean.heating_boolean_group_1_week_4
# 周5 同时打开
- service: >-
{% if is_state('input_boolean.heating_boolean_group_1_week_5','off') and
is_state('input_boolean.heating_boolean_group_2_week_5','off') %}
input_boolean.turn_on
{% else %}
script.none
{% endif %}
data_template:
entity_id: input_boolean.heating_boolean_group_1_week_5
# 周6 同时打开
- service: >-
{% if is_state('input_boolean.heating_boolean_group_1_week_6','off') and
is_state('input_boolean.heating_boolean_group_2_week_6','off') %}
input_boolean.turn_on
{% else %}
script.none
{% endif %}
data_template:
entity_id: input_boolean.heating_boolean_group_2_week_6
# 周日 同时打开
- service: >-
{% if is_state('input_boolean.heating_boolean_group_1_week_7','off') and
is_state('input_boolean.heating_boolean_group_2_week_7','off') %}
input_boolean.turn_on
{% else %}
script.none
{% endif %}
data_template:
entity_id: input_boolean.heating_boolean_group_2_week_7
# ------------------------------------------------------------------------------#
# 星期设置重复 自动关闭
# ------------------------------------------------------------------------------#
- alias: Heating Set Initialize Value On Week All Open
id: "heating_set_initialize_value_on_week_all_open"
trigger:
# 系统启动时
- platform: homeassistant
event: start
# 温控打开时
- platform: state
entity_id: input_boolean.heating_boolean_on_off_1
# 更改星期时
- platform: state
entity_id:
- input_boolean.heating_boolean_group_1_week_1
- input_boolean.heating_boolean_group_1_week_2
- input_boolean.heating_boolean_group_1_week_3
- input_boolean.heating_boolean_group_1_week_4
- input_boolean.heating_boolean_group_1_week_5
- input_boolean.heating_boolean_group_1_week_6
- input_boolean.heating_boolean_group_1_week_7
- input_boolean.heating_boolean_group_2_week_1
- input_boolean.heating_boolean_group_2_week_2
- input_boolean.heating_boolean_group_2_week_3
- input_boolean.heating_boolean_group_2_week_4
- input_boolean.heating_boolean_group_2_week_5
- input_boolean.heating_boolean_group_2_week_6
- input_boolean.heating_boolean_group_2_week_7
condition:
# 温控打开状态
- condition: state
entity_id: input_boolean.heating_boolean_on_off_1
state: "on"
# # 日期编辑模式
# - condition: state
# entity_id: input_boolean.heating_boolean_edit_mode_1
# state: 'on'
action:
# 周1 同时打开
- service: >-
{% if is_state('input_boolean.heating_boolean_group_1_week_1','on') and
is_state('input_boolean.heating_boolean_group_2_week_1','on') %}
input_boolean.turn_off
{% else %}
script.none
{% endif %}
data_template:
entity_id: input_boolean.heating_boolean_group_2_week_1
# 周2 同时打开
- service: >-
{% if is_state('input_boolean.heating_boolean_group_1_week_2','on') and
is_state('input_boolean.heating_boolean_group_2_week_2','on') %}
input_boolean.turn_off
{% else %}
script.none
{% endif %}
data_template:
entity_id: input_boolean.heating_boolean_group_2_week_2
# 周3 同时打开
- service: >-
{% if is_state('input_boolean.heating_boolean_group_1_week_3','on') and
is_state('input_boolean.heating_boolean_group_2_week_3','on') %}
input_boolean.turn_off
{% else %}
script.none
{% endif %}
data_template:
entity_id: input_boolean.heating_boolean_group_2_week_3
# 周4 同时打开
- service: >-
{% if is_state('input_boolean.heating_boolean_group_1_week_4','on') and
is_state('input_boolean.heating_boolean_group_2_week_4','on') %}
input_boolean.turn_off
{% else %}
script.none
{% endif %}
data_template:
entity_id: input_boolean.heating_boolean_group_2_week_4
# 周5 同时打开
- service: >-
{% if is_state('input_boolean.heating_boolean_group_1_week_5','on') and
is_state('input_boolean.heating_boolean_group_2_week_5','on') %}
input_boolean.turn_off
{% else %}
script.none
{% endif %}
data_template:
entity_id: input_boolean.heating_boolean_group_2_week_5
# 周6 同时打开
- service: >-
{% if is_state('input_boolean.heating_boolean_group_1_week_6','on') and
is_state('input_boolean.heating_boolean_group_2_week_6','on') %}
input_boolean.turn_off
{% else %}
script.none
{% endif %}
data_template:
entity_id: input_boolean.heating_boolean_group_1_week_6
# 周日 同时打开
- service: >-
{% if is_state('input_boolean.heating_boolean_group_1_week_7','on') and
is_state('input_boolean.heating_boolean_group_2_week_7','on') %}
input_boolean.turn_off
{% else %}
script.none
{% endif %}
data_template:
entity_id: input_boolean.heating_boolean_group_1_week_7
# ------------------------------------------------------------------------------#
# 温度/时间 设置检查
# ------------------------------------------------------------------------------#
- alias: Heating Mode2 Set Initialize Value
id: "heating_mode2_set_initialize_value"
trigger:
# 系统启动时
- platform: homeassistant
event: start
# 温控打开时
- platform: state
entity_id: input_boolean.heating_boolean_on_off_1
to: "on"
variables:
varSetGroup1_Init: >-
{# # 初始化 # #}
{% set varInitTime = False %}
{% set varInitTemp = False %}
{% set varGroup = "1" %}
{# # 全部时间段未打开时 # #}
{% if is_state("input_boolean.heating_boolean_mode2_group_" + varGroup +"_switch_1","off") and
is_state("input_boolean.heating_boolean_mode2_group_" + varGroup +"_switch_2","off") and
is_state("input_boolean.heating_boolean_mode2_group_" + varGroup +"_switch_3","off") and
is_state("input_boolean.heating_boolean_mode2_group_" + varGroup +"_switch_4","off") and
is_state("input_boolean.heating_boolean_mode2_group_" + varGroup +"_switch_5","off") %}
{% set varInitTime = True %}
{% endif %}
{# # 全部时间段温度相同 # #}
{% if states("input_datetime.heating_time_mode2_group_" + varGroup +"_start_1") == states("input_datetime.heating_time_mode2_group_" + varGroup +"_end_1") and
states("input_datetime.heating_time_mode2_group_" + varGroup +"_start_2") == states("input_datetime.heating_time_mode2_group_" + varGroup +"_end_2") and
states("input_datetime.heating_time_mode2_group_" + varGroup +"_start_3") == states("input_datetime.heating_time_mode2_group_" + varGroup +"_end_3") and
states("input_datetime.heating_time_mode2_group_" + varGroup +"_start_4") == states("input_datetime.heating_time_mode2_group_" + varGroup +"_end_4") and
states("input_datetime.heating_time_mode2_group_" + varGroup +"_start_5") == states("input_datetime.heating_time_mode2_group_" + varGroup +"_end_5") %}
{% set varInitTemp = True %}
{% endif %}
{# # 开关和时间段都是初期状态的话,返回需要初始化 # #}
{% if varInitTime == True or varInitTemp == True %}
True
{% else %}
False
{% endif %}
varSetGroup1_Init_Service_Boolean: >-
{% if varSetGroup1_Init == True %}
input_boolean.turn_on
{% else %}
script.none
{% endif %}
varSetGroup1_Init_Service_Datetime: >-
{% if varSetGroup1_Init == True %}
input_datetime.set_datetime
{% else %}
script.none
{% endif %}
varSetGroup1_Init_Service_Number: >-
{% if varSetGroup1_Init == True %}
input_number.set_value
{% else %}
script.none
{% endif %}
varSetGroup2_Init: >-
{# # 初始化 # #}
{% set varInitTime = False %}
{% set varInitTemp = False %}
{% set varGroup = "2" %}
{# # 全部时间段未打开时 # #}
{% if is_state("input_boolean.heating_boolean_mode2_group_" + varGroup +"_switch_1","off") and
is_state("input_boolean.heating_boolean_mode2_group_" + varGroup +"_switch_2","off") and
is_state("input_boolean.heating_boolean_mode2_group_" + varGroup +"_switch_3","off") and
is_state("input_boolean.heating_boolean_mode2_group_" + varGroup +"_switch_4","off") and
is_state("input_boolean.heating_boolean_mode2_group_" + varGroup +"_switch_5","off") %}
{% set varInitTime = True %}
{% endif %}
{# # 全部时间段温度相同 # #}
{% if states("input_datetime.heating_time_mode2_group_" + varGroup +"_start_1") == states("input_datetime.heating_time_mode2_group_" + varGroup +"_end_1") and
states("input_datetime.heating_time_mode2_group_" + varGroup +"_start_2") == states("input_datetime.heating_time_mode2_group_" + varGroup +"_end_2") and
states("input_datetime.heating_time_mode2_group_" + varGroup +"_start_3") == states("input_datetime.heating_time_mode2_group_" + varGroup +"_end_3") and
states("input_datetime.heating_time_mode2_group_" + varGroup +"_start_4") == states("input_datetime.heating_time_mode2_group_" + varGroup +"_end_4") and
states("input_datetime.heating_time_mode2_group_" + varGroup +"_start_5") == states("input_datetime.heating_time_mode2_group_" + varGroup +"_end_5") %}
{% set varInitTemp = True %}
{% endif %}
{# # 开关和时间段都是初期状态的话,返回需要初始化 # #}
{% if varInitTime == True or varInitTemp == True %}
True
{% else %}
False
{% endif %}
varSetGroup2_Init_Service_Boolean: >-
{% if varSetGroup2_Init == True %}
input_boolean.turn_on
{% else %}
script.none
{% endif %}
varSetGroup2_Init_Service_Datetime: >-
{% if varSetGroup2_Init == True %}
input_datetime.set_datetime
{% else %}
script.none
{% endif %}
varSetGroup2_Init_Service_Number: >-
{% if varSetGroup2_Init == True %}
input_number.set_value
{% else %}
script.none
{% endif %}
condition:
# 温控打开状态
- condition: state
entity_id: input_boolean.heating_boolean_on_off_1
state: "on"
# 需要初始化
- condition: template
value_template: "{{ varSetGroup1_Init == True or varSetGroup2_Init == True }}"
action:
# - service: notify.persistent_notification
# data:
# title: "var"
# message: "Boolean:{{ varSetGroup1_Init_Service_Boolean }} Datetime:{{ varSetGroup1_Init_Service_Datetime }} Number:{{ varSetGroup1_Init_Service_Number }} "
#####################
# 工作日
#####################
# 打开时间段1
- service: "{{ varSetGroup1_Init_Service_Boolean }}"
data:
entity_id: input_boolean.heating_boolean_mode2_group_1_switch_1
# 设定时间段1开始
- service: "{{ varSetGroup1_Init_Service_Datetime }}"
data:
entity_id: input_datetime.heating_time_mode2_group_1_start_1
time: "00:00:00"
# 设定时间段1结束
- service: "{{ varSetGroup1_Init_Service_Datetime }}"
data:
entity_id: input_datetime.heating_time_mode2_group_1_end_1
time: "23:59:59"
# 设定时间段1温度
- service: "{{ varSetGroup1_Init_Service_Number }}"
data:
entity_id: input_number.heating_number_mode2_group_1_temp_1
value: "19"
# 打开时间段2
- service: "{{ varSetGroup1_Init_Service_Boolean }}"
data:
entity_id: input_boolean.heating_boolean_mode2_group_1_switch_2
# 设定时间段2开始
- service: "{{ varSetGroup1_Init_Service_Datetime }}"
data:
entity_id: input_datetime.heating_time_mode2_group_1_start_2
time: "05:00:00"
# 设定时间段2结束
- service: "{{ varSetGroup1_Init_Service_Datetime }}"
data:
entity_id: input_datetime.heating_time_mode2_group_1_end_2
time: "22:00:00"
# 设定时间段2温度
- service: "{{ varSetGroup1_Init_Service_Number }}"
data:
entity_id: input_number.heating_number_mode2_group_1_temp_2
value: "21.5"
#####################
# 休息日
#####################
# 打开时间段1
- service: "{{ varSetGroup2_Init_Service_Boolean }}"
data:
entity_id: input_boolean.heating_boolean_mode2_group_2_switch_1
# 设定时间段1开始
- service: "{{ varSetGroup2_Init_Service_Datetime }}"
data:
entity_id: input_datetime.heating_time_mode2_group_2_start_1
time: "00:00:00"
# 设定时间段1结束
- service: "{{ varSetGroup2_Init_Service_Datetime }}"
data:
entity_id: input_datetime.heating_time_mode2_group_2_end_1
time: "23:59:59"
# 设定时间段1温度
- service: "{{ varSetGroup2_Init_Service_Number }}"
data:
entity_id: input_number.heating_number_mode2_group_2_temp_1
value: "19"
# 打开时间段2
- service: "{{ varSetGroup2_Init_Service_Boolean }}"
data:
entity_id: input_boolean.heating_boolean_mode2_group_2_switch_2
# 设定时间段2开始
- service: "{{ varSetGroup2_Init_Service_Datetime }}"
data:
entity_id: input_datetime.heating_time_mode2_group_2_start_2
time: "06:00:00"
# 设定时间段2结束
- service: "{{ varSetGroup2_Init_Service_Datetime }}"
data:
entity_id: input_datetime.heating_time_mode2_group_2_end_2
time: "22:00:00"
# 设定时间段2温度
- service: "{{ varSetGroup2_Init_Service_Number }}"
data:
entity_id: input_number.heating_number_mode2_group_2_temp_2
value: "21.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 ) }}"
# 判断是否需要启动燃气炉
# - condition: template
# value_template: >-
# {# # 初始化 # #}
# {% set isHeating = false %}
# {% if states("input_datetime.heating_time_timer_exec_start_time_1") == (states("sensor.time") + ":00") %}
# {% set isHeating = true %}
# {% endif %}
# {% if states("input_datetime.heating_time_timer_exec_start_time_2") == (states("sensor.time") + ":00") %}
# {% set isHeating = true %}
# {% endif %}
# {% if states("input_datetime.heating_time_timer_exec_start_time_3") == (states("sensor.time") + ":00") %}
# {% set isHeating = true %}
# {% endif %}
# {% if states("input_datetime.heating_time_timer_exec_start_time_4") == (states("sensor.time") + ":00") %}
# {% set isHeating = true %}
# {% endif %}
# {# # 返回结果 # #}
# {{ isHeating }}
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 }}
# # Test
# varTest: >-
# {# # 初始化 # #}
# {% set numTemp = "0" %}
# {# # 循环5个时间段 # #}
# {% for i in ["1","2","3","4","5"] %}
# {% set numTemp = i %}
# {% endfor %}
# {{ numTemp }}
# {# # 循环5个时间段 # #}
# {% for i in ["1","2","3","4","5"] %}
# {# # 时间段启动 # #}
# {% if is_state("input_boolean.heating_boolean_mode2_group_" + varGroup | string + "_switch_" + i | string,"on") %}
# {# # 开始<结束 # #}
# {% if states("input_datetime.heating_time_mode2_group_" + varGroup | string + "_start_" + i | string) < states("input_datetime.heating_time_mode2_group_" + varGroup | string + "_end_" + i | string) %}
# {# # 开始<=现在时间<结束 # #}
# {% if states('sensor.time') >= (state_attr("input_datetime.heating_time_mode2_group_" + varGroup | string + "_start_" + i | string,'timestamp') | int | timestamp_custom('%H:%M', False)) %}
# {% if states('sensor.time') < (state_attr("input_datetime.heating_time_mode2_group_" + varGroup | string + "_end_" + i | string,'timestamp') | int | timestamp_custom('%H:%M', False)) %}
# {# # 如果设定温度更高 # #}
# {% if states("input_number.heating_number_mode2_group_" + varGroup | string + "_temp_" + i | string) | float > numTemp | float %}
# {# # 设定温度 # #}
# {% set numTemp = states("input_number.heating_number_mode2_group_" + varGroup | string + "_temp_" + i | string) | float %}
# {% endif %}
# {% endif %}
# {% endif %}
# {% endif %}
# {% endif %}
# {% endfor %}
# 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