ESPhome做了一个包含人体传感器和距离传感器的开关。正在试验。成后后打样。。
大概流程:
进入卫生间触发人体感应(触发高电平延迟3分钟,并可以反复触发)--开灯 也可以手动开灯,全屋总控等(射频遥控和HASS)
马桶正上方用倒车雷达那种距离感应。每一分钟检测一次距离(人坐在马桶上必定减少了距离)有人就设置一个InWC传感器为true
当距离检测没有人蹲坑后设置InWC为false。并且同时检测人体传感器状态。低电平就关灯。
当人体传感器低电平后在检测 InWC如果为false 则关灯。
本也现过在马桶盖上贴个门窗传感器(智能马桶会自动关盖)。但是怕水。偶尔会冲刷马桶外围必定会让小米门窗传感器进水。
也现过改装马桶。如果上面这个方法还是不完美在折腾了。
人体距离传感器一定要用超声波的。不能用红外漫反射什么的。则东西以前用过。反光表面材质,颜色不一样检测就失灵了。
ESPHome的代码如下:
#卫生间
substitutions:
device_name: 1ch_rf_relay_1 #设备名称(多个改成不一样的)
wifi_ssid: '1111111111' #WiFi_SSID名称
wifi_password: '111111111' #WiFi密码
wifi_ssid_AP: '1ch_rf_relay'
wifi_password_AP: '111111111' #ap_WiFi密码
wifi_static_ip: 192.168.3.35
wifi_gateway: 192.168.3.1
wifi_subnet: 255.255.255.0
wifi_dns1: 192.168.3.1
wifi_dns2: 192.168.3.1
wifi_fast_connect: 'false' #如果SSID是隐藏的,设置为true
wifi_reboot_timeout: 0s #WiFi离线多久后重启设备,秒s/分钟min/小时h,不需要此功能设置为0s
ota_password: '1111111111' #OTA密码
api_password: '1111111111' #API密码
api_reboot_timeout: 0s #与客户端(如Home Assistant)失去连接多久后重启设备,秒s/分钟min/小时h,不需要此功能设置为0s
esphome:
name: $device_name
platform: ESP8266
board: esp12e
wifi:
ssid: $wifi_ssid
password: $wifi_password
#可选,手工指定IP地址
manual_ip:
static_ip: $wifi_static_ip
gateway: $wifi_gateway
subnet: $wifi_subnet
dns1: $wifi_dns1 #(可选)
dns2: $wifi_dns2 #(可选)
use_address: $wifi_static_ip #(可选,字符串)手动覆盖用于连接ESP的地址。默认为自动生成的值。例如,如果您更改了静态IP并想将OTA刷新为先前配置的IP地址。
domain: .local #(可选,字符串):设置用于上传的节点主机名的域。例如,如果将其设置为.local,则所有上传将发送到<HOSTNAME>.local。默认为.local。
reboot_timeout: $wifi_reboot_timeout #(可选)wifi连接失败后重启时间,0s禁用。默认为15min。
power_save_mode: "NONE" #(可选,字符串) WiFi省电模式。NONE(省电最少,ESP8266默认) LIGHT(ESP32默认) HIGH(最省电)
fast_connect: $wifi_fast_connect #(可选,on,off)直连WIFI,而不进行信号强弱扫描
id: #(可选)手动指定用于代码生成的ID。
#无线没有连接的时候用以下信息转为AP模式
ap:
ssid: $wifi_ssid_AP
password: $wifi_password_AP
channel: 1 #(可选)AP应该在1到14上运行的信道。默认为1。
manual_ip: #(可选)手动设置AP的IP选项。与工作站模式的manual_ip相同
static_ip: 192.168.4.1
gateway: 192.168.4.1
subnet: 255.255.255.0
ap_timeout: 1min #(可选)启用配置的后备热点的时间。默认为1min。
captive_portal:
# Enable logging
logger:
#web_server:
# Enable Home Assistant API
api:
password: $api_password
reboot_timeout: $api_reboot_timeout
ota:
password: $ota_password
sensor: #传感器
- platform: wifi_signal
name: "WiFi Signal_${device_name}"
update_interval: 60s
- platform: ultrasonic
trigger_pin: 14
echo_pin: 4
name: "Ultrasonic Sensor"
update_interval: 60s #更新周期 60秒
timeout: 4.5m #20厘米-4.5米
pulse_time: 10us # trig时间 10us
on_value:
then:
- binary_sensor.template.publish:
id: InWC
state: !lambda 'return !(x > 1);'
- if:
condition:
lambda: 'return (x > 1) and !id(PIR).state;'
then:
- switch.turn_off: CH_1
text_sensor:
- platform: wifi_info
ip_address:
name: ESP IP_${device_name}
# ssid:
# name: ESP Connected SSID
# bssid:
# name: ESP Connected BSSID
switch:
- platform: gpio
name: "通道_1_卫生间灯"
pin: 13
restore_mode: ALWAYS_OFF #RESTORE_DEFAULT_OFF
id: CH_1
binary_sensor:
- platform: template
name: "蹲坑中"
id: InWC
- platform: gpio
pin: 12
name: "PIR Sensor"
device_class: motion
id: PIR
on_press:
then:
- switch.turn_on: CH_1
on_release:
then:
- if:
condition: #距离传感器判断无人的时候才关闭
lambda: 'return !id(InWC).state;'
then:
- switch.turn_off: CH_1
#全开
- platform: remote_receiver
name: "大门_全开"
internal: true
filters:
- delayed_off: 100ms
rc_switch_raw:
code: '010111000100100000000100'
protocol: 1
on_press:
then:
- switch.turn_on: CH_1
#全关
- platform: remote_receiver
name: "大门_全关"
internal: true
filters:
- delayed_off: 100ms
rc_switch_raw:
code: '010111000100100000000010'
protocol: 1
on_press:
then:
- switch.turn_off: CH_1
#局部全关
- platform: remote_receiver
name: "过道边_外总关"
internal: true
filters:
- delayed_off: 100ms
rc_switch_raw:
code: '010110010100100000001000'
protocol: 1
on_press:
then:
- switch.turn_off: CH_1
- platform: remote_receiver
name: "大门_外总关"
internal: true
filters:
- delayed_off: 100ms
rc_switch_raw:
code: '010111000100100000001000'
protocol: 1
on_press:
then:
- switch.turn_off: CH_1
#除书房全屋总关
- platform: remote_receiver
name: "书房墙壁_除书房全屋总关"
internal: true
filters:
- delayed_off: 100ms
rc_switch_raw:
code: '100001000100011100000010'
protocol: 1
on_press:
then:
- switch.turn_off: CH_1
- platform: remote_receiver
name: "空闲_除书房全屋总关"
internal: true
filters:
- delayed_off: 100ms
rc_switch_raw:
code: '100001100100011100000010'
protocol: 1
on_press:
then:
- switch.turn_off: CH_1
# 除卧室全屋总关
- platform: remote_receiver
name: "床边靠门_除卧室全屋总关"
internal: true
filters:
- delayed_off: 100ms
rc_switch_raw:
code: '001110000100011000000010'
protocol: 1
on_press:
then:
- switch.turn_off: CH_1
- platform: remote_receiver
name: "床边靠窗_除卧室全屋总关"
internal: true
filters:
- delayed_off: 100ms
rc_switch_raw:
code: '100010110100011100001000'
protocol: 1
on_press:
then:
- switch.turn_off: CH_1
# 1通道 卫生间
- platform: remote_receiver
name: "卫生间_开"
internal: true
filters:
- delayed_off: 100ms
rc_switch_raw:
code: '110101001111001100001100'
protocol: 1
on_press:
then:
- switch.turn_on: CH_1
- platform: remote_receiver
name: "卫生间_关"
internal: true
filters:
- delayed_off: 100ms
rc_switch_raw:
code: '110101001111001111000000'
protocol: 1
on_press:
then:
- switch.turn_off: CH_1
- platform: remote_receiver
name: "书房门口_书房"
internal: true
filters:
- delayed_off: 100ms
rc_switch_raw:
code: '100001110100011100000100'
protocol: 1
on_press:
then:
- switch.toggle: CH_1
remote_receiver: #rf射频的接收,详见https://esphome.io/components/remote_receiver.html
pin: 5
dump:
- rc_switch
tolerance: 50%
filter: 200us
idle: 4ms
buffer_size: 1kb
|