『瀚思彼岸』» 智能家居技术论坛
标题: 开关灯自动化分享 [打印本页]
作者: thang009 时间: 2020-9-20 11:04
标题: 开关灯自动化分享
本帖最后由 thang009 于 2020-9-20 11:12 编辑
参考了论坛各种大神的自动化开关灯方案之后,发现只有计数器这个方法比较适合做自动化,尤其是【DIY】廉价人体存在解决方案,区域人数统计大神提出的方案实在是目前比较完美的方法.但是他提到的两个方案红外对射需要装修加持.激光需要自己编译.这个对于我这种什么都不会的人来说简直是灾难.不过自动化还是要做的,那就自己想办法呗.所以用了三个传感器实现了类似的功能,目前使用下来还是比较满意.也不需要自己写代码.
那么下面需要三种传感器分别是:
- 关照感应器gy30/bh1750 用来检测环境光.当光照充足的时候不会触发开灯动作.
- rcwl-0516 前置感应器
- sr501 后置感应器
- 一个esp8266
esp8266刷的是espeasy的固件,毕竟大神写好的东西,咱们没能力就伸手拿来用了..接线方式就不叙述了.论坛上面一搜就有.下面直接放出代码参考
- counter:
- # 测试人体计数器
- ce_suo_count:
- name: 厕所人数
- initial: 0
- step: 1
- minimum: 0
- restore: false
- ce_suo_front:
- name: 前感应器
- initial: 0
- step: 1
- minimum: 0
- maximum: 1
- ce_suo_back:
- name: 后感应器
- initial: 0
- step: 1
- minimum: 0
- maximum: 1
复制代码- binary_sensor:
- # 前置感应器
- - platform: mqtt
- name: motion_sensor.ce_suo_front
- device_class: motion
- state_topic: ESP_ce_suo/motion_sensor.front/state
- qos: 0
- payload_on: "1"
- payload_off: "0"
- unique_id: motion_sensor.ce_suo_front
- # 后置感应器
- - platform: mqtt
- name: motion_sensor.ce_suo_back
- device_class: motion
- state_topic: ESP_ce_suo/motion_sensor.back/state
- qos: 0
- payload_on: "1"
- payload_off: "0"
- unique_id: motion_sensor.ce_suo_back
复制代码- sensor:
- # 光照传感器
- - platform: mqtt
- name: ce_suo_bh1750
- state_topic: ESP_ce_suo/sensor.bh1750/lux
- unit_of_measurement: lx
- unique_id: ce_suo_bh1750
复制代码- # 增加人数
- - alias: 增加人数
- initial_state: true
- trigger:
- - platform: state
- entity_id: binary_sensor.motion_sensor_ce_suo_front
- to: 'on'
- condition:
- condition: and
- conditions:
- - condition: numeric_state
- entity_id: counter.ce_suo_back
- below: 1
- action:
- - service: counter.increment
- entity_id: counter.ce_suo_front
- - service: script.toggle
- entity_id: script.add_ce_suo
- - delay: 00:00:05
- - service: script.turn_off
- entity_id: script.add_ce_suo
- - service: counter.decrement
- entity_id: counter.ce_suo_front
复制代码- # 减少人数
- - alias: 减少人数
- initial_state: true
- trigger:
- - platform: state
- entity_id: binary_sensor.motion_sensor_ce_suo_back
- to: 'on'
- condition:
- condition: and
- conditions:
- - condition: numeric_state
- entity_id: counter.ce_suo_front
- below: 1
- action:
- - service: counter.increment
- entity_id: counter.ce_suo_back
- - service: script.toggle
- entity_id: script.del_ce_suo
- - delay: 00:00:05
- - service: script.turn_off
- entity_id: script.del_ce_suo
- - service: counter.decrement
- entity_id: counter.ce_suo_back
复制代码- # 自动开厕所灯
- - alias: 自动开厕所灯
- initial_state: true
- trigger:
- - platform: state
- entity_id: counter.ce_suo_count
- from: '0'
- to: '1'
- condition:
- condition: and
- conditions:
- - condition: numeric_state
- entity_id: sensor.ce_suo_bh1750
- below: 10
- - condition: state
- entity_id: light.ce_suo_deng
- state: 'off'
- action:
- - service: light.turn_on
- entity_id: light.ce_suo_deng
复制代码- # 自动关厕所灯
- - alias: 自动关厕所灯
- initial_state: true
- trigger:
- - platform: state
- entity_id: counter.ce_suo_count
- to: '0'
- condition:
- condition: and
- conditions:
- - condition: state
- entity_id: light.ce_suo_deng
- state: 'on'
- - condition: state
- entity_id: binary_sensor.door_window_sensor_158d000522504e
- state: 'on'
- action:
- - service: light.turn_off
- entity_id: light.ce_suo_deng
-
复制代码- # 增加人数
- add_ce_suo:
- alias: 增加人数
- sequence:
- - wait_template: >-
- {% if(states.binary_sensor.motion_sensor_ce_suo_back.state == 'on') %}
- true
- {% endif %}
- - data:
- entity_id: counter.ce_suo_count
- service_template: >-
- {% if( as_timestamp(states.counter.ce_suo_front.last_changed) - as_timestamp(states.binary_sensor.motion_sensor_ce_suo_back.last_changed) | float < 0 ) %}
- counter.increment
- {% endif %}
- - data:
- entity_id: counter.ce_suo_front
- service: counter.decrement
复制代码- # 减少人数
- del_ce_suo:
- alias: 减少人数
- sequence:
- - wait_template: >-
- {% if(states.binary_sensor.motion_sensor_ce_suo_front.state == 'on') %}
- true
- {% endif %}
- - data:
- entity_id: counter.ce_suo_count
- service_template: >-
- {% if( as_timestamp(states.counter.ce_suo_back.last_changed) - as_timestamp(states.binary_sensor.motion_sensor_ce_suo_front.last_changed) | float < 0 ) %}
- counter.decrement
- {% endif %}
- - data:
- entity_id: counter.ce_suo_back
- service: counter.decrement
复制代码逻辑思路是:
- 前置感应器触发之后改变前置统计人数保存触发时间.并且等待后置感应器触发,5秒内后置感应器触发的话通过计算前置触发器和后置触发器时间差判断人是否进入卫生间.人数统计+1,并且光照低的时候开灯
- 前置感应器触发之后如果5秒内不进入卫生间,则关闭检测脚本.等待下一次触发,减少误触发情况
- 后置感应器触发和前置触发器逻辑一样.
这里还有一种情况,当卫生间门关闭的时候为了防止在里面的传感器乱触发,加了一个小米的门窗感应器.当关闭的时候不触发关灯指令.但是目前我使用的情况下来,这种情况基本上没出现过.统计人数还是比较准确.不过这种方案有4秒的锁止时间,所以如果两个人前后脚进入的话很可能会失败,因此这个方案可能只适合单身狗
希望有大神可以告知还有什么传感器可以实现只在卫生间门口才会触发的.比如上面提到的大神用激光模块,但是又不需要自己撸代码的方案.最后祝各位都能实现自己的家庭自动化方案
作者: jyz_0501 时间: 2020-9-20 20:49
额,一前一后进入卫生间是要做什么???。。。画面自行脑补。。。
如果是干湿分离的卫生间,我觉得你这个已经不用改了,重点是装在湿区,干区这个一般一个小米人体就搞定了,毕竟洗脸化妆吹头发什么的都会一直运动的。主要还是蹲坑的时候。
作者: thang009 时间: 2020-9-20 21:26
前后感应不是为了探测人体存在.是为了统计触发时间差,因为ha的last_changed会一直变化.所以用两个计数器保存触发时间而已.就是这种方案的核心
作者: zsqduke 时间: 2021-4-14 05:40
统计人数。可能只适合单身狗。。
欢迎光临 『瀚思彼岸』» 智能家居技术论坛 (https://bbs.hassbian.com/) |
Powered by Discuz! X3.5 |