本帖最后由 hunl1986 于 2023-5-17 19:02 编辑
终于搞定,原来climate.set_operation_mode服务不能用,要改为climate.set_hvac_mode,新版本原来的代码不能用。
把代码给大家看看
## 倒计时通用面板
homeassistant:
customize:
sensor.timer_setting:
friendly_name: 设置延迟时间
icon: mdi:timer
input_number.timer_hour:
friendly_name: 时
icon: mdi:timer
input_number.timer_min:
friendly_name: 分
icon: mdi:timer
input_number.timer_sec:
friendly_name: 秒
icon: mdi:timer
# hidden: true
timer.timer:
friendly_name: 延迟倒计时
icon: mdi:timer
script.timer_start:
friendly_name: 开始倒计时
icon: mdi:timer
script.timer_cancel:
friendly_name: 取消倒计时
icon: mdi:timer-off
input_select:
timer_climate:
name: 延时关闭空调
options:
- 选择空调
- 客厅空调
- 主卧空调
- 次卧空调
- 客卧空调
initial: '选择空调'
icon: mdi:format-list-checkbox #select-all #toggle-switch-off
timer_switch:
name: 延时关闭设备
options:
- 选择设备
- 客厅大灯
- 客厅餐灯
- 未定义8
- 未定义9
- 未定义0
initial: '选择设备'
icon: mdi:format-list-checkbox #select-all #toggle-switch-off
timer_state:
name: 操作
options:
- 开
- 关
initial: '关'
icon: mdi:light-switch #nintendo-switch
sensor:
- platform: template
sensors:
timer_setting:
friendly_name: 'Time'
value_template: '{{ "%0.02d:%0.02d:%0.02d" | format(states("input_number.timer_hour") | int, states("input_number.timer_min") | int, states("input_number.timer_sec") | int) }}'
input_number:
timer_hour:
name: TimerHour
# icon: mdi:timer
# initial: 00
min: 0
max: 23
step: 1
timer_min:
name: TimerMinute
# icon: mdi:timer
# initial: 00
min: 0
max: 59
step: 1
timer_sec:
name: TimerSecond
# icon: mdi:timer
initial: 00
min: 0
max: 59
step: 1
timer:
timer:
duration: '00:00:00'
script:
timer_start:
sequence:
service: timer.start
data_template:
entity_id: timer.timer
duration: >
{{ states("sensor.timer_setting") }}
timer_cancel:
sequence:
service: timer.cancel
entity_id: timer.timer
group:
timer_switch:
name: 通用延时器
entities:
- input_select.timer_climate
- input_select.timer_switch
- input_select.timer_state
- sensor.timer_setting
- input_number.timer_hour
- input_number.timer_min
- input_number.timer_sec
- timer.timer
- script.timer_start
- script.timer_cancel
# binary_sensor:
# - platform: platform: state
# name: timer_climate
# entity_id: input_select.timer_climate
# payload_on: "Select Input"
# - platform: platform: state
# name: timer_switch
# entity_id: input_select.timer_switch
# payload_on: "Select Input"
automation:
- alias: number_timer
hide_entity: true
trigger:
- platform: state
entity_id: sensor.timer_setting
action:
service: timer.start
data_template:
entity_id: timer.timer
duration: >
{{ states("sensor.timer_setting") }}
- alias: empty_timer
hide_entity: true
trigger:
- platform: state
entity_id: input_select.timer_climate
- platform: state
entity_id: input_select.timer_switch
- platform: state
entity_id: input_select.timer_state
action:
- service: timer.cancel
entity_id: timer.timer
# - service: timer.start
# data_template:
# entity_id: timer.timer
# duration: >
# {{ states("sensor.timer_setting") }}
- alias: timer_climate_delay
hide_entity: true
trigger:
platform: event
event_type: timer.finished
event_data:
entity_id: timer.timer
action:
- service: climate.set_hvac_mode
data_template:
entity_id: >-
{% if is_state("input_select.timer_climate", "客厅空调") %}
climate.mqtt_34ea344dd13c
{% elif is_state("input_select.timer_climate", "主卧空调") %}
climate.mqtt_34ea3496151c
{% elif is_state("input_select.timer_climate", "次卧空调") %}
climate.entity_id3
{% elif is_state("input_select.timer_climate", "客卧空调") %}
climate.entity_id4
{% endif %}
hvac_mode: 'off'
#hvac_mode后面要改为自己控制的关闭代码,在开发者工具-服务可以看到
- service: input_select.select_option
data:
entity_id: input_select.timer_climate
option: "选择空调"
- alias: timer_switch_turnon
hide_entity: true
trigger:
platform: event
event_type: timer.finished
event_data:
entity_id: timer.timer
condition:
condition: state
entity_id: input_select.timer_state
state: '开'
action:
- service: homeassistant.turn_on
data_template:
entity_id: >-
{% if is_state("input_select.timer_switch", "客厅大灯") %}
light.fsl002_cloud_646808
{% elif is_state("input_select.timer_switch", "客厅餐灯") %}
light.wy0b01_cloud_056917
{% elif is_state("input_select.timer_switch", "未定义8") %}
switch.entity_id8
{% elif is_state("input_select.timer_switch", "未定义9") %}
switch.entity_id9
{% elif is_state("input_select.timer_switch", "未定义0") %}
switch.entity_id0
{% endif %}
- service: input_select.select_option
data:
entity_id: input_select.timer_switch
option: "选择设备"
- alias: timer_switch_turnoff
hide_entity: true
trigger:
platform: event
event_type: timer.finished
event_data:
entity_id: timer.timer
condition:
condition: state
entity_id: input_select.timer_state
state: '关'
action:
- service: homeassistant.turn_off
data_template:
entity_id: >-
{% if is_state("input_select.timer_switch", "客厅大灯") %}
light.fsl002_cloud_646808
{% elif is_state("input_select.timer_switch", "客厅餐灯") %}
light.wy0b01_cloud_056917
{% elif is_state("input_select.timer_switch", "未定义8") %}
switch.entity_id8
{% elif is_state("input_select.timer_switch", "未定义9") %}
switch.entity_id9
{% elif is_state("input_select.timer_switch", "未定义0") %}
switch.entity_id0
{% endif %}
- service: input_select.select_option
data:
entity_id: input_select.timer_switch
option: "选择设备"
|