[
{
"id": "e14bf0df.21632",
"type": "function",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "添加",
"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",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 270,
"y": 3720,
"wires": [
[
"3a5b1f229d5ac474"
]
]
},
{
"id": "4f5cb819.b6e44",
"type": "server-state-changed",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "昨天用水量",
"server": "99c664b867ad2e30",
"version": 5,
"outputs": 1,
"exposeAsEntityConfig": "",
"entityId": "sensor.yesterday_water_consumption",
"entityIdType": "exact",
"outputInitially": false,
"stateType": "str",
"ifState": "",
"ifStateType": "str",
"ifStateOperator": "is",
"outputOnlyOnStateChange": true,
"for": 0,
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
},
{
"property": "topic",
"propertyType": "msg",
"value": "",
"valueType": "triggerId"
}
],
"x": 120,
"y": 3720,
"wires": [
[
"e14bf0df.21632"
]
]
},
{
"id": "d606da6b.8c25d8",
"type": "function",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "查询",
"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插排,创建了多个表时,修改这个表名即可。",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 270,
"y": 3880,
"wires": [
[
"627b9fe6.71d368"
]
]
},
{
"id": "39af7a27.7b04f6",
"type": "mqtt out",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "本周",
"topic": "esp32s_water/sensor/this_work",
"qos": "0",
"retain": "true",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "22b93c622b5df242",
"x": 830,
"y": 3720,
"wires": []
},
{
"id": "d71eaf9b.e70e8",
"type": "change",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "本周",
"rules": [
{
"t": "move",
"p": "payload[0].d1",
"pt": "msg",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 550,
"y": 3720,
"wires": [
[
"b0f09ef3.4b0c9"
]
]
},
{
"id": "9479aaf3.27cb38",
"type": "mqtt out",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "上周",
"topic": "esp32s_water/sensor/last_work",
"qos": "0",
"retain": "true",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "22b93c622b5df242",
"x": 830,
"y": 3760,
"wires": []
},
{
"id": "c6a6fdf8.09f01",
"type": "change",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "上周",
"rules": [
{
"t": "move",
"p": "payload[0].d2",
"pt": "msg",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 550,
"y": 3760,
"wires": [
[
"9479aaf3.27cb38"
]
]
},
{
"id": "b8160812.22e7e8",
"type": "mqtt out",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "本月",
"topic": "esp32s_water/sensor/this_month",
"qos": "0",
"retain": "true",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "22b93c622b5df242",
"x": 830,
"y": 3800,
"wires": []
},
{
"id": "ee67cdba.c347e",
"type": "change",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "本月",
"rules": [
{
"t": "move",
"p": "payload[0].d3",
"pt": "msg",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 550,
"y": 3800,
"wires": [
[
"f5d351c.7fa6db"
]
]
},
{
"id": "3ea0f493.f22634",
"type": "mqtt out",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "上月",
"topic": "esp32s_water/sensor/last_month",
"qos": "0",
"retain": "true",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "22b93c622b5df242",
"x": 830,
"y": 3840,
"wires": []
},
{
"id": "acb53b1b.0cd358",
"type": "change",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "上月",
"rules": [
{
"t": "move",
"p": "payload[0].d4",
"pt": "msg",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 550,
"y": 3840,
"wires": [
[
"3ea0f493.f22634"
]
]
},
{
"id": "b0f09ef3.4b0c9",
"type": "function",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "相加",
"func": "//将本周用电量加上今日实时用电量 得出最新的本周用电量\nmsg.payload = Number(msg.payload) + Number(msg.jt);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 3720,
"wires": [
[
"39af7a27.7b04f6"
]
]
},
{
"id": "f5d351c.7fa6db",
"type": "function",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "相加",
"func": "//将本月用电量加上今日实时用电量 得出最新的本月用电量\nmsg.payload = Number(msg.payload) + Number(msg.jt);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 3800,
"wires": [
[
"b8160812.22e7e8"
]
]
},
{
"id": "1aca4370.6e8785",
"type": "server-state-changed",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "今日用水量",
"server": "99c664b867ad2e30",
"version": 5,
"outputs": 1,
"exposeAsEntityConfig": "",
"entityId": "sensor.daily_water_consumption",
"entityIdType": "exact",
"outputInitially": false,
"stateType": "str",
"ifState": "",
"ifStateType": "str",
"ifStateOperator": "is",
"outputOnlyOnStateChange": true,
"for": 0,
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
},
{
"property": "topic",
"propertyType": "msg",
"value": "",
"valueType": "triggerId"
}
],
"x": 120,
"y": 3880,
"wires": [
[
"d606da6b.8c25d8"
]
]
},
{
"id": "627b9fe6.71d368",
"type": "mysql",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"mydb": "f30e442.46d6a38",
"name": "数据库",
"x": 410,
"y": 3880,
"wires": [
[
"d71eaf9b.e70e8",
"c6a6fdf8.09f01",
"ee67cdba.c347e",
"acb53b1b.0cd358",
"2716b815c1611442"
]
]
},
{
"id": "43567a10.ed7b74",
"type": "mqtt out",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "本周用水量",
"topic": "homeassistant/sensor/esp32s_water/1/config",
"qos": "0",
"retain": "true",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "22b93c622b5df242",
"x": 1350,
"y": 3720,
"wires": []
},
{
"id": "aced1bb.32392e8",
"type": "inject",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "自动发现",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": "1",
"topic": "",
"payload": "{"unit_of_measurement":"m³","device_class":"sensor","unique_id":"water_this_work","state_topic":"esp32s_water/sensor/this_work","name":"本周用水量"}",
"payloadType": "json",
"x": 1040,
"y": 3720,
"wires": [
[
"bf98089f.a7d578"
]
]
},
{
"id": "bf98089f.a7d578",
"type": "rbe",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "",
"func": "rbe",
"gap": "",
"start": "",
"inout": "out",
"property": "payload",
"x": 1190,
"y": 3720,
"wires": [
[
"43567a10.ed7b74"
]
]
},
{
"id": "47f7fb79.b15ecc",
"type": "mqtt out",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "上周用水量",
"topic": "homeassistant/sensor/esp32s_water/2/config",
"qos": "0",
"retain": "true",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "22b93c622b5df242",
"x": 1350,
"y": 3760,
"wires": []
},
{
"id": "87599a40.d5562",
"type": "inject",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "自动发现",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": "1",
"topic": "",
"payload": "{"unit_of_measurement":"m³","device_class":"sensor","unique_id":"water_last_work","state_topic":"esp32s_water/sensor/last_work","name":"上周用水量"}",
"payloadType": "json",
"x": 1040,
"y": 3760,
"wires": [
[
"fada92ab.eacd3"
]
]
},
{
"id": "fada92ab.eacd3",
"type": "rbe",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "",
"func": "rbe",
"gap": "",
"start": "",
"inout": "out",
"property": "payload",
"x": 1190,
"y": 3760,
"wires": [
[
"47f7fb79.b15ecc"
]
]
},
{
"id": "b9588b7a.b9b81",
"type": "mqtt out",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "本月用水量",
"topic": "homeassistant/sensor/esp32s_water/3/config",
"qos": "0",
"retain": "true",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "22b93c622b5df242",
"x": 1350,
"y": 3800,
"wires": []
},
{
"id": "a164a83d.756c78",
"type": "inject",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "自动发现",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": "1",
"topic": "",
"payload": "{"unit_of_measurement":"m³","device_class":"sensor","unique_id":"water_this_month","state_topic":"esp32s_water/sensor/this_month","name":"本月用水量"}",
"payloadType": "json",
"x": 1040,
"y": 3800,
"wires": [
[
"82c7517d.f97f6"
]
]
},
{
"id": "82c7517d.f97f6",
"type": "rbe",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "",
"func": "rbe",
"gap": "",
"start": "",
"inout": "out",
"property": "payload",
"x": 1190,
"y": 3800,
"wires": [
[
"b9588b7a.b9b81"
]
]
},
{
"id": "402fecad.f6d254",
"type": "inject",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "自动发现",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": "1",
"topic": "",
"payload": "{"unit_of_measurement":"m³","device_class":"sensor","unique_id":"water_last_month","state_topic":"esp32s_water/sensor/last_month","name":"上月用水量"}",
"payloadType": "json",
"x": 1040,
"y": 3840,
"wires": [
[
"60a5d683.5d23"
]
]
},
{
"id": "60a5d683.5d23",
"type": "rbe",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "",
"func": "rbe",
"gap": "",
"start": "",
"inout": "out",
"property": "payload",
"x": 1190,
"y": 3840,
"wires": [
[
"fd29d03e.19de5"
]
]
},
{
"id": "fd29d03e.19de5",
"type": "mqtt out",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "上月用水量",
"topic": "homeassistant/sensor/esp32s_water/4/config",
"qos": "0",
"retain": "true",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "22b93c622b5df242",
"x": 1350,
"y": 3840,
"wires": []
},
{
"id": "3a5b1f229d5ac474",
"type": "mysql",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"mydb": "f30e442.46d6a38",
"name": "数据库",
"x": 410,
"y": 3720,
"wires": [
[]
]
},
{
"id": "2716b815c1611442",
"type": "change",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "本年",
"rules": [
{
"t": "move",
"p": "payload[0].d5",
"pt": "msg",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 550,
"y": 3880,
"wires": [
[
"e954b3588272f65a"
]
]
},
{
"id": "e954b3588272f65a",
"type": "function",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "相加",
"func": "//将本月用电量加上今日实时用电量 得出最新的本月用电量\nmsg.payload = Number(msg.payload) + Number(msg.jt);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 3880,
"wires": [
[
"56313c7539e5661a"
]
]
},
{
"id": "56313c7539e5661a",
"type": "mqtt out",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "本年",
"topic": "esp32s_water/sensor/this_year",
"qos": "0",
"retain": "true",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "22b93c622b5df242",
"x": 830,
"y": 3880,
"wires": []
},
{
"id": "fa62e117cc0198c7",
"type": "inject",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "自动发现",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": "1",
"topic": "",
"payload": "{"unit_of_measurement":"m³","device_class":"sensor","unique_id":"water_this_year","state_topic":"esp32s_water/sensor/this_year","name":"本年用水量"}",
"payloadType": "json",
"x": 1040,
"y": 3880,
"wires": [
[
"457b3b8001534312"
]
]
},
{
"id": "457b3b8001534312",
"type": "rbe",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "",
"func": "rbe",
"gap": "",
"start": "",
"inout": "out",
"property": "payload",
"x": 1190,
"y": 3880,
"wires": [
[
"c8177c495fb470d0"
]
]
},
{
"id": "c8177c495fb470d0",
"type": "mqtt out",
"z": "f6f2187d.f17ca8",
"g": "5aabb8329669cca2",
"name": "本年用水量",
"topic": "homeassistant/sensor/esp32s_water/5/config",
"qos": "0",
"retain": "true",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "22b93c622b5df242",
"x": 1350,
"y": 3880,
"wires": []
},
{
"id": "99c664b867ad2e30",
"type": "server",
"name": "omv-homeassistant",
"version": 5,
"addon": false,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true,
"heartbeat": false,
"heartbeatInterval": "30",
"areaSelector": "friendlyName",
"deviceSelector": "friendlyName",
"entitySelector": "friendlyName",
"statusSeparator": "at: ",
"statusYear": "hidden",
"statusMonth": "short",
"statusDay": "numeric",
"statusHourCycle": "h23",
"statusTimeFormat": "h:m",
"enableGlobalContextStore": true
},
{
"id": "22b93c622b5df242",
"type": "mqtt-broker",
"name": "omv-emqx",
"broker": "192.168.2.10",
"port": "1883",
"clientid": "node-red",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"autoUnsubscribe": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
},
{
"id": "f30e442.46d6a38",
"type": "MySQLdatabase",
"name": "",
"host": "192.168.2.10",
"port": "3306",
"db": "esp32s_water",
"tz": "",
"charset": "UTF8"
}
]