以前要把多个同类型设备的自动化写到一起得用date_template 然后写很多if,
后来升级到某个版本之后,action中从此无法使用 jinja2 模板,导致后台报错无法执行。
今天翻看了下,居然有了这个功能,配合ESPHOME的设备自动化,感觉方便了很多。
以前的自动化模板:
- id: 1bc9067bd15d4760bf4ccd5290ae93c9
alias: 车库状态变化通知
trigger:
- event_data: {}
event_type: state_changed
platform: event
condition:
- condition: or
conditions:
- condition: and
conditions:
- condition: template
value_template: '{{ trigger.event.data.new_state.state != trigger.event.data.old_state.state
}}'
- condition: template
value_template: '{{ trigger.event.data.old_state.state == "closed" or trigger.event.data.old_state.state
== "open" }}'
- condition: template
value_template: '{{ trigger.event.data.entity_id.split(".")[0] == "cover"}}'
- condition: state
entity_id: sensor.chao_sheng_bo_chuan_gan_qi
state: unknown
- condition: template
value_template: '{{ trigger.event.data.entity_id != "cover.curtain_158d0002aca826"
}}'
- condition: not
conditions:
- condition: state
entity_id: sensor.chao_sheng_bo_chuan_gan_qi
state: unavailable
action:
- data_template:
data:
push:
badge: 1
category: garage
sound: '{% if trigger.event.data.new_state.state == "closed" %}Garage_had_been_closed.wav{%
elif trigger.event.data.new_state.state == "open" %}Garage_had_been_opened.wav{%
endif %}'
message: '{% if trigger.event.data.new_state.state == "closed" %} {{ trigger.event.data.new_state.attributes.friendly_name}}已关闭。
{% elif trigger.event.data.new_state.state == "open" %} {{ trigger.event.data.new_state.attributes.friendly_name}}被打开。{%
endif %}'
title: 安防通知
service: notify.mobile_app_iphone11
复制代码
现在的自动化:
- id: '1599898981144'
alias: 车库状态提醒
description: ''
trigger:
- device_id: 7a18b978cf99405787f256448d461efb
domain: cover
entity_id: cover.dong_che_ku_men
platform: device
type: opening
- device_id: 7a18b978cf99405787f256448d461efb
domain: cover
entity_id: cover.dong_che_ku_men
platform: device
type: closing
- device_id: 5b824882eb5e4d059e204ba8945f3709
domain: cover
entity_id: cover.xi_che_ku_men
platform: device
type: opening
- device_id: 5b824882eb5e4d059e204ba8945f3709
domain: cover
entity_id: cover.xi_che_ku_men
platform: device
type: closing
condition: []
action:
- choose:
- conditions:
- condition: or
conditions:
- condition: device
device_id: 7a18b978cf99405787f256448d461efb
domain: cover
entity_id: cover.dong_che_ku_men
type: is_closing
- condition: device
device_id: 5b824882eb5e4d059e204ba8945f3709
domain: cover
entity_id: cover.xi_che_ku_men
type: is_closing
sequence:
- data:
data:
push:
badge: 1
category: garage
sound: Garage_had_been_closed.wav
message: 车库门已关闭。
title: 安防通知
service: notify.mobile_app_iphone11
- conditions:
- condition: or
conditions:
- condition: device
device_id: 7a18b978cf99405787f256448d461efb
domain: cover
entity_id: cover.dong_che_ku_men
type: is_opening
- condition: device
device_id: 5b824882eb5e4d059e204ba8945f3709
domain: cover
entity_id: cover.xi_che_ku_men
type: is_opening
sequence:
- data:
data:
push:
badge: 1
category: garage
sound: Garage_had_been_opened.wav
message: 车库门已打开。
title: 安防通知
service: notify.mobile_app_iphone11
default: []
mode: single
复制代码
直接在前端选择就可以了~~一个字!方便!!