lannister 发表于 2022-7-15 15:06:22

人体存在传感器1115H,可在线调参的配置文件[更新串口显示]

本帖最后由 lannister 于 2022-7-19 18:14 编辑

2022年7月19日 第二次更新:

应坛友的要求,更新了串口信息的相关的功能:
1、能够显示串口实时的雷达数据输出;
2、更改数据后显示串口的修改反馈以便确认;
3、获取当前雷达的全部配置参数;

下面2份文件,第一份为 esp8266 的 yaml,另一份为 c++ 文件。
接入方法:
1、将下列 c++ 文件命名为 UartReadLineSensor.h 放置到 esphome 的 config 文件夹中。
注:如果不知道文件夹位置,就直接编译这个 yaml, 会编译报错:Could not find file 'config/uart_read_line_sensor.h'. Please make sure it exists (full path: /Users/XXXXXXX/config/uart_read_line_sensor.h),把文件放到这个地址就可以。
2、使用新版 yaml 编译到设备就可以了。

二更注意事项:

1、1115H 的串口每秒发送大概26次数据,因此 C++ 文件中做了限制 update_frq = 26 即每秒显示一次,可根据需求进行修改,不建议更新频率太快


2、这里使用了 GPIO 2 作为 Tx,GPIO 0 作为 Rx,在 esp8265-01s 上是软件模拟的 Uart,建议 IO 多的其他板子换硬件 UART 会效率会好些,当然不换也没多少差


3、设置参数后 “串口输出” 先立即显示 XXX is XXX, 说明设置成功。亦可点击“查看配置” 显示所有参数(没有格式化输出,就凑合看看吧,反正不常用)


4、建议参数调好后就可以禁用 Rx 了,毕竟 hass 中会日志会不断记录数值










其他感悟:


基本上 1115h 相关的功能玩到头了,后面大概率不会再更新本帖相关的内容了,有疑问回帖会解答


同时个人感觉 2410 可玩性会比 1115 高,可以设置不同距离的不同的灵敏度,以达到屏蔽扰动的功能,并且能够获得物体的距离


但 up 主本人只会将雷达扔在洗手间的角落里,只需要判断有没有人,不需要那么复杂的功能 ~

ps: 坛友 moe1983 写了个 2410 配置文件,传送门:https://bbs.hassbian.com/thread-17143-1-1.html,进阶玩家可以去试试,调参会比 1115 复杂



**** Hidden Message *****



==================== 以下为首发内容 ==================

最近在折腾人体存在传感器,写了个 esp8266-01s 可调参的配置文件,这样就可以直接把原件放置在指定位置后进行调参,不用反复连接电脑折腾了。

效果如下:



其他事项:
1、连接前最好先记住旧参数,连接后需要将每个参数点击一次以同步 1115h 与 esp8266 的参数,否则可能实际值与显示值不同
2、在 hass 上调节参数后会立即设置并自动保存,即1115h、8266 均会写入flash,掉电后数值依然记录
3、默认只开放了 th1、th2 两个参数,要调节其他参数可以在实体设置中启用即可
4、上述数值显示可以使用 滑块 来显示,但由于滑块需要点击才显示数值不够直观,所以本人没使用。喜欢滑块的可以把配置中的 mode: box 改为 mode: slide
5、配置中的 binary_sensor 设置了 delayed_off: 15,即雷达Vout为低(无人)15秒后,hass才变为无人状态,可避免hass中有人\无人反复的情况,可视个人需要调节
6、配置中使用 Tx_pin: 2 接入到 1115h 的 Rx , 未设置 Rx_pin(本人不需要读取雷达数据),1115h 的 Vout 接入 GPIO3,可视个人需要调节。

雷达参数释义: (详见 1115h 手册 )

th1移动灵敏度:默认值:120。值越大,模块越不灵敏。感应距离及范 围就越小
th2存在灵敏度:默认值:250。值越大,模块对存在检测越不灵敏。感应距离及范围就越小。(一般该灵敏度可不调整)
GPIO检测延时:默认值: 5 秒。
mov触发条件:检测到多少次大幅度数据时,拉高 Vout。默认值:3 ,设置越大越不灵敏,当有大幅度误报时可以调高。
occ维持条件:GPIO拉高后,检测到多少次小幅度数据来維持GPIO高电平。默认值: 5,设置越大越不灵敏,不建议调高。





esp8266-01的 yaml 文件
esphome:
name: "main-toilet-motion"


esp8266:
board: esp01_1m
restore_from_flash: true

# Enable logging
logger:

# Enable Home Assistant API
api:
encryption:
    key: "kPzhXXTr2OwAm2GPFfZlDTMvFsYCo5cMNAwj1Otm2f8="

ota:
password: "7e93cc276712a312371a64d2f5d4b237"

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password

# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
    ssid: "main-toilet-motion Hotspot"
    password: "iYYGq0Tr27Y9"

captive_portal:


binary_sensor:
- platform: gpio
    id: motion
    pin: 3
    name: "main-toilet-motion"
    device_class: motion
    filters:
      delayed_off: 15s

uart:
id: uart_bus
#rx_pin: 1
tx_pin: 2
baud_rate: 115200
      
number:
- platform: template
    id: motion_th1
    name: "th1 移动灵敏度"
    mode: box
    optimistic: true
    min_value: 0
    max_value: 500
    step: 1
    restore_value: true
    initial_value: 120
    on_value:
      then:
      - uart.write: !lambda
          int v = (int)x;
          std::string cmd = "th1=" + to_string(v);
          return std::vector<unsigned char>(cmd.begin(), cmd.end());
      - delay: 100ms
      - uart.write: "save"
      - delay: 100ms
      - uart.write: "get_all"
      - logger.log:
          format: "th1 is %.1f"
          args: [ 'id(motion_th1).state' ]
      
- platform: template
    id: motion_th2
    name: "th2 存在灵敏度"
    mode: box
    optimistic: true
    min_value: 0
    max_value: 500
    step: 1
    restore_value: true
    initial_value: 250
    on_value:
      then:
      - uart.write: !lambda
          int v = (int)x;
          std::string cmd = "th2=" + to_string(v);
          return std::vector<unsigned char>(cmd.begin(), cmd.end());
      - delay: 100ms
      - uart.write: "save"
      - delay: 100ms
      - uart.write: "get_all"
      - logger.log:
          format: "th2 is %.1f"
          args: [ 'id(motion_th2).state' ]
         
- platform: template
    id: occ_sn
    name: "occ 维持条件"
    disabled_by_default: true
    optimistic: true
    mode: box
    min_value: 1
    max_value: 100
    step: 1
    restore_value: true
    initial_value: 3
    on_value:
      then:
      - uart.write: !lambda
          int v = (int)x;
          std::string cmd = "occ_sn=" + to_string(v);
          return std::vector<unsigned char>(cmd.begin(), cmd.end());
      - delay: 100ms
      - uart.write: "save"
      - delay: 100ms
      - uart.write: "get_all"
      - logger.log:
          format: "occ_sn set %.1f"
          args: [ 'id(occ_sn).state' ]
            
- platform: template
    id: motion_dtime
    name: "gpio 检测延迟"
    icon: "mdi:clock-time-four"
    mode: box
    disabled_by_default: true
    optimistic: true
    min_value: 1
    max_value: 300
    step: 1
    restore_value: true
    initial_value: 5
    on_value:
      then:
      - uart.write: !lambda
          int v = (int)x;
          std::string cmd = "dtime=" + to_string(v);
          return std::vector<unsigned char>(cmd.begin(), cmd.end());
      - delay: 100ms
      - uart.write: "save"
      - delay: 100ms
      - uart.write: "get_all"
      - logger.log:
          format: "dtime set %.1f"
          args: [ 'id(motion_dtime).state' ]

- platform: template
    id: mov_sn
    name: "mov 触发条件"
    optimistic: true
    disabled_by_default: true
    min_value: 1
    max_value: 100
    step: 1
    restore_value: true
    mode: box
    initial_value: 5
    on_value:
      then:
      - uart.write: !lambda
          int v = (int)x;
          std::string cmd = "mov_sn=" + to_string(v);
          return std::vector<unsigned char>(cmd.begin(), cmd.end());
      - delay: 100ms
      - uart.write: "save"
      - delay: 100ms
      - uart.write: "get_all"
      - logger.log:
          format: "mov_sn set %.1f"
          args: [ 'id(mov_sn).state' ]




本来想设置回复可见的...才发现没有权限 - - ,各位看官回帖子支持一下呗~






嘻嘻 发表于 2022-7-15 15:19:10

赶紧占个位置

三尺寒 发表于 2022-7-15 15:48:43

支持一下

showphi 发表于 2022-7-15 15:50:53

大佬威武

520key 发表于 2022-7-15 15:57:36


支持一下

yinghu183 发表于 2022-7-15 16:47:43

本帖最后由 yinghu183 于 2022-7-15 16:49 编辑

感谢分享,正好有闲置01s

book123 发表于 2022-7-15 17:03:28

太棒了,感谢分享!

sxrcm 发表于 2022-7-15 17:22:24

感谢分享!!!

sasukebinbin 发表于 2022-7-15 17:54:05

支持一下

jjcs 发表于 2022-7-15 21:09:26

这才是esphome的高阶用法
页: [1] 2 3 4 5 6 7 8 9 10
查看完整版本: 人体存在传感器1115H,可在线调参的配置文件[更新串口显示]