本帖最后由 hyifan 于 2023-2-7 14:37 编辑
我用device_tracker来监控手机是否连接wifi和门磁辅助判断来避免误判,一直用了好久了没啥问题,供你参考.
楼上说的PING就不要了.很多手机熄屏后wifi会休眠导致PING不通的.
我是华硕的路由器,用这个集成:https://github.com/Vaskivskyi/ha-asusrouter
alias: 外出电源自动关闭
trigger:
- platform: template
value_template: >-
{{ is_state('device_tracker.iphone_13', 'not_home') and
is_state('device_tracker.iphone_6s', 'not_home') and
is_state('device_tracker.iphone_12', 'not_home') and
is_state('device_tracker.iqoo_neo5', 'not_home')}}
condition:
- condition: and
conditions:
- condition: time
after: "06:00"
before: "23:59"
- condition: state
entity_id: binary_sensor.door_state
state: "off"
- condition: template
value_template: >-
{{ as_timestamp(now()) -
as_timestamp(states.binary_sensor.door_state.last_changed) < 240 }}
action:
- service: input_boolean.turn_off
entity_id: input_boolean.home_state
- service: notify.mobile_app_iphone
data:
title: Home Assistant
message: 切换到外出模式
- service: fan.turn_off
target:
entity_id: fan.zhimi_airpurifier_ma2
data: {}
- service: media_player.turn_off
target:
entity_id: media_player.sony_bravia_tv
data: {}
- service: switch.turn_off
target:
entity_id:
- switch.broadlink_mp1_s1
- switch.broadlink_mp1_s2
- switch.broadlink_mp1_s3
- switch.broadlink_mp1_s4
- switch.livingroom_dc1_3
- switch.livingroom_dc1_4
data: {}
- service: light.turn_off
target:
entity_id:
- light.lemesh_wy_4bb4_light
- light.lemesh_wy_f6f9_light
- light.hue_color_light_1
- light.hue_color_light_2
- light.hue_color_light_3
- light.hue_color_light_4
- light.hue_color_light_5
- light.dining_room_light
data: {}
- if:
- condition: numeric_state
entity_id: sensor.livingroom_dc1_power
above: "200"
then:
- service: script.dc1_01_slot3_delay_off
data: {}
else:
- service: switch.turn_off
data: {}
target:
entity_id: switch.livingroom_dc1_2
initial_state: true
|