homeassistant-config-example/automations.yaml

205 lines
6.0 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# https://www.home-assistant.io/docs/automation/trigger/
# https://www.home-assistant.io/docs/automation/condition/
# https://www.home-assistant.io/docs/automation/action/
# 这个文件记录的是自动化的相关内容。
# 可以在达到某个条件时,触发一系列的操作。
# 回家时
# 这里用的一个临时方案。我tracking的方式有两种iCloud和ping。
# iCloud只能判断设备的大致范围而ping在手机休眠时有可能离线。
# 所以单独用任何一种都无法获得准确的到家时间。
# 现在先通过iCloud判断是否到了家附近是的话打开一个标记home_return_fuzzy。
# 然后通过ping来触发精确的到家时间点。
# ping默认间隔12秒所以到家进门连上设备+被ping到还是会有一点延迟。
# 旧方案是只用iCloud那就会有点提前。
# 开启即将到家的状态
# - id: home_return_fuzzy # 这个id没啥卵用 unique就行
# alias: Home Return Fuzzy # 这个名称会以下划线替换空格成为id
# description: 判断即将到家
# trigger:
# - entity_id: device_tracker.erimuss_iphonexr
# platform: state
# from: 'not_home'
# to: 'home'
# action:
# - service: input_boolean.turn_on # 状态记录器
# entity_id: input_boolean.home_return_fuzzy
# # 精确的到家时间 ping作为开关
# - id: home_return_exact
# alias: Home Return Exact # 这个名称会以下划线替换空格成为id
# description: 回家时开启电器
# trigger:
# - entity_id: device_tracker.pingiphonexr
# platform: state
# from: 'not_home'
# to: 'home'
# condition:
# condition: state
# entity_id: input_boolean.home_return_fuzzy
# state: 'on'
# action:
# - service: script.home_return_exact
# # 离家时
# - id: home_leave
# alias: Home Leave
# description: 离家时关闭电器
# trigger:
# - entity_id: device_tracker.erimuss_iphonexr
# platform: state
# from: 'home'
# to: 'not_home'
# # platform: zone
# # zone: zone.home
# # event: leave
# condition: # 防止iCloud偶尔抽风误触 加一个ping判断
# - condition: state
# entity_id: device_tracker.pingiphonexr
# state: 'not_home'
# action:
# - service: switch.turn_off
# entity_id:
# - switch.amplifier_smart
# - switch.water_pump
# - switch.aircon_power_off
# - group.light
# - service: input_boolean.turn_off # 状态记录器
# entity_id: input_boolean.home_return_fuzzy
# 监听水泵开启在15分钟后自动发送一次关闭命令。防止忘记关水泵。
- id: auto_turn_off_pump
alias: Auto turn off pump
description: 自动关水泵
trigger:
- entity_id: switch.water_pump
platform: state
from: 'off'
to: 'on'
for: 00:15:00
condition: []
action:
- entity_id: switch.water_pump
service: switch.turn_off
# 每整点关一次水泵 避免漏关
- id: auto_turn_off_pump_hourly
alias: Auto turn off pump hourly
trigger:
platform: time_pattern
minutes: 0
condition: []
action:
- entity_id: switch.water_pump
service: switch.turn_off
# 监听空气污染状态
# - id: auto_turn_on_purifier
# alias: Auto turn on purifier
# description: 根据空气状态自动开净化器
# trigger:
# platform: time_pattern
# minutes: '/10'
# condition:
# condition: and
# conditions:
# - condition: state
# entity_id: input_boolean.at_home
# state: 'on'
# - condition: numeric_state
# entity_id: sensor.waqi_pudong_monitoring_station_shanghai_shang_hai_pu_dong_jian_ce_zhan
# above: 75
# - condition: state
# entity_id: switch.purifier
# state: 'off'
# action:
# - entity_id: switch.purifier
# service: switch.turn_on
# - entity_id: switch.purifier
# service: switch.turn_on
# - entity_id: switch.purifier
# service: switch.turn_on
# - id: auto_turn_off_purifier
# alias: Auto turn off purifier
# description: 根据空气状态自动关净化器
# trigger:
# platform: time_pattern
# minutes: '/10'
# condition:
# condition: and
# conditions:
# - condition: state
# entity_id: input_boolean.at_home
# state: 'on'
# - condition: numeric_state
# entity_id: sensor.waqi_pudong_monitoring_station_shanghai_shang_hai_pu_dong_jian_ce_zhan
# below: 75
# - condition: state
# entity_id: switch.purifier
# state: 'on'
# action:
# - entity_id: switch.purifier
# service: switch.turn_off
# - entity_id: switch.purifier
# service: switch.turn_off
# - entity_id: switch.purifier
# service: switch.turn_off
# 每整点关一次水泵 避免漏关
- id: auto_turn_off_pump_hourly
alias: Auto turn off pump hourly
trigger:
platform: time_pattern
minutes: 0
condition: []
action:
- entity_id: switch.water_pump
service: switch.turn_off
# ===== test below
# 精确的到家时间 person.erimus 作为开关
- id: erimus_return
alias: Erimus Return # 这个名称会以下划线替换空格成为id
description: 回家时开启电器
trigger:
- entity_id: person.erimus
platform: state
from: 'not_home'
to: 'home'
condition:
- condition: state
entity_id: input_boolean.at_home
state: 'off'
# avoid tirggering by mistake while sleeping
- condition: time
after: '08:00:00'
before: '22:00:00'
action:
- service: script.home_return
# 离家时
- id: erimus_leave
alias: Erimus Leave
description: 离家时关闭电器
trigger:
- entity_id: person.erimus
platform: state
from: 'home'
to: 'not_home'
condition:
- condition: state
entity_id: input_boolean.at_home
state: 'on'
- condition: state
entity_id: input_boolean.playing_sound
state: 'off'
# avoid tirggering by mistake while sleeping
- condition: time
after: '08:00:00'
before: '22:00:00'
action:
- service: script.home_leave