本帖最后由 落叶无声 于 2020-10-23 09:52 编辑
起因 :大概一年前就买了srx882,还买了一个433按键,但是一直没有找到既便宜,又好看,至少有开关两种码的门磁所以一直没做。最近刚好买到了想要的门磁就做了。结果用了srx882接收只有四五米遂又搁置几天买了新的模块才做完。
材料 :D1 mini 、 H5V4D(433模块,接收很好四堵墙几十米没问题)、双向门磁(自认为是比较好看和米家相似,实际有三个码后面有个防拆的但是安拆都会触发 )、433按键(只有一个码)。 价格:
功能: 对于两个码的门磁识别开关状态,对于一个码的设备可以实现按下切换状态。另外可以一键恢复单码设备状态(对于防拆开关用,实际没做)。
效果图:
问题: 只有一个传感器命名为中文没有问题,如果之后再命名为中文,在hass里面就会不显示。但是esphome的log可以正常显示。不知道什么原因。
代码: 部分代码抄自官方论坛
pin: D2
dump: rc_switch
# Settings to optimize recognition of RF devices
tolerance: 50%
filter: 250us
idle: 4ms
buffer_size: 2kb
#433接收器设置
binary_sensor:
#第一个门磁--------------------------------------------------
# 1 入户门门磁开启码
- platform: remote_receiver
id: one_door_open
internal: true
rc_switch_raw:
code: '100100010000001100000011'
protocol: 1
filters:
delayed_off: 100ms
# 1 入户门门磁关闭码
- platform: remote_receiver
id: one_door_closed
internal: true
rc_switch_raw:
code: '100100010000001100001010'
protocol: 1
filters:
delayed_off: 100ms
# 1 入户门门磁自动化
- platform: template
name: "入户门"
device_class: door
id: a111
lambda: |-
if (id(one_door_open).state) {
// front dooris open
return true;
} else if (id(one_door_closed).state) {
// front door closed
return false;
} else {
return {};
}
# 1 入户门门磁防拆码
- platform: template
name: "one_door"
id: one_door_connectivity
device_class: connectivity
- platform: remote_receiver
name: "one_door_connectivity"
internal: true
rc_switch_raw:
code: "100100010000001100000111"
protocol: 1
filters:
delayed_off: 100ms
on_press:
if:
condition:
binary_sensor.is_on: one_door_connectivity
then:
- logger.log: "开关为打开状态将改变为关闭"
- binary_sensor.template.publish:
id: one_door_connectivity
state: OFF
else:
- logger.log: "开关为关闭状态将改变为打开"
- binary_sensor.template.publish:
id: one_door_connectivity
state: ON
# 1 入户门门磁结束
#第二个门磁--------------------------------------------------
# 2 阳台窗户门磁开启码
- platform: remote_receiver
id: one_windows_open
internal: true
rc_switch_raw:
code: '010110110000001000000011'
protocol: 1
filters:
delayed_off: 100ms
on_press:
then:
- logger.log: "阳台窗户打开"
- binary_sensor.template.publish:
id: balcony_windows
state: ON
# 2 阳台窗户门磁关闭码
- platform: remote_receiver
id: one_windows_closed
internal: true
rc_switch_raw:
code: '010110110000001000001010'
protocol: 1
filters:
delayed_off: 100ms
on_press:
then:
- logger.log: "阳台窗户关闭"
- binary_sensor.template.publish:
id: balcony_windows
state: OFF
# 2 阳台窗户门磁自动化
- platform: template
name: "balcony_windows"
device_class: window
id: balcony_windows
# 2 阳台窗户门磁防拆码
- platform: template
name: "balcony_windows_connectivity"
id: balcony_windows_connectivity
device_class: connectivity
- platform: remote_receiver
name: "balcony_windows_connectivity"
internal: true
rc_switch_raw:
code: "010110110000001000000111"
protocol: 1
filters:
delayed_off: 100ms
on_press:
if:
condition:
binary_sensor.is_on: balcony_windows_connectivity
then:
- logger.log: "开关为打开状态将改变为关闭"
- binary_sensor.template.publish:
id: balcony_windows_connectivity
state: OFF
else:
- logger.log: "开关为关闭状态将改变为打开"
- binary_sensor.template.publish:
id: balcony_windows_connectivity
state: ON
# 2 阳台窗户门磁结束
#第三个门磁--------------------------------------------------
# 3 433按键
- platform: template
name: "433button"
id: a433button
- platform: remote_receiver
name: "433button"
internal: true
rc_switch_raw:
code: "000010000101100010111000"
protocol: 1
filters:
delayed_off: 100ms
on_press:
if:
condition:
binary_sensor.is_on: a433button
then:
- binary_sensor.template.publish:
id: a433button
state: OFF
else:
- binary_sensor.template.publish:
id: a433button
state: ON
复制代码