找回密码
 立即注册
楼主: brook77

[经验分享] 我也分享个我的电费插件

[复制链接]
lhy6 手机认证

0

主题

9

回帖

71

积分

注册会员

积分
71
金钱
62
HASS币
0
发表于 2024-12-29 20:30:51 | 显示全部楼层
brook77 发表于 2024-12-26 14:54
https://github.com/ARC-MX/sgcc_electricity_new ,
可以使用仓库,有完整的教程。我是把这个仓库拉数据的 ...

大佬新手看不懂,可否出详细教程
回复

使用道具 举报

4

主题

129

回帖

850

积分

高级会员

积分
850
金钱
717
HASS币
0
发表于 2024-12-30 14:22:13 | 显示全部楼层
brook77 发表于 2024-12-28 10:41
我是把电费插件修改后直接写入mysql数据库的,所以安装在哪里没啥影响 ...

nodered流可以分享吗
回复

使用道具 举报

5

主题

48

回帖

392

积分

中级会员

积分
392
金钱
339
HASS币
0
发表于 2024-12-31 13:55:58 | 显示全部楼层
不太想放到mysql 虽然便利 感觉额外启动一个程序会消耗内存
回复

使用道具 举报

22

主题

124

回帖

982

积分

高级会员

积分
982
金钱
836
HASS币
0
发表于 2024-12-31 15:53:00 | 显示全部楼层
我是通过pyscript post到后台,如重启,就从后天读取
回复

使用道具 举报

0

主题

9

回帖

142

积分

注册会员

积分
142
金钱
133
HASS币
0
发表于 2024-12-31 17:22:16 | 显示全部楼层
大佬可以给个修改后的代码和教程嘛,我也是想写到外部MySQL数据库里
回复

使用道具 举报

1

主题

44

回帖

1272

积分

金牌会员

积分
1272
金钱
1227
HASS币
0
发表于 2025-1-1 14:45:31 | 显示全部楼层
青龙面板定时抓取国家电网页面数据,登录token不会超时?
回复

使用道具 举报

0

主题

16

回帖

208

积分

中级会员

积分
208
金钱
192
HASS币
0
发表于 2025-1-1 16:24:34 | 显示全部楼层
求个教程
回复

使用道具 举报

2

主题

51

回帖

413

积分

中级会员

积分
413
金钱
360
HASS币
0
 楼主| 发表于 2025-1-1 16:55:15 | 显示全部楼层
霸都智能小白 发表于 2025-1-1 14:45
青龙面板定时抓取国家电网页面数据,登录token不会超时?

每次抓取都是用账号登陆,不用token
回复

使用道具 举报

2

主题

51

回帖

413

积分

中级会员

积分
413
金钱
360
HASS币
0
 楼主| 发表于 2025-1-1 17:06:19 | 显示全部楼层
snowing 发表于 2024-12-30 14:22
nodered流可以分享吗
[
    {
        "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": ""
    }
]
回复

使用道具 举报

2

主题

51

回帖

413

积分

中级会员

积分
413
金钱
360
HASS币
0
 楼主| 发表于 2025-1-1 17:08:12 | 显示全部楼层
wzx123 发表于 2024-12-31 13:55
不太想放到mysql 虽然便利 感觉额外启动一个程序会消耗内存

数据获取到,放哪这个看自己,怎么方便怎么来
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2025-5-5 01:28 , Processed in 0.072062 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表