[
{
"id": "02469b19359eb84f",
"type": "group",
"z": "a4dd53e3fe1911dd",
"name": "电费",
"style": {
"fill": "#d1d1d1",
"label": true,
"color": "#0070c0"
},
"nodes": [
"ee06c91d0fdcd560",
"702b223a29af86dd",
"c1f0837366025677",
"b9d87d67363a1712",
"808694f131f203a4",
"b7a605265476dea6",
"eccd7a1dbf034e94",
"5669c234e7577489",
"e964783cfa335a49",
"9bee2ef1f140a1c7",
"5bd3c872d9b6e32b",
"7ad1753652776116",
"6ac7f45ac488d196",
"6c5f508b90b8a1f7"
],
"x": 14,
"y": 579,
"w": 1352,
"h": 182
},
{
"id": "cc38778ee88158f4",
"type": "subflow",
"name": "hass ready",
"info": "",
"category": "",
"in": [],
"out": [
{
"x": 780,
"y": 280,
"wires": [
{
"id": "dc59cc0ed54aa815",
"port": 0
}
]
}
],
"env": [],
"meta": {},
"color": "#DDAA99",
"status": {
"x": 580,
"y": 400,
"wires": [
{
"id": "d6d7bcf9dc411f85",
"port": 0
}
]
}
},
{
"id": "dc59cc0ed54aa815",
"type": "switch",
"z": "cc38778ee88158f4",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "ready",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 670,
"y": 280,
"wires": [
[]
]
},
{
"id": "d6d7bcf9dc411f85",
"type": "server-events",
"z": "cc38778ee88158f4",
"name": "home_assistant_client",
"server": "27853294c2453a0f",
"version": 3,
"exposeAsEntityConfig": "",
"eventType": "home_assistant_client",
"eventData": "",
"waitForRunning": true,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
},
{
"property": "topic",
"propertyType": "msg",
"value": "$outputData("eventData").event_type",
"valueType": "jsonata"
}
],
"x": 360,
"y": 280,
"wires": [
[
"dc59cc0ed54aa815"
]
]
},
{
"id": "27853294c2453a0f",
"type": "server",
"name": "Home Assistant",
"version": 5,
"addon": false,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true,
"heartbeat": true,
"heartbeatInterval": "300",
"areaSelector": "friendlyName",
"deviceSelector": "friendlyName",
"entitySelector": "friendlyName",
"statusSeparator": ": ",
"statusYear": "2-digit",
"statusMonth": "2-digit",
"statusDay": "2-digit",
"statusHourCycle": "default",
"statusTimeFormat": "h:m",
"enableGlobalContextStore": false
},
{
"id": "ee06c91d0fdcd560",
"type": "inject",
"z": "a4dd53e3fe1911dd",
"g": "02469b19359eb84f",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "7200",
"crontab": "",
"once": true,
"onceDelay": "10",
"topic": "",
"payload": "",
"payloadType": "date",
"x": 120,
"y": 620,
"wires": [
[
"7ad1753652776116"
]
]
},
{
"id": "702b223a29af86dd",
"type": "subflow:cc38778ee88158f4",
"z": "a4dd53e3fe1911dd",
"g": "02469b19359eb84f",
"name": "",
"x": 100,
"y": 700,
"wires": [
[
"7ad1753652776116"
]
]
},
{
"id": "c1f0837366025677",
"type": "mysql",
"z": "a4dd53e3fe1911dd",
"g": "02469b19359eb84f",
"mydb": "3db048564ffcee62",
"name": "sgcc",
"x": 390,
"y": 660,
"wires": [
[
"6ac7f45ac488d196",
"6c5f508b90b8a1f7"
]
]
},
{
"id": "b9d87d67363a1712",
"type": "mysql",
"z": "a4dd53e3fe1911dd",
"g": "02469b19359eb84f",
"mydb": "3db048564ffcee62",
"name": "sgcc",
"x": 650,
"y": 620,
"wires": [
[
"eccd7a1dbf034e94"
]
]
},
{
"id": "808694f131f203a4",
"type": "debug",
"z": "a4dd53e3fe1911dd",
"g": "02469b19359eb84f",
"name": "debug 57",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1260,
"y": 720,
"wires": []
},
{
"id": "b7a605265476dea6",
"type": "mysql",
"z": "a4dd53e3fe1911dd",
"g": "02469b19359eb84f",
"mydb": "3db048564ffcee62",
"name": "sgcc",
"x": 650,
"y": 700,
"wires": [
[
"5669c234e7577489"
]
]
},
{
"id": "eccd7a1dbf034e94",
"type": "function",
"z": "a4dd53e3fe1911dd",
"g": "02469b19359eb84f",
"name": "function 40",
"func": "\nlet month_usage = 0\nlet month_usage_gu = 0\nlet month_usage_feng = 0\n\n//每天用电量\nconst daily = msg.payload\nconst year = daily[0]["date"].split('-')[0]\nconst month = daily[0]["date"].split('-')[1]\ndaily.forEach((d,i)=>{\n if(d['date'].startsWith(year+"-"+month))\n {\n month_usage = month_usage + d['usage'] * 100\n month_usage_feng = month_usage_feng + d["feng"]*100\n month_usage_gu = month_usage_gu + d['gu']*100\n }\n})\n\n\nmsg.payload = { \n daily_list : daily ,\n month_usage: Math.round(month_usage / 100),\n month_usage_feng: month_usage_feng/100,\n month_usage_gu : month_usage_gu/100,\n updateAt :daily[0]["date"]\n }\ndelete msg.topic\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 790,
"y": 620,
"wires": [
[
"e964783cfa335a49"
]
]
},
{
"id": "5669c234e7577489",
"type": "function",
"z": "a4dd53e3fe1911dd",
"g": "02469b19359eb84f",
"name": "function 41",
"func": "let year_usage = 0\nlet year_charge = 0.0\nlet month_list = []\nconst month_data = msg.payload\nmonth_data.forEach((d)=>{\n const usage = d["usage"]*100\n const charge = d["charge"]*100\n year_usage = year_usage + usage\n year_charge = year_charge + charge\n month_list.push({\n "date" : d['date'].substring(0,7),\n "usage": usage/100,\n "charge": charge/100\n })\n})\nmsg.payload = {\n year_usage : year_usage/100,\n year_charge : year_charge/100,\n month_list : month_list\n} \ndelete msg.topic\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "// 部署节点后,此处添加的代码将运行一次。 \n\nfunction accAdd(arg1, arg2) {\n var r1, r2, m;\n try {\n r1 = arg1.toString().split('.')[1].length;\n } catch (e) {\n r1 = 0;\n }\n try {\n r2 = arg2.toString().split('.')[1].length;\n } catch (e) {\n r2 = 0;\n }\n m = Math.pow(10, Math.max(r1, r2));\n return (arg1 * m + arg2 * m) / m;\n}\n\n//给Number类型增加一个add方法,调用起来更加方便。\nNumber.prototype.add = function (arg) {\n return accAdd(arg, this);\n}\n",
"finalize": "",
"libs": [],
"x": 790,
"y": 700,
"wires": [
[
"e964783cfa335a49"
]
]
},
{
"id": "e964783cfa335a49",
"type": "join",
"z": "a4dd53e3fe1911dd",
"g": "02469b19359eb84f",
"name": "结果",
"mode": "custom",
"build": "merged",
"property": "payload",
"propertyType": "msg",
"key": "payload",
"joiner": "\\n",
"joinerType": "str",
"useparts": false,
"accumulate": false,
"timeout": "",
"count": "8",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "num",
"reduceFixup": "",
"x": 950,
"y": 660,
"wires": [
[
"9bee2ef1f140a1c7"
]
]
},
{
"id": "9bee2ef1f140a1c7",
"type": "function",
"z": "a4dd53e3fe1911dd",
"g": "02469b19359eb84f",
"name": "function 42",
"func": "//电费计算 [0,2700,4800]\nconst charge_feng = [0,0.5680, 0.6180, 0.8680]\nconst charge_gu = [0,0.2880, 0.3380, 0.5880]\n\nlet year_usage = msg.payload.year_usage\nlet year_charge = msg.payload.year_charge\nconst month_usage = msg.payload.month_usage\nconst month_usage_gu = msg.payload.month_usage_gu\nconst month_usage_feng = msg.payload.month_usage_feng\n\nlet charge_index = 1\nlet jieti_s = 2700 - year_usage\nif(year_usage > 4800) {\n charge_index = 3\n jieti_s = '∞'\n}\nelse if(year_usage > 2700) {\n charge_index = 2\n jieti_s = 4800 - year_usage\n}\n\nconst month_charge_feng = month_usage_feng * charge_feng[charge_index]\nconst month_charge_gu = month_usage_gu * charge_gu[charge_index]\nconst month_charge = month_charge_feng + month_charge_gu\n\nmsg.payload.month_charge_feng = Math.round(month_charge_feng * 100) / 100\nmsg.payload.month_charge_gu = Math.round(month_charge_gu * 100) / 100\nmsg.payload.month_charge = Math.round(month_charge * 100) / 100\nmsg.payload.jieti = charge_index\nmsg.payload.jieti_s = jieti_s\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "// 部署节点后,此处添加的代码将运行一次。 \n\nfunction accAdd(arg1, arg2) {\n var r1, r2, m;\n try {\n r1 = arg1.toString().split('.')[1].length;\n } catch (e) {\n r1 = 0;\n }\n try {\n r2 = arg2.toString().split('.')[1].length;\n } catch (e) {\n r2 = 0;\n }\n m = Math.pow(10, Math.max(r1, r2));\n return (arg1 * m + arg2 * m) / m;\n}\n\nfunction accSub(arg1, arg2) {\n var r1, r2, m, n;\n try {\n r1 = arg1.toString().split('.')[1].length;\n } catch (e) {\n r1 = 0;\n }\n try {\n r2 = arg2.toString().split('.')[1].length;\n } catch (e) {\n r2 = 0;\n }\n m = Math.pow(10, Math.max(r1, r2));\n //动态控制精度长度\n n = (r1 >= r2) ? r1 : r2;\n return ((arg1 * m - arg2 * m) / m).toFixed(n);\n}\nfunction accMul(arg1, arg2) {\n var m = 0,\n s1 = arg1.toString(),\n s2 = arg2.toString();\n try {\n m += s1.split('.')[1].length;\n } catch (e) { }\n try {\n m += s2.split('.')[1].length;\n } catch (e) { }\n return (Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) / Math.pow(10, m);\n}\n\nfunction accDiv(arg1, arg2) {\n var t1 = 0,\n t2 = 0,\n r1,\n r2;\n try {\n t1 = arg1.toString().split('.')[1].length;\n } catch (e) { }\n try {\n t2 = arg2.toString().split('.')[1].length;\n } catch (e) { }\n r1 = Number(arg1.toString().replace('.', ''));\n r2 = Number(arg2.toString().replace('.', ''));\n return (r1 / r2) * Math.pow(10, t2 - t1);\n}\n\n//给Number类型增加一个add方法,调用起来更加方便。\nNumber.prototype.add = function (arg) {\n return accAdd(arg, this);\n}\nNumber.prototype.sub = function (arg) {\n return accSub(arg, this);\n}\nNumber.prototype.mul = function (arg) {\n return accMul(arg, this);\n}\nNumber.prototype.div = function (arg) {\n return accDiv(arg, this);\n}",
"finalize": "",
"libs": [],
"x": 1090,
"y": 660,
"wires": [
[
"808694f131f203a4",
"5bd3c872d9b6e32b"
]
]
},
{
"id": "5bd3c872d9b6e32b",
"type": "ha-sensor",
"z": "a4dd53e3fe1911dd",
"g": "02469b19359eb84f",
"name": "统计",
"entityConfig": "3e404bf852074428",
"version": 0,
"state": "payload.daily_list[0].usage",
"stateType": "msg",
"attributes": [
{
"property": "month_charge",
"value": "payload.month_charge",
"valueType": "msg"
},
{
"property": "month_usage",
"value": "payload.month_usage",
"valueType": "msg"
},
{
"property": "year_charge",
"value": "payload.year_charge",
"valueType": "msg"
},
{
"property": "year_usage",
"value": "payload.year_usage",
"valueType": "msg"
},
{
"property": "daily_list",
"value": "payload.daily_list",
"valueType": "msg"
},
{
"property": "month_list",
"value": "payload.month_list",
"valueType": "msg"
},
{
"property": "month_usage_feng",
"value": "payload.month_usage_feng",
"valueType": "msg"
},
{
"property": "month_usage_gu",
"value": "payload.month_usage_gu",
"valueType": "msg"
},
{
"property": "jieti",
"value": "payload.jieti",
"valueType": "msg"
},
{
"property": "updateAt",
"value": "payload.updateAt",
"valueType": "msg"
},
{
"property": "jieti_s",
"value": "payload.jieti_s",
"valueType": "msg"
}
],
"inputOverride": "allow",
"outputProperties": [],
"x": 1250,
"y": 660,
"wires": [
[
"808694f131f203a4"
]
]
},
{
"id": "7ad1753652776116",
"type": "change",
"z": "a4dd53e3fe1911dd",
"g": "02469b19359eb84f",
"name": "topic",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "SELECT DISTINCT userid FROM daily;",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 270,
"y": 660,
"wires": [
[
"c1f0837366025677"
]
]
},
{
"id": "6ac7f45ac488d196",
"type": "change",
"z": "a4dd53e3fe1911dd",
"g": "02469b19359eb84f",
"name": "daily",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "$join(\t [\t "SELECT * FROM daily WHERE userid=",\t msg.payload[0].userid,\t " ORDER BY DATE DESC LIMIT 60"\t ]\t)",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 530,
"y": 620,
"wires": [
[
"b9d87d67363a1712"
]
]
},
{
"id": "6c5f508b90b8a1f7",
"type": "change",
"z": "a4dd53e3fe1911dd",
"g": "02469b19359eb84f",
"name": "month",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "$join(\t [\t "SELECT * FROM month WHERE userid=",\t msg.payload[0].userid,\t " ORDER BY DATE DESC LIMIT 12"\t ]\t)\t",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 530,
"y": 700,
"wires": [
[
"b7a605265476dea6"
]
]
},
{
"id": "3db048564ffcee62",
"type": "MySQLdatabase",
"name": "sgcc",
"host": "192.168.110.45",
"port": "3306",
"db": "sgcc",
"tz": "",
"charset": "UTF8"
},
{
"id": "3e404bf852074428",
"type": "ha-entity-config",
"server": "27853294c2453a0f",
"deviceConfig": "b09e51bbc20d375a",
"name": "电费",
"version": "6",
"entityType": "sensor",
"haConfig": [
{
"property": "name",
"value": "电费"
},
{
"property": "icon",
"value": ""
},
{
"property": "entity_picture",
"value": ""
},
{
"property": "entity_category",
"value": ""
},
{
"property": "device_class",
"value": "energy"
},
{
"property": "unit_of_measurement",
"value": "kWh"
},
{
"property": "state_class",
"value": "total"
},
{
"property": "last_reset",
"value": "2024-11-22T17:17:00.000Z"
}
],
"resend": false,
"debugEnabled": true
},
{
"id": "b09e51bbc20d375a",
"type": "ha-device-config",
"name": "电费",
"hwVersion": "",
"manufacturer": "Node-RED",
"model": "",
"swVersion": ""
}
]