rf射频接收部分,参考一下esphome的介绍,我esp8266刷了esphome后是这样设置的
1、首先是接收部分的代码:
remote_receiver: pin: D5 dump: - rc_switch tolerance: 50% filter: 200us idle:4ms buffer_size: 1kb
以上代码输入后先保存刷机,然后用按遥控器的按键,在esphome的log中会显示如下代码: [02:28:08][D][remote.rc_switch:243]: Received RCSwitch Raw: protocol=1 data='111111000000001000000001' [02:28:08][D][remote.rc_switch:243]: Received RCSwitch Raw: protocol=1 data='111111000000001000000001' [02:28:10][D][remote.rc_switch:243]: Received RCSwitch Raw: protocol=2 data='111111000000001000000001' [02:28:10][D][remote.rc_switch:243]: Received RCSwitch Raw: protocol=1 data='111111000000001000000001' [02:28:13][D][remote.rc_switch:243]: Received RCSwitch Raw: protocol=3 data='00000111111111111111111' [02:28:13][D][remote.rc_switch:243]: Received RCSwitch Raw: protocol=3 data='00000111111111'
找到显示最长的那个data数值,比如上面的111111000000001000000001 然后在esphome中再编辑,增加一个二进制传感器和一个开关(或者灯)。原理是esphome收到指定的射频date数据后,会虚拟一个二进制传感器,并短时将传感器进行on和off的切换,然后通过自动化,当二进制传感器on后,自动切换开关的状态。代码如下 binary_sensor: - platform: remote_receiver name: "woshideng1 rf xinhao" filters: - delayed_off: 10ms rc_switch_raw: code: '111111000000001000000001' protocol: 1 on_press: then: - switch.toggle: jidianqi1 switch: - platform: gpio pin: D6 name: "继电器1" id: jidianqi1 这里code就是你刚才找到的那个date数值,delayed_off参数10ms是指在10ms内连续收到指定的信号只触发一次二进制传感器,这个看你的需要。 以上代码没有好好编辑,缩进自行修改
|