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

标题: [智能家居]: 实时监控家庭水流量情况 [打印本页]

作者: MX10085    时间: 2024-3-1 17:44
标题: [智能家居]: 实时监控家庭水流量情况
本帖最后由 MX10085 于 2024-3-2 19:42 编辑

[智能家居]: 实时监控家庭水流量情况
使用目的:实时监控家庭水流量情况,异常的话可以自动关闭水闸,不用担心会出现水浸地面的情况发生。

1. 使用环境
home-assistant
node-red
esphome
mariadb 数据库

2. 准备材料
esp32 板子
[attach]56353[/attach]
压力传感器
[attach]56354[/attach]
流量计
[attach]56355[/attach]

3. esp32刷入程序
[attach]56361[/attach]

控制代码:打x的地方自己更改
  1. ####################################################
  2. #                    基本信息                       #
  3. ####################################################
  4. esphome:
  5.   name: esp32s-s3-water
  6.   friendly_name: esp32s-s3-water

  7. esp32:
  8.   board: esp32-s3-devkitc-1
  9.   framework:
  10.     type: arduino

  11. # Enable logging
  12. logger:

  13. # Enable Home Assistant API
  14. api:
  15.   encryption:
  16.     key: "xxxxxxxxxxxxxxxxxxxxxxxxxx"

  17. ota:
  18.   password: "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"

  19. ####################################################
  20. #                    网络信息                       #
  21. ####################################################
  22. wifi:
  23.   ssid: !secret wifi_ssid
  24.   password: !secret wifi_password
  25.   # manual_ip:
  26.   #  static_ip: 192.168.2.50
  27.   #  gateway: 192.168.2.1
  28.   #  subnet: 255.255.255.0
  29.   #  dns1: 223.5.5.5
  30.   #  dns2: 223.6.6.6
  31.   # Enable fallback hotspot (captive portal) in case wifi connection fails
  32.   ap:
  33.     ssid: "Esp32s-s3-Water"
  34.     password: "xxxxxxxxxxxxxxxxxxx"

  35. captive_portal:

  36. ####################################################
  37. #                    时间信息                       #
  38. ####################################################
  39. time:
  40.   - platform: sntp
  41.     id: sntp_time
  42.     timezone: Asia/Shanghai
  43.     servers:
  44.       - ntp1.aliyun.com
  45.       - ntp2.aliyun.com
  46.       - ntp3.aliyun.com

  47. ####################################################
  48. #                    MQTT信息                       #
  49. ####################################################
  50. # mqtt:
  51. #  broker: 192.168.2.14
  52. #  username: !secret mqtt_username
  53. #  password: !secret mqtt_password

  54. ####################################################
  55. #                     传感器                        #
  56. ####################################################
  57. sensor:

  58. ####################  用水计量  #####################
  59.   - platform: pulse_counter
  60.     name: "Instant water consumption"
  61.     pin: GPIO12
  62.     id: water
  63.     unit_of_measurement: 'L/Min'
  64.     update_interval: 6s
  65.     filters:
  66.       # - multiply: 0.0020964360587002
  67.       - lambda: return (x / 477.0);
  68.     total:
  69.       name: "Total water consumption"
  70.       unit_of_measurement: "m³"
  71.       device_class: water
  72.       state_class: total_increasing
  73.       accuracy_decimals: 3
  74.       icon: "mdi:water"
  75.       filters:
  76.         - lambda: return (x / 477000.0);

  77.   # - platform: pulse_meter
  78.   #   pin: GPIO12
  79.   #   id: water
  80.   #   name: "Instant water consumption"
  81.   #   unit_of_measurement: "L/min"
  82.   #   icon: "mdi:water"
  83.   #   timeout: 1s
  84.   #   accuracy_decimals: 3
  85.   #   filters:
  86.   #     - lambda: return (x / 477.0);
  87.   #   total:
  88.   #     name: "Total water consumption"
  89.   #     unit_of_measurement: "m³"
  90.   #     device_class: water
  91.   #     state_class: total_increasing
  92.   #     accuracy_decimals: 3
  93.   #     icon: "mdi:water"
  94.   #     filters:
  95.   #       - lambda: return (x / 477000.0);

  96.   - platform: total_daily_energy
  97.     name: "Daily water consumption"
  98.     power_id: water
  99.     unit_of_measurement: 'm³'
  100.     filters:
  101.       - multiply: 0.06

  102. ####################  进水压力  #####################
  103.   - platform: adc
  104.     name: "Water inlet pressure"
  105.     icon: "mdi:gauge-low"
  106.     pin: GPIO1
  107.     id: water_inlet_pressure
  108.     unit_of_measurement: "bar"
  109.     update_interval: 6s
  110.     accuracy_decimals: 2
  111.     attenuation: 11db
  112.     filters:
  113.       - lambda: |-
  114.           if(x-0.41<0) return 0.00;
  115.           return (x-0.41) * 4.00;

  116. ####################  运行时间  #####################
  117.   - platform: uptime
  118.     name: Uptime Sensor
  119.     id: uptime_sensor
  120.     update_interval: 60s
复制代码

4. home-assistant 设置
[attach]56356[/attach]

[attach]56357[/attach]


5. node-red 设置
[attach]56358[/attach]

node-red 代码:
  1. [
  2.     {
  3.         "id": "e14bf0df.21632",
  4.         "type": "function",
  5.         "z": "f6f2187d.f17ca8",
  6.         "g": "5aabb8329669cca2",
  7.         "name": "添加",
  8.         "func": "\n//获取前一天的日期,这段不要改动\nvar dd = new Date();\ndd.setDate(dd.getDate() -1);\nvar y = dd.getFullYear();\nvar m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;\nvar d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();\nvar f = y + "-" + m + "-" + d;\n\n//water为表名,sj和dl字段名\n\nmsg.topic = "INSERT INTO water (sj,dl) VALUES (?,?)";\nmsg.payload = [f,msg.payload]\n\n//这里的f这个值是上面获取到的前一天的日期,要传递给数据库的sj字段\n//sj这个字段表示的是昨日的日期\n//msg.payload 是water的昨天电量更新后获取到的值,传递到dl里面\nreturn msg;\n",
  9.         "outputs": 1,
  10.         "noerr": 0,
  11.         "initialize": "",
  12.         "finalize": "",
  13.         "libs": [],
  14.         "x": 270,
  15.         "y": 3720,
  16.         "wires": [
  17.             [
  18.                 "3a5b1f229d5ac474"
  19.             ]
  20.         ]
  21.     },
  22.     {
  23.         "id": "4f5cb819.b6e44",
  24.         "type": "server-state-changed",
  25.         "z": "f6f2187d.f17ca8",
  26.         "g": "5aabb8329669cca2",
  27.         "name": "昨天用水量",
  28.         "server": "99c664b867ad2e30",
  29.         "version": 5,
  30.         "outputs": 1,
  31.         "exposeAsEntityConfig": "",
  32.         "entityId": "sensor.yesterday_water_consumption",
  33.         "entityIdType": "exact",
  34.         "outputInitially": false,
  35.         "stateType": "str",
  36.         "ifState": "",
  37.         "ifStateType": "str",
  38.         "ifStateOperator": "is",
  39.         "outputOnlyOnStateChange": true,
  40.         "for": 0,
  41.         "forType": "num",
  42.         "forUnits": "minutes",
  43.         "ignorePrevStateNull": false,
  44.         "ignorePrevStateUnknown": false,
  45.         "ignorePrevStateUnavailable": false,
  46.         "ignoreCurrentStateUnknown": false,
  47.         "ignoreCurrentStateUnavailable": false,
  48.         "outputProperties": [
  49.             {
  50.                 "property": "payload",
  51.                 "propertyType": "msg",
  52.                 "value": "",
  53.                 "valueType": "entityState"
  54.             },
  55.             {
  56.                 "property": "data",
  57.                 "propertyType": "msg",
  58.                 "value": "",
  59.                 "valueType": "eventData"
  60.             },
  61.             {
  62.                 "property": "topic",
  63.                 "propertyType": "msg",
  64.                 "value": "",
  65.                 "valueType": "triggerId"
  66.             }
  67.         ],
  68.         "x": 120,
  69.         "y": 3720,
  70.         "wires": [
  71.             [
  72.                 "e14bf0df.21632"
  73.             ]
  74.         ]
  75.     },
  76.     {
  77.         "id": "d606da6b.8c25d8",
  78.         "type": "function",
  79.         "z": "f6f2187d.f17ca8",
  80.         "g": "5aabb8329669cca2",
  81.         "name": "查询",
  82.         "func": "msg.topic = "SELECT (select round(SUM(dl),4) from water where yearweek(date_format(sj,'%Y-%m-%d'),1)=yearweek(now(),1)) as d1,(select round(SUM(dl),4) from water where yearweek(date_format(sj,'%Y-%m-%d'),1)=yearweek(now(),1)-1) as d2,(select round(SUM(dl),4) from water where date_format( sj, '%y%m' ) = date_format( curdate( ) , '%y%m' )) as d3,(select round(SUM(dl),4) from water where period_diff( date_format( now( ) , '%y%m' ) , date_format( sj, '%y%m' ) ) =1) as d4,(select round(SUM(dl),4) from water where date_format( sj, '%y' ) = date_format( curdate( ) , '%y' )) as d5";\nmsg.jt = msg.payload //把今日用电量保存在jt里面,后面要用\nreturn msg;\n\n// round(SUM(dl),3). 保留小数点后3位\n// yearweek(date_format(sj,'%Y-%m-%d'),1)  后面这个1表示从周一开始一周\n//water表示表名,当你多个dc插排,创建了多个表时,修改这个表名即可。",
  83.         "outputs": 1,
  84.         "noerr": 0,
  85.         "initialize": "",
  86.         "finalize": "",
  87.         "libs": [],
  88.         "x": 270,
  89.         "y": 3880,
  90.         "wires": [
  91.             [
  92.                 "627b9fe6.71d368"
  93.             ]
  94.         ]
  95.     },
  96.     {
  97.         "id": "39af7a27.7b04f6",
  98.         "type": "mqtt out",
  99.         "z": "f6f2187d.f17ca8",
  100.         "g": "5aabb8329669cca2",
  101.         "name": "本周",
  102.         "topic": "esp32s_water/sensor/this_work",
  103.         "qos": "0",
  104.         "retain": "true",
  105.         "respTopic": "",
  106.         "contentType": "",
  107.         "userProps": "",
  108.         "correl": "",
  109.         "expiry": "",
  110.         "broker": "22b93c622b5df242",
  111.         "x": 830,
  112.         "y": 3720,
  113.         "wires": []
  114.     },
  115.     {
  116.         "id": "d71eaf9b.e70e8",
  117.         "type": "change",
  118.         "z": "f6f2187d.f17ca8",
  119.         "g": "5aabb8329669cca2",
  120.         "name": "本周",
  121.         "rules": [
  122.             {
  123.                 "t": "move",
  124.                 "p": "payload[0].d1",
  125.                 "pt": "msg",
  126.                 "to": "payload",
  127.                 "tot": "msg"
  128.             }
  129.         ],
  130.         "action": "",
  131.         "property": "",
  132.         "from": "",
  133.         "to": "",
  134.         "reg": false,
  135.         "x": 550,
  136.         "y": 3720,
  137.         "wires": [
  138.             [
  139.                 "b0f09ef3.4b0c9"
  140.             ]
  141.         ]
  142.     },
  143.     {
  144.         "id": "9479aaf3.27cb38",
  145.         "type": "mqtt out",
  146.         "z": "f6f2187d.f17ca8",
  147.         "g": "5aabb8329669cca2",
  148.         "name": "上周",
  149.         "topic": "esp32s_water/sensor/last_work",
  150.         "qos": "0",
  151.         "retain": "true",
  152.         "respTopic": "",
  153.         "contentType": "",
  154.         "userProps": "",
  155.         "correl": "",
  156.         "expiry": "",
  157.         "broker": "22b93c622b5df242",
  158.         "x": 830,
  159.         "y": 3760,
  160.         "wires": []
  161.     },
  162.     {
  163.         "id": "c6a6fdf8.09f01",
  164.         "type": "change",
  165.         "z": "f6f2187d.f17ca8",
  166.         "g": "5aabb8329669cca2",
  167.         "name": "上周",
  168.         "rules": [
  169.             {
  170.                 "t": "move",
  171.                 "p": "payload[0].d2",
  172.                 "pt": "msg",
  173.                 "to": "payload",
  174.                 "tot": "msg"
  175.             }
  176.         ],
  177.         "action": "",
  178.         "property": "",
  179.         "from": "",
  180.         "to": "",
  181.         "reg": false,
  182.         "x": 550,
  183.         "y": 3760,
  184.         "wires": [
  185.             [
  186.                 "9479aaf3.27cb38"
  187.             ]
  188.         ]
  189.     },
  190.     {
  191.         "id": "b8160812.22e7e8",
  192.         "type": "mqtt out",
  193.         "z": "f6f2187d.f17ca8",
  194.         "g": "5aabb8329669cca2",
  195.         "name": "本月",
  196.         "topic": "esp32s_water/sensor/this_month",
  197.         "qos": "0",
  198.         "retain": "true",
  199.         "respTopic": "",
  200.         "contentType": "",
  201.         "userProps": "",
  202.         "correl": "",
  203.         "expiry": "",
  204.         "broker": "22b93c622b5df242",
  205.         "x": 830,
  206.         "y": 3800,
  207.         "wires": []
  208.     },
  209.     {
  210.         "id": "ee67cdba.c347e",
  211.         "type": "change",
  212.         "z": "f6f2187d.f17ca8",
  213.         "g": "5aabb8329669cca2",
  214.         "name": "本月",
  215.         "rules": [
  216.             {
  217.                 "t": "move",
  218.                 "p": "payload[0].d3",
  219.                 "pt": "msg",
  220.                 "to": "payload",
  221.                 "tot": "msg"
  222.             }
  223.         ],
  224.         "action": "",
  225.         "property": "",
  226.         "from": "",
  227.         "to": "",
  228.         "reg": false,
  229.         "x": 550,
  230.         "y": 3800,
  231.         "wires": [
  232.             [
  233.                 "f5d351c.7fa6db"
  234.             ]
  235.         ]
  236.     },
  237.     {
  238.         "id": "3ea0f493.f22634",
  239.         "type": "mqtt out",
  240.         "z": "f6f2187d.f17ca8",
  241.         "g": "5aabb8329669cca2",
  242.         "name": "上月",
  243.         "topic": "esp32s_water/sensor/last_month",
  244.         "qos": "0",
  245.         "retain": "true",
  246.         "respTopic": "",
  247.         "contentType": "",
  248.         "userProps": "",
  249.         "correl": "",
  250.         "expiry": "",
  251.         "broker": "22b93c622b5df242",
  252.         "x": 830,
  253.         "y": 3840,
  254.         "wires": []
  255.     },
  256.     {
  257.         "id": "acb53b1b.0cd358",
  258.         "type": "change",
  259.         "z": "f6f2187d.f17ca8",
  260.         "g": "5aabb8329669cca2",
  261.         "name": "上月",
  262.         "rules": [
  263.             {
  264.                 "t": "move",
  265.                 "p": "payload[0].d4",
  266.                 "pt": "msg",
  267.                 "to": "payload",
  268.                 "tot": "msg"
  269.             }
  270.         ],
  271.         "action": "",
  272.         "property": "",
  273.         "from": "",
  274.         "to": "",
  275.         "reg": false,
  276.         "x": 550,
  277.         "y": 3840,
  278.         "wires": [
  279.             [
  280.                 "3ea0f493.f22634"
  281.             ]
  282.         ]
  283.     },
  284.     {
  285.         "id": "b0f09ef3.4b0c9",
  286.         "type": "function",
  287.         "z": "f6f2187d.f17ca8",
  288.         "g": "5aabb8329669cca2",
  289.         "name": "相加",
  290.         "func": "//将本周用电量加上今日实时用电量  得出最新的本周用电量\nmsg.payload = Number(msg.payload) + Number(msg.jt);\nreturn msg;",
  291.         "outputs": 1,
  292.         "noerr": 0,
  293.         "initialize": "",
  294.         "finalize": "",
  295.         "libs": [],
  296.         "x": 690,
  297.         "y": 3720,
  298.         "wires": [
  299.             [
  300.                 "39af7a27.7b04f6"
  301.             ]
  302.         ]
  303.     },
  304.     {
  305.         "id": "f5d351c.7fa6db",
  306.         "type": "function",
  307.         "z": "f6f2187d.f17ca8",
  308.         "g": "5aabb8329669cca2",
  309.         "name": "相加",
  310.         "func": "//将本月用电量加上今日实时用电量  得出最新的本月用电量\nmsg.payload = Number(msg.payload) + Number(msg.jt);\nreturn msg;",
  311.         "outputs": 1,
  312.         "noerr": 0,
  313.         "initialize": "",
  314.         "finalize": "",
  315.         "libs": [],
  316.         "x": 690,
  317.         "y": 3800,
  318.         "wires": [
  319.             [
  320.                 "b8160812.22e7e8"
  321.             ]
  322.         ]
  323.     },
  324.     {
  325.         "id": "1aca4370.6e8785",
  326.         "type": "server-state-changed",
  327.         "z": "f6f2187d.f17ca8",
  328.         "g": "5aabb8329669cca2",
  329.         "name": "今日用水量",
  330.         "server": "99c664b867ad2e30",
  331.         "version": 5,
  332.         "outputs": 1,
  333.         "exposeAsEntityConfig": "",
  334.         "entityId": "sensor.daily_water_consumption",
  335.         "entityIdType": "exact",
  336.         "outputInitially": false,
  337.         "stateType": "str",
  338.         "ifState": "",
  339.         "ifStateType": "str",
  340.         "ifStateOperator": "is",
  341.         "outputOnlyOnStateChange": true,
  342.         "for": 0,
  343.         "forType": "num",
  344.         "forUnits": "minutes",
  345.         "ignorePrevStateNull": false,
  346.         "ignorePrevStateUnknown": false,
  347.         "ignorePrevStateUnavailable": false,
  348.         "ignoreCurrentStateUnknown": false,
  349.         "ignoreCurrentStateUnavailable": false,
  350.         "outputProperties": [
  351.             {
  352.                 "property": "payload",
  353.                 "propertyType": "msg",
  354.                 "value": "",
  355.                 "valueType": "entityState"
  356.             },
  357.             {
  358.                 "property": "data",
  359.                 "propertyType": "msg",
  360.                 "value": "",
  361.                 "valueType": "eventData"
  362.             },
  363.             {
  364.                 "property": "topic",
  365.                 "propertyType": "msg",
  366.                 "value": "",
  367.                 "valueType": "triggerId"
  368.             }
  369.         ],
  370.         "x": 120,
  371.         "y": 3880,
  372.         "wires": [
  373.             [
  374.                 "d606da6b.8c25d8"
  375.             ]
  376.         ]
  377.     },
  378.     {
  379.         "id": "627b9fe6.71d368",
  380.         "type": "mysql",
  381.         "z": "f6f2187d.f17ca8",
  382.         "g": "5aabb8329669cca2",
  383.         "mydb": "f30e442.46d6a38",
  384.         "name": "数据库",
  385.         "x": 410,
  386.         "y": 3880,
  387.         "wires": [
  388.             [
  389.                 "d71eaf9b.e70e8",
  390.                 "c6a6fdf8.09f01",
  391.                 "ee67cdba.c347e",
  392.                 "acb53b1b.0cd358",
  393.                 "2716b815c1611442"
  394.             ]
  395.         ]
  396.     },
  397.     {
  398.         "id": "43567a10.ed7b74",
  399.         "type": "mqtt out",
  400.         "z": "f6f2187d.f17ca8",
  401.         "g": "5aabb8329669cca2",
  402.         "name": "本周用水量",
  403.         "topic": "homeassistant/sensor/esp32s_water/1/config",
  404.         "qos": "0",
  405.         "retain": "true",
  406.         "respTopic": "",
  407.         "contentType": "",
  408.         "userProps": "",
  409.         "correl": "",
  410.         "expiry": "",
  411.         "broker": "22b93c622b5df242",
  412.         "x": 1350,
  413.         "y": 3720,
  414.         "wires": []
  415.     },
  416.     {
  417.         "id": "aced1bb.32392e8",
  418.         "type": "inject",
  419.         "z": "f6f2187d.f17ca8",
  420.         "g": "5aabb8329669cca2",
  421.         "name": "自动发现",
  422.         "props": [
  423.             {
  424.                 "p": "payload"
  425.             }
  426.         ],
  427.         "repeat": "",
  428.         "crontab": "",
  429.         "once": true,
  430.         "onceDelay": "1",
  431.         "topic": "",
  432.         "payload": "{"unit_of_measurement":"m³","device_class":"sensor","unique_id":"water_this_work","state_topic":"esp32s_water/sensor/this_work","name":"本周用水量"}",
  433.         "payloadType": "json",
  434.         "x": 1040,
  435.         "y": 3720,
  436.         "wires": [
  437.             [
  438.                 "bf98089f.a7d578"
  439.             ]
  440.         ]
  441.     },
  442.     {
  443.         "id": "bf98089f.a7d578",
  444.         "type": "rbe",
  445.         "z": "f6f2187d.f17ca8",
  446.         "g": "5aabb8329669cca2",
  447.         "name": "",
  448.         "func": "rbe",
  449.         "gap": "",
  450.         "start": "",
  451.         "inout": "out",
  452.         "property": "payload",
  453.         "x": 1190,
  454.         "y": 3720,
  455.         "wires": [
  456.             [
  457.                 "43567a10.ed7b74"
  458.             ]
  459.         ]
  460.     },
  461.     {
  462.         "id": "47f7fb79.b15ecc",
  463.         "type": "mqtt out",
  464.         "z": "f6f2187d.f17ca8",
  465.         "g": "5aabb8329669cca2",
  466.         "name": "上周用水量",
  467.         "topic": "homeassistant/sensor/esp32s_water/2/config",
  468.         "qos": "0",
  469.         "retain": "true",
  470.         "respTopic": "",
  471.         "contentType": "",
  472.         "userProps": "",
  473.         "correl": "",
  474.         "expiry": "",
  475.         "broker": "22b93c622b5df242",
  476.         "x": 1350,
  477.         "y": 3760,
  478.         "wires": []
  479.     },
  480.     {
  481.         "id": "87599a40.d5562",
  482.         "type": "inject",
  483.         "z": "f6f2187d.f17ca8",
  484.         "g": "5aabb8329669cca2",
  485.         "name": "自动发现",
  486.         "props": [
  487.             {
  488.                 "p": "payload"
  489.             }
  490.         ],
  491.         "repeat": "",
  492.         "crontab": "",
  493.         "once": true,
  494.         "onceDelay": "1",
  495.         "topic": "",
  496.         "payload": "{"unit_of_measurement":"m³","device_class":"sensor","unique_id":"water_last_work","state_topic":"esp32s_water/sensor/last_work","name":"上周用水量"}",
  497.         "payloadType": "json",
  498.         "x": 1040,
  499.         "y": 3760,
  500.         "wires": [
  501.             [
  502.                 "fada92ab.eacd3"
  503.             ]
  504.         ]
  505.     },
  506.     {
  507.         "id": "fada92ab.eacd3",
  508.         "type": "rbe",
  509.         "z": "f6f2187d.f17ca8",
  510.         "g": "5aabb8329669cca2",
  511.         "name": "",
  512.         "func": "rbe",
  513.         "gap": "",
  514.         "start": "",
  515.         "inout": "out",
  516.         "property": "payload",
  517.         "x": 1190,
  518.         "y": 3760,
  519.         "wires": [
  520.             [
  521.                 "47f7fb79.b15ecc"
  522.             ]
  523.         ]
  524.     },
  525.     {
  526.         "id": "b9588b7a.b9b81",
  527.         "type": "mqtt out",
  528.         "z": "f6f2187d.f17ca8",
  529.         "g": "5aabb8329669cca2",
  530.         "name": "本月用水量",
  531.         "topic": "homeassistant/sensor/esp32s_water/3/config",
  532.         "qos": "0",
  533.         "retain": "true",
  534.         "respTopic": "",
  535.         "contentType": "",
  536.         "userProps": "",
  537.         "correl": "",
  538.         "expiry": "",
  539.         "broker": "22b93c622b5df242",
  540.         "x": 1350,
  541.         "y": 3800,
  542.         "wires": []
  543.     },
  544.     {
  545.         "id": "a164a83d.756c78",
  546.         "type": "inject",
  547.         "z": "f6f2187d.f17ca8",
  548.         "g": "5aabb8329669cca2",
  549.         "name": "自动发现",
  550.         "props": [
  551.             {
  552.                 "p": "payload"
  553.             }
  554.         ],
  555.         "repeat": "",
  556.         "crontab": "",
  557.         "once": true,
  558.         "onceDelay": "1",
  559.         "topic": "",
  560.         "payload": "{"unit_of_measurement":"m³","device_class":"sensor","unique_id":"water_this_month","state_topic":"esp32s_water/sensor/this_month","name":"本月用水量"}",
  561.         "payloadType": "json",
  562.         "x": 1040,
  563.         "y": 3800,
  564.         "wires": [
  565.             [
  566.                 "82c7517d.f97f6"
  567.             ]
  568.         ]
  569.     },
  570.     {
  571.         "id": "82c7517d.f97f6",
  572.         "type": "rbe",
  573.         "z": "f6f2187d.f17ca8",
  574.         "g": "5aabb8329669cca2",
  575.         "name": "",
  576.         "func": "rbe",
  577.         "gap": "",
  578.         "start": "",
  579.         "inout": "out",
  580.         "property": "payload",
  581.         "x": 1190,
  582.         "y": 3800,
  583.         "wires": [
  584.             [
  585.                 "b9588b7a.b9b81"
  586.             ]
  587.         ]
  588.     },
  589.     {
  590.         "id": "402fecad.f6d254",
  591.         "type": "inject",
  592.         "z": "f6f2187d.f17ca8",
  593.         "g": "5aabb8329669cca2",
  594.         "name": "自动发现",
  595.         "props": [
  596.             {
  597.                 "p": "payload"
  598.             }
  599.         ],
  600.         "repeat": "",
  601.         "crontab": "",
  602.         "once": true,
  603.         "onceDelay": "1",
  604.         "topic": "",
  605.         "payload": "{"unit_of_measurement":"m³","device_class":"sensor","unique_id":"water_last_month","state_topic":"esp32s_water/sensor/last_month","name":"上月用水量"}",
  606.         "payloadType": "json",
  607.         "x": 1040,
  608.         "y": 3840,
  609.         "wires": [
  610.             [
  611.                 "60a5d683.5d23"
  612.             ]
  613.         ]
  614.     },
  615.     {
  616.         "id": "60a5d683.5d23",
  617.         "type": "rbe",
  618.         "z": "f6f2187d.f17ca8",
  619.         "g": "5aabb8329669cca2",
  620.         "name": "",
  621.         "func": "rbe",
  622.         "gap": "",
  623.         "start": "",
  624.         "inout": "out",
  625.         "property": "payload",
  626.         "x": 1190,
  627.         "y": 3840,
  628.         "wires": [
  629.             [
  630.                 "fd29d03e.19de5"
  631.             ]
  632.         ]
  633.     },
  634.     {
  635.         "id": "fd29d03e.19de5",
  636.         "type": "mqtt out",
  637.         "z": "f6f2187d.f17ca8",
  638.         "g": "5aabb8329669cca2",
  639.         "name": "上月用水量",
  640.         "topic": "homeassistant/sensor/esp32s_water/4/config",
  641.         "qos": "0",
  642.         "retain": "true",
  643.         "respTopic": "",
  644.         "contentType": "",
  645.         "userProps": "",
  646.         "correl": "",
  647.         "expiry": "",
  648.         "broker": "22b93c622b5df242",
  649.         "x": 1350,
  650.         "y": 3840,
  651.         "wires": []
  652.     },
  653.     {
  654.         "id": "3a5b1f229d5ac474",
  655.         "type": "mysql",
  656.         "z": "f6f2187d.f17ca8",
  657.         "g": "5aabb8329669cca2",
  658.         "mydb": "f30e442.46d6a38",
  659.         "name": "数据库",
  660.         "x": 410,
  661.         "y": 3720,
  662.         "wires": [
  663.             []
  664.         ]
  665.     },
  666.     {
  667.         "id": "2716b815c1611442",
  668.         "type": "change",
  669.         "z": "f6f2187d.f17ca8",
  670.         "g": "5aabb8329669cca2",
  671.         "name": "本年",
  672.         "rules": [
  673.             {
  674.                 "t": "move",
  675.                 "p": "payload[0].d5",
  676.                 "pt": "msg",
  677.                 "to": "payload",
  678.                 "tot": "msg"
  679.             }
  680.         ],
  681.         "action": "",
  682.         "property": "",
  683.         "from": "",
  684.         "to": "",
  685.         "reg": false,
  686.         "x": 550,
  687.         "y": 3880,
  688.         "wires": [
  689.             [
  690.                 "e954b3588272f65a"
  691.             ]
  692.         ]
  693.     },
  694.     {
  695.         "id": "e954b3588272f65a",
  696.         "type": "function",
  697.         "z": "f6f2187d.f17ca8",
  698.         "g": "5aabb8329669cca2",
  699.         "name": "相加",
  700.         "func": "//将本月用电量加上今日实时用电量  得出最新的本月用电量\nmsg.payload = Number(msg.payload) + Number(msg.jt);\nreturn msg;",
  701.         "outputs": 1,
  702.         "noerr": 0,
  703.         "initialize": "",
  704.         "finalize": "",
  705.         "libs": [],
  706.         "x": 690,
  707.         "y": 3880,
  708.         "wires": [
  709.             [
  710.                 "56313c7539e5661a"
  711.             ]
  712.         ]
  713.     },
  714.     {
  715.         "id": "56313c7539e5661a",
  716.         "type": "mqtt out",
  717.         "z": "f6f2187d.f17ca8",
  718.         "g": "5aabb8329669cca2",
  719.         "name": "本年",
  720.         "topic": "esp32s_water/sensor/this_year",
  721.         "qos": "0",
  722.         "retain": "true",
  723.         "respTopic": "",
  724.         "contentType": "",
  725.         "userProps": "",
  726.         "correl": "",
  727.         "expiry": "",
  728.         "broker": "22b93c622b5df242",
  729.         "x": 830,
  730.         "y": 3880,
  731.         "wires": []
  732.     },
  733.     {
  734.         "id": "fa62e117cc0198c7",
  735.         "type": "inject",
  736.         "z": "f6f2187d.f17ca8",
  737.         "g": "5aabb8329669cca2",
  738.         "name": "自动发现",
  739.         "props": [
  740.             {
  741.                 "p": "payload"
  742.             }
  743.         ],
  744.         "repeat": "",
  745.         "crontab": "",
  746.         "once": true,
  747.         "onceDelay": "1",
  748.         "topic": "",
  749.         "payload": "{"unit_of_measurement":"m³","device_class":"sensor","unique_id":"water_this_year","state_topic":"esp32s_water/sensor/this_year","name":"本年用水量"}",
  750.         "payloadType": "json",
  751.         "x": 1040,
  752.         "y": 3880,
  753.         "wires": [
  754.             [
  755.                 "457b3b8001534312"
  756.             ]
  757.         ]
  758.     },
  759.     {
  760.         "id": "457b3b8001534312",
  761.         "type": "rbe",
  762.         "z": "f6f2187d.f17ca8",
  763.         "g": "5aabb8329669cca2",
  764.         "name": "",
  765.         "func": "rbe",
  766.         "gap": "",
  767.         "start": "",
  768.         "inout": "out",
  769.         "property": "payload",
  770.         "x": 1190,
  771.         "y": 3880,
  772.         "wires": [
  773.             [
  774.                 "c8177c495fb470d0"
  775.             ]
  776.         ]
  777.     },
  778.     {
  779.         "id": "c8177c495fb470d0",
  780.         "type": "mqtt out",
  781.         "z": "f6f2187d.f17ca8",
  782.         "g": "5aabb8329669cca2",
  783.         "name": "本年用水量",
  784.         "topic": "homeassistant/sensor/esp32s_water/5/config",
  785.         "qos": "0",
  786.         "retain": "true",
  787.         "respTopic": "",
  788.         "contentType": "",
  789.         "userProps": "",
  790.         "correl": "",
  791.         "expiry": "",
  792.         "broker": "22b93c622b5df242",
  793.         "x": 1350,
  794.         "y": 3880,
  795.         "wires": []
  796.     },
  797.     {
  798.         "id": "99c664b867ad2e30",
  799.         "type": "server",
  800.         "name": "omv-homeassistant",
  801.         "version": 5,
  802.         "addon": false,
  803.         "rejectUnauthorizedCerts": true,
  804.         "ha_boolean": "y|yes|true|on|home|open",
  805.         "connectionDelay": true,
  806.         "cacheJson": true,
  807.         "heartbeat": false,
  808.         "heartbeatInterval": "30",
  809.         "areaSelector": "friendlyName",
  810.         "deviceSelector": "friendlyName",
  811.         "entitySelector": "friendlyName",
  812.         "statusSeparator": "at: ",
  813.         "statusYear": "hidden",
  814.         "statusMonth": "short",
  815.         "statusDay": "numeric",
  816.         "statusHourCycle": "h23",
  817.         "statusTimeFormat": "h:m",
  818.         "enableGlobalContextStore": true
  819.     },
  820.     {
  821.         "id": "22b93c622b5df242",
  822.         "type": "mqtt-broker",
  823.         "name": "omv-emqx",
  824.         "broker": "192.168.2.10",
  825.         "port": "1883",
  826.         "clientid": "node-red",
  827.         "autoConnect": true,
  828.         "usetls": false,
  829.         "protocolVersion": "4",
  830.         "keepalive": "60",
  831.         "cleansession": true,
  832.         "autoUnsubscribe": true,
  833.         "birthTopic": "",
  834.         "birthQos": "0",
  835.         "birthPayload": "",
  836.         "birthMsg": {},
  837.         "closeTopic": "",
  838.         "closeQos": "0",
  839.         "closePayload": "",
  840.         "closeMsg": {},
  841.         "willTopic": "",
  842.         "willQos": "0",
  843.         "willPayload": "",
  844.         "willMsg": {},
  845.         "userProps": "",
  846.         "sessionExpiry": ""
  847.     },
  848.     {
  849.         "id": "f30e442.46d6a38",
  850.         "type": "MySQLdatabase",
  851.         "name": "",
  852.         "host": "192.168.2.10",
  853.         "port": "3306",
  854.         "db": "esp32s_water",
  855.         "tz": "",
  856.         "charset": "UTF8"
  857.     }
  858. ]
复制代码

6. 完成效果
[attach]56359[/attach]

[attach]56360[/attach]

[attach]56404[/attach]

作者: hhh.    时间: 2024-3-1 18:09
感谢大佬分享
作者: sorrypqa    时间: 2024-3-1 19:35
学习一下,谢谢楼主分享!
作者: wpw72    时间: 2024-3-1 19:51
再加个电动球阀,做成自来水的测控
作者: dbh    时间: 2024-3-1 21:23
wpw72 发表于 2024-3-1 19:51
再加个电动球阀,做成自来水的测控

我就是安装了个球阀,只要人不在家,就关闭。有人回家就打开。同时也安装好几只小米的水浸传感器,也设定了漏水关阀。
作者: bugensui    时间: 2024-3-1 21:52
怎么接线
作者: xjol    时间: 2024-3-1 21:56
压力传感器  是什么规格的?
作者: MX10085    时间: 2024-3-1 22:20
xjol 发表于 2024-3-1 21:56
压力传感器  是什么规格的?

选5V电压,兼容Arduino的,
作者: MX10085    时间: 2024-3-1 22:21
bugensui 发表于 2024-3-1 21:52
怎么接线

传感器就+-与信号3根线
作者: jj1234567    时间: 2024-3-2 11:55
流量计材质是不锈钢么?
作者: 隔壁的王叔叔    时间: 2024-3-2 14:06
大佬,压力变送器和流量计的链接分享一下呗。谢谢
作者: 点来点去    时间: 2024-3-2 15:25
谢谢楼主分享!
作者: 点来点去    时间: 2024-3-2 15:34
楼主 导入nr代码报错。
作者: MX10085    时间: 2024-3-2 19:46
点来点去 发表于 2024-3-2 15:34
楼主 导入nr代码报错。

上传个文件了,里面要添加数据库
你看看这个帖子:https://bbs.hassbian.com/thread-13265-1-1.html
作者: MX10085    时间: 2024-3-2 19:51
隔壁的王叔叔 发表于 2024-3-2 14:06
大佬,压力变送器和流量计的链接分享一下呗。谢谢

某宝入的,搜索的一就有,霍尔流量计,与模拟量压力传感器选用5V电压的,供电方便。
作者: 隔壁的王叔叔    时间: 2024-3-2 19:54
MX10085 发表于 2024-3-2 19:51
某宝入的,搜索的一就有,霍尔流量计,与模拟量压力传感器选用5V电压的,供电方便。 ...

收到,感谢。
作者: laogong888    时间: 2024-3-2 20:27
我是小米水浸传感器加上自制的水绳探头加上电动球阀,只要有一出探测到有水就触发自动化关阀,给手机发信息。
作者: hunterfox    时间: 2024-3-2 20:51
可以将统计信息全部放到ESP32里。这个少个NR环节
作者: wpw72    时间: 2024-3-3 10:15
dbh 发表于 2024-3-1 21:23
我就是安装了个球阀,只要人不在家,就关闭。有人回家就打开。同时也安装好几只小米的水浸传感器,也设定 ...

我原本的意思是加一个普通电动球阀,由这个系统控制(控制电动阀的开、关,同时返回阀门的位置信息),可以不用买wifi、ble或zigbee的智能球阀了
作者: 尼陌    时间: 2024-3-3 17:07
dbh 发表于 2024-3-1 21:23
我就是安装了个球阀,只要人不在家,就关闭。有人回家就打开。同时也安装好几只小米的水浸传感器,也设定 ...

球阀哪种适合一点,是常开?常闭?还是三线控制的?
作者: 尼陌    时间: 2024-3-3 17:42
wpw72 发表于 2024-3-3 10:15
我原本的意思是加一个普通电动球阀,由这个系统控制(控制电动阀的开、关,同时返回阀门的位置信息),可 ...

可以用继电器加普通电动球阀。
作者: wpw72    时间: 2024-3-3 18:10
本帖最后由 wpw72 于 2024-3-3 18:22 编辑
尼陌 发表于 2024-3-3 17:42
可以用继电器加普通电动球阀。

对,单片机+继电器模块来控制球阀开关,最好球阀有带开关到位信号输出反馈的
作者: xjol    时间: 2024-3-3 22:14
MX10085 发表于 2024-3-1 22:20
选5V电压,兼容Arduino的,

谢谢,先买一个回来试一下
作者: xjol    时间: 2024-3-4 16:43
MX10085 发表于 2024-3-1 22:20
选5V电压,兼容Arduino的,

量程选  0-10 bar 就可以了吧
作者: hxkjc    时间: 2024-3-6 15:51
学习一下,谢谢楼主分享!
作者: 点来点去    时间: 2024-3-13 08:34
流量传感器有个注意事项,无负压二次供水如果压力不稳,压差大,传感器也会有读数。
作者: goldstep    时间: 2024-3-13 10:58
如果有自来水公司的智能水表,最好也能接入,做个对比就更好了
作者: 翻滚吧暖菌    时间: 2024-7-30 16:20
真的厉害
作者: heiyangou    时间: 2024-7-31 21:51
这个流量计统计和水表比对准确率怎么样?
作者: 尼陌    时间: 2024-12-15 13:47
自己做的,不太会焊接,稳定性很差。。。




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