『瀚思彼岸』» 智能家居技术论坛

标题: ESPHome驱动UART型雨量传感器 [打印本页]

作者: nbxzl    时间: 2023-10-1 23:11
标题: ESPHome驱动UART型雨量传感器
本帖最后由 nbxzl 于 2023-10-1 23:18 编辑

[attach]51902[/attach]


下雨检测坛友常用的其中一类传感器,如下图:

[attach]51903[/attach]

这种传感器也为孩子科技课做过,报警时播放语音模块,完成上交学校了。当然,如坛友所遇到的问题一样,就是不能长时间在潮湿环境中使用,线路板表面容易腐蚀损坏。

最后找到一款型号为RS200的传感器,其常应用于安防系统中的室外高档摄像机上,用以检测镜头前面的玻璃表面是否有雨水,为驱动雨刮器提供依据等

[attach]51904[/attach]
[attach]51917[/attach]
[attach]51916[/attach]
[attach]51905[/attach]
    需要注意的是,采购厂家淘宝卖的模块不配数据线,需要自己另配4P 0.8间距的插头线
[attach]51906[/attach]
[attach]51907[/attach]
传感器表面距离与玻璃最外侧4mm,不与雨水直接接触,实际制作中我把整个模块用有机硅1029绝缘电路板灌封胶密封在玻璃上,胶透明度极高,胶体固化后透明软性,不损坏线路板,也容易清除。
[attach]51908[/attach]
    找出一块黑色玻璃触摸86空白面板,在上面留出需要的位置,用热熔胶依次固定小杯和传感器模块(提示:1029透明胶的渗透力极强,正式用之前在别的地方先做下测试),位置要求:RS200 模块正面“PCB 表面”到“玻璃外表面”的典型距离为 4.0mm(可调),玻璃与柔性透明光学材料的厚度可适当调节,例如:若玻璃厚度为 1.5mm,则填充的柔性透明光学材料厚度为2.5mm;若玻璃厚度为2.0mm,则填充的柔性透明光学材料厚度为2.0mm。
    按说明书1:1调好透明1029胶,等5分钟气泡没有后缓缓倒入,静置4小时等待固化即可。
    按下图将线接好在串口下载器进行调试:
[attach]51914[/attach]
[attach]51910[/attach]
    配套调试软件做得一般,只能使用1~4端口,需要把下载器端口控制在这个范围。
[attach]51911[/attach]
    确认后打开串口,在玻璃表面用湿润纸巾滑动,软件就会输出雨量数据了。
    接下来将传感器固定到ESP8266上,利用以前为HX711做的多余PCB板,板刷上三防漆,把外壳也用密封胶处理好,硬件就完成了。
[attach]51912[/attach]
[attach]51913[/attach]

UART驱动借用了坛友zro22  通过ESPhome集成射频收发功能,可以让射频遥控器作为输入修改而来。



  1. substitutions:
  2.   devicename: yuliang

  3. esphome:
  4.   name: $devicename
  5.   friendly_name: $devicename
  6.   includes:
  7.     - uartRS200_sensor.h

  8. ## 模块类型
  9. esp8266:
  10.   board: nodemcuv2                             

  11. # 启用日志
  12. logger:
  13.   baud_rate: 0

  14. # 启用HomeAssistant API
  15. api:
  16.   encryption:
  17.     key: "/i/sYVZtlW6NAbsY17CAoSR1+cWkfrQ/dexoW1uXjB2=" ## 密码
  18. #  reboot_timeout: 30min                       ## 断网重启时间

  19. ota:
  20.   password: "admin"                            ## 密码
  21.   port: 8266                                   ## 端口

  22. ## 启用网页调试模式
  23. web_server:                                    
  24.   port: 80                                     ## 端口
  25.   
  26. wifi:
  27.   ssid: "xxxxxxx"                              ## WiFi SSID
  28.   password: "xxxxxxxxxxxx"                     ## WiFi 密码
  29.   use_address: 192.168.x.xxx                   ## 指定烧录固件时候目标设备IP,优先级高于静态IP(例如,如果您更改了静态IP并想将OTA刷新为先前配置的IP地址)
  30.   manual_ip:                                   ## 手动配置节点静态IP
  31.     static_ip: 192.168.x.xxx                   ## 固定IP
  32.     gateway: 192.168.x.x                       ## 网关
  33.     subnet: 255.255.255.0                      ## 子网掩码
  34.     dns1: 223.5.5.5                            ## DNS1
  35.     dns2: 223.6.6.6                            ## DNS2
  36.   ap:                                          ## wifi连接失败时启用备用热点
  37.     ssid: "yuliang Hotspot"                    ## WiFi SSID
  38.     password: "admin"                          ## WiFi 密码
  39.    
  40.   fast_connect: off                            ##如果启用,则直接连接到WiFi网络,而无需先进行全面扫描。这对于隐藏网络是必需的,并且可以大大缩短连接时间。默认为off。

  41. ## 强制门户认证
  42. captive_portal:
  43.    
  44. # Example configuration entry
  45. uart:
  46.   id: uart_bus
  47.   rx_pin: GPIO3
  48.   tx_pin: GPIO1
  49.   baud_rate: 115200

  50. text_sensor:
  51.   - platform: custom
  52.     lambda: |-
  53.       auto uart_custext_sensor = new CustomP1UartComponent(id(uart_bus));
  54.       App.register_component(uart_custext_sensor);
  55.       return {uart_custext_sensor->uart_text_sensors};   
  56.     text_sensors:
  57.       id: "uart_readline"
  58.       name: $devicename"_UART"

  59. button:
  60.   - platform: template
  61.     name: "Rainfall status"                             #读取雨量状态
  62.     on_press:
  63.       - uart.write: [0x3A, 0x01, 0x00, 0x00, 0x0D]
  64.   - platform: template
  65.     name: "On sleep"                                    #进入睡眠状态
  66.     on_press:
  67.       - uart.write: [0x3A, 0x91, 0x01, 0x00, 0x88]
  68.   - platform: template
  69.     name: "Off sleep"                                   #退出睡眠状态
  70.     on_press:
  71.       - uart.write: [0x3A ,0x91 ,0x00 ,0x00 ,0x7C]
  72.   - platform: template
  73.     name: "On Real time rainfall"                       #进入实时雨量状态
  74.     on_press:
  75.       - uart.write: [0x3A ,0x84 ,0x01 ,0x00 ,0x43]
  76.   - platform: template
  77.     name: "Off Real time rainfall"                      #退出实时雨量状态
  78.     on_press:
  79.       - uart.write: [0x3A ,0x84 ,0x00 ,0x00 ,0xB7]
  80.   - platform: template
  81.     name: "CHIP Temperature"                            #发送芯片温度,数据返回值 3A  90  xx  xx  xx
  82.     on_press:
  83.       - uart.write: [0x3A ,0x10 ,0x00 ,0x00 ,0xEF]
  84.   - platform: template
  85.     name: "On ambient light"                            #进入实时环境光测,数据返回值 3A  8F  xx  xx  xx
  86.     on_press:
  87.       - uart.write: [0x3A ,0x8F ,0x01 ,0x00 ,0xDB]
  88.   - platform: template
  89.     name: "Off ambient light"                           #退出实时环境光测
  90.     on_press:
  91.       - uart.write: [0x3A ,0x8F ,0x00 ,0x00 ,0x2F]
复制代码




[attach]51921[/attach]

[attach]51918[/attach]

[attach]51919[/attach]

[attach]51920[/attach]


作者: dengxiao    时间: 2023-10-1 23:41
感谢楼主分享,一直不懂esphome的自定义uart,现在可以学习了
作者: george65    时间: 2023-10-2 11:23
可以自定義兩組~三組uart嗎??

作者: jole    时间: 2023-10-2 15:25
这个传感器有点贵哦,雨量检测怎么样?准不准
作者: nbxzl    时间: 2023-10-2 20:16
jole 发表于 2023-10-2 15:25
这个传感器有点贵哦,雨量检测怎么样?准不准

还是比较灵敏准确的
作者: nbxzl    时间: 2023-10-2 20:17
george65 发表于 2023-10-2 11:23
可以自定義兩組~三組uart嗎??

我没有这么多UART,没测试过哦
作者: lensam    时间: 2023-10-2 22:11
不知道是否可以用汽车的雨刮雨量传感器,其实挺准的,只要有3个档,也够用了,就不知道能不能实现,这个就几十块,很便宜。
作者: nbxzl    时间: 2023-10-3 20:10
lensam 发表于 2023-10-2 22:11
不知道是否可以用汽车的雨刮雨量传感器,其实挺准的,只要有3个档,也够用了,就不知道能不能实现,这个就 ...

可以,这个是它应用之一
作者: Ari    时间: 2023-10-3 22:57
顶一个技术性,感谢分享
作者: silversucks    时间: 2023-10-9 10:02
谢谢分享   抄一份哦
作者: roc634    时间: 2024-3-28 10:36
这胶暴晒久了会不会老化变黄?
作者: nbxzl    时间: 2024-4-10 13:38
roc634 发表于 2024-3-28 10:36
这胶暴晒久了会不会老化变黄?

到目前为止半年时间,一直使用报警正常,安装位置在屋顶,没上去看。以前室外用过这个胶没问题
作者: a_dongde    时间: 2024-4-10 14:08
厉害呀大佬。。。
作者: misLia    时间: 2024-11-4 11:29
自从玩了HA后,就喜欢在某宝上翻各种传感器。前两天晚上,翻到了这个传感器,无奈自己不会弄。今天看到居然已经有第一个吃螃蟹的了。
作者: misLia    时间: 2024-11-4 16:54
大佬,手里还有多余的D1Mini,应该也能可以用吧。
作者: nbxzl    时间: 2024-11-22 01:07
D1Mini ?
作者: shadowba    时间: 2024-11-22 08:16
留名备用
作者: shaula    时间: 2024-11-22 10:42
感谢楼主分享。原先用的是电阻式传感器,用起来还可以,就是连续阴雨天的时候,判断不准确,另外还有氧化问题。因此,照这个贴子做了一个光学雨量传感器。只不过这个传感器主动上报的雨量状态还存在雨转晴时不会主动上报状态的问题。因此,做了一个自动化来读取雨量状态,其中的雨量开关即relay2是个虚拟开关,逻辑是当雨量开关打开时,触发自动化,每一秒读取一次传感器雨量状态,如果60次内有小雨、中雨或大雨,则重新触发自动化,否则就关闭雨量开关。

[attach]65144[/attach][attach]65145[/attach]
  1. alias: 雨量检测自动化测试
  2. description: ""
  3. triggers:
  4.   - trigger: state
  5.     entity_id:
  6.       - switch.relay2
  7.     to: "on"
  8. conditions: []
  9. actions:
  10.   - repeat:
  11.       count: 60
  12.       sequence:
  13.         - action: button.press
  14.           metadata: {}
  15.           data: {}
  16.           target:
  17.             entity_id: button.rainfall_status
  18.         - delay:
  19.             hours: 0
  20.             minutes: 0
  21.             seconds: 1
  22.             milliseconds: 0
  23.         - if:
  24.             - condition: or
  25.               conditions:
  26.                 - condition: state
  27.                   entity_id: sensor.rain_uart_value
  28.                   state: 3A8101002C
  29.                 - condition: state
  30.                   entity_id: sensor.rain_uart_value
  31.                   state: 3A81020001
  32.                 - condition: state
  33.                   entity_id: sensor.rain_uart_value
  34.                   state: 3A810300F5
  35.           then:
  36.             - action: automation.trigger
  37.               metadata: {}
  38.               data:
  39.                 skip_condition: true
  40.               target:
  41.                 entity_id: automation.yu_liang_jian_ce_zi_dong_hua_ce_shi
  42.   - action: switch.turn_off
  43.     metadata: {}
  44.     data: {}
  45.     target:
  46.       entity_id: switch.relay2
  47. mode: restart
复制代码



作者: misLia    时间: 2024-11-22 13:19
nbxzl 发表于 2024-11-22 01:07
D1Mini ?

esp8266 D1mini啊。
作者: misLia    时间: 2024-11-22 13:26
shaula 发表于 2024-11-22 10:42
感谢楼主分享。原先用的是电阻式传感器,用起来还可以,就是连续阴雨天的时候,判断不准确,另外还有氧化问 ...

我看你这是天台。供电是怎么解决的?风力?
作者: nbxzl    时间: 2024-11-22 20:58
shaula 发表于 2024-11-22 10:42
感谢楼主分享。原先用的是电阻式传感器,用起来还可以,就是连续阴雨天的时候,判断不准确,另外还有氧化问 ...


作者: nbxzl    时间: 2024-11-22 21:05
misLia 发表于 2024-11-4 16:54
大佬,手里还有多余的D1Mini,应该也能可以用吧。

应该可以用,试试看
作者: norikohxb    时间: 2025-1-22 00:51
多少钱老板?
作者: nbxzl    时间: 2025-2-12 11:29
norikohxb 发表于 2025-1-22 00:51
多少钱老板?

传感器大概60左右,WIFI芯片12左右,变压器大概15左右,其它配件大概是10左右
作者: norikohxb    时间: 2025-2-12 13:37
nbxzl 发表于 2025-2-12 11:29
传感器大概60左右,WIFI芯片12左右,变压器大概15左右,其它配件大概是10左右 ...

变压器我有是12v还是5v你的传感器+芯片的加工组合能否卖一个给我
作者: nbxzl    时间: 2025-2-18 16:51
norikohxb 发表于 2025-2-12 13:37
变压器我有是12v还是5v你的传感器+芯片的加工组合能否卖一个给我

最近工作比较忙,空闲时间比较少,没办法帮忙,你可按帖子依次制作,有什么不明白的可以提问,下面是之前购买的链接,供参考:
智能雨量检测模块RS200
可以用8266开发板代替单一模块
8266开发板
0.8mm间距 雨量传感器配套短线

86型空白面板:白色钢化玻璃表面
作者: nbxzl    时间: 2025-2-18 16:54
贴子用以前剩下的黑色空白面板,实际使用中,因放置在屋顶,加上黑色板吸热,易死机,处理成白色面,目前一直正常使用。
作者: hyq    时间: 2025-2-21 17:04
nbxzl 发表于 2025-2-18 16:54
贴子用以前剩下的黑色空白面板,实际使用中,因放置在屋顶,加上黑色板吸热,易死机,处理成白色面,目前一 ...

方便展示一下在HA中的效果图吗?
作者: nbxzl    时间: 2025-2-22 09:26
- id: '1696250526466'
  alias: 微信报警_下小雨
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.yuliang_177_yuliang_177_uart
    to: 3A8101002C
    for:
      hours: 0
      minutes: 0
      seconds: 5
    from: 3A810000D8
  condition: []
  action:
  - service: notify.wework
    data:
      message: 注意哦,下小雨了!
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - device_id: dce12561214bf712aa2421d330ee0654
    domain: button
    entity_id: fd51bd1cdec2dad2701131e14fb4b34d
    type: press
  mode: single
- id: '1696257537665'
  alias: 微信报警_小雨变中雨
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.yuliang_177_yuliang_177_uart
    for:
      hours: 0
      minutes: 0
      seconds: 5
    from: 3A8101002C
    to: 3A81020001
  condition: []
  action:
  - service: notify.wework
    data:
      message: 注意,小雨变中雨了!
  mode: single
- id: '1696257839578'
  alias: 微信报警_大雨变中雨
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.yuliang_177_yuliang_177_uart
    to: 3A81020001
    for:
      hours: 0
      minutes: 0
      seconds: 5
    from: 3A810300F5
  condition: []
  action:
  - service: notify.wework
    data:
      message: 哈哈,大雨变中雨了!
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - device_id: dce12561214bf712aa2421d330ee0654
    domain: button
    entity_id: fd51bd1cdec2dad2701131e14fb4b34d
    type: press
  mode: single
- id: '1696258084153'
  alias: 微信报警_中雨变小雨
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.yuliang_177_yuliang_177_uart
    to: 3A8101002C
    for:
      hours: 0
      minutes: 0
      seconds: 5
    from: 3A81020001
  condition: []
  action:
  - service: notify.wework
    data:
      message: 嘿嘿,中雨变小雨了!
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - device_id: dce12561214bf712aa2421d330ee0654
    domain: button
    entity_id: fd51bd1cdec2dad2701131e14fb4b34d
    type: press
  mode: single
- id: '1696258298242'
  alias: 微信报警_中雨变大雨
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.yuliang_177_yuliang_177_uart
    to: 3A810300F5
    for:
      hours: 0
      minutes: 0
      seconds: 5
    from: 3A81020001
  condition: []
  action:
  - service: notify.wework
    data:
      message: 唉,中雨变大雨了!
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - device_id: dce12561214bf712aa2421d330ee0654
    domain: button
    entity_id: fd51bd1cdec2dad2701131e14fb4b34d
    type: press
  mode: single
- id: '1696258463410'
  alias: 微信报警_天晴
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.yuliang_177_yuliang_177_uart
    to: 3A810000D8
    for:
      hours: 0
      minutes: 0
      seconds: 5
    from: 3A8101002C
  condition: []
  action:
  - service: notify.wework
    data:
      message: 耶,雨过天晴了!
  - delay:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  - device_id: dce12561214bf712aa2421d330ee0654
    domain: button
    entity_id: fd51bd1cdec2dad2701131e14fb4b34d
    type: press
  mode: single
- id: '1696258797194'
  alias: 微信报警_大雨变小雨
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.yuliang_177_yuliang_177_uart
    to: 3A8101002C
    for:
      hours: 0
      minutes: 0
      seconds: 5
    from: 3A810300F5
  condition: []
  action:
  - service: notify.wework
    data:
      message: 哈哈,大雨变小雨了!
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - device_id: dce12561214bf712aa2421d330ee0654
    domain: button
    entity_id: fd51bd1cdec2dad2701131e14fb4b34d
    type: press
  mode: single
- id: '1697345390585'
  alias: 自动刷新雨量状态
  description: ''
  trigger: []
  condition:
  - condition: state
    entity_id: sensor.yuliang_177_yuliang_177_uart
    state: 3A8101002C
    for:
      hours: 0
      minutes: 5
      seconds: 0
  - condition: state
    entity_id: sensor.yuliang_177_yuliang_177_uart
    state: 3A81020001
    for:
      hours: 0
      minutes: 5
      seconds: 0
  - condition: state
    entity_id: sensor.yuliang_177_yuliang_177_uart
    state: 3A810300F5
    for:
      hours: 0
      minutes: 5
      seconds: 0
  action:
  - device_id: dce12561214bf712aa2421d330ee0654
    domain: button
    entity_id: fd51bd1cdec2dad2701131e14fb4b34d
    type: press
  mode: single
作者: nbxzl    时间: 2025-2-22 09:29
本帖最后由 nbxzl 于 2025-2-22 09:31 编辑

HA界面中
[attach]68389[/attach]
设置了微信推送到手机上
[attach]68390[/attach]


作者: shaula    时间: 2025-2-23 20:22
nbxzl 发表于 2025-2-22 09:29
HA界面中

设置了微信推送到手机上

楼主,最新的esphome取消了custom组件,请教有什么办法可以读取 UART并传入到 Text Sensor传感器当中?
作者: nbxzl    时间: 2025-2-24 09:12
shaula 发表于 2025-2-23 20:22
楼主,最新的esphome取消了custom组件,请教有什么办法可以读取 UART并传入到 Text Sensor传感器当中? ...

抱歉,这个不清楚,实在想用可以临时安装老版ESPHOME
作者: shaula    时间: 2025-2-25 13:05
本帖最后由 shaula 于 2025-2-25 13:09 编辑
nbxzl 发表于 2025-2-24 09:12
抱歉,这个不清楚,实在想用可以临时安装老版ESPHOME

找到解决方案了
在esphome该设备的yaml文件里加入这一段后ota,即可使用custom组件。
external_components:
  - source:
      type: git
      url: https://github.com/robertklep/esphome-custom-component
    components: [ custom, custom_component ]

作者: nbxzl    时间: 2025-2-28 08:49
shaula 发表于 2025-2-25 13:05
找到解决方案了
在esphome该设备的yaml文件里加入这一段后ota,即可使用custom组件。
external_components ...






欢迎光临 『瀚思彼岸』» 智能家居技术论坛 (https://bbs.hassbian.com/) Powered by Discuz! X3.5