本来是想写一个自动化,如果检测到人体(state: from "off" to "on"),就打开Aqara网关的灯,如果没有检测到(state: from "on" to "off"),就关闭Aqara的灯,结果测试的时候发现只能打开,不能关闭,在网上查是说off状态不上报,参考这个帖子改了也没有用《踩个使用Aqara人体传感器的小坑》,下面是我自动化的代码,有大佬知道怎么解决嘛?
- id: test
alias: turn light
trigger:
- entity_id: binary_sensor.motion_sensor_7ad9
platform: state
to: 'on'
- entity_id: binary_sensor.motion_sensor_7ad9
platform: state
to: 'off'
condition:
condition: or
conditions:
- condition: template
value_template: '{{ now().hour < 6 }}'
- condition: template
value_template: '{{ now().hour > 18 }}'
action:
- service_template: "light.turn_{% if trigger.to_state.state == 'on' %}on{% else %}off{% endif %}"
data_template:
color_name: red
entity_id: light.aqara_hub_7e29
- service: persistent_notification.create
data_template:
message: >
Light state is already changed to {% if trigger.to_state.state == 'on' %}on!{% else %}off!{% endif %}
mode: single