共计 3758 个字符,预计需要花费 10 分钟才能阅读完成。
前言
之前用的大佬的 docker 也是模拟操作去获取余额元素然后生成 ha 的实体,获取电网时添加了滑动验证码,原作者不再继续维护,现有千石酱大佬制作的 docker,特此感谢千石酱分享,经过我做了延时的优化,目前已稳定运行 2 个月,此次部署还是以群晖为例,使用此教程前首先部署 nodered(百度一大堆,不再重复撰写),通过 nodered get 控制容器任务运行,抓取余额数值生成实体
docker 镜像
okatuloli-electricity-tr...ker(v0-0-1).syno.tar
https://www.alipan.com/s/vcEsWQuqE4e 提取码: y21t
安装部署
1. 导入镜像
1) 首先有一台可以运行 docker 的机器
2) 导入以上的 docker 镜像,群晖可通过 docker – 映像 – 新增 – 从文件添加
3) 导入成功后完成第一步
2. 部署 docker
1) 首先在 docker 文件夹创建一个映射文件夹,起名 electricity,electricity 文件夹内创建文件夹 debug,用于测试截图放入,把以下文件复制到文件夹内
Electricity-Tracker-master.zip https://www.alipan.com/s/CUeEvG5274e 提取码: mw88
2) 放入后,编辑 config.ini 文件,username/password 账号密码填写自己的,保存即可
3) 以群晖为例,导入的镜像双击进行部署
存储空间映射本地文件夹,以下为例
容器端口 5000,自己对应端口一个即可,默认 5000 也可以,不要跟群晖或其他服务冲突
4) 部署完毕后运行 docker
使用方法
1. 强制更新电费(get 请求):
http://IP: 端口 /getelectricity
2. 获取最新电费(post 请求):
http://IP: 端口 /electricity
nodered
通过接口 2 获取到电费信息,自己送到 ha 也可以,这个不局限于 nodered,以上是 nodered 流程图很简单
json 自行替换局域网请求地址
nodered 流
[
{
"id": "38779186405936d7",
"type": "tab",
"label": "电费",
"disabled": false,
"info": "",
"env": []
},
{
"id": "38ef0eaf5cb549ca",
"type": "inject",
"z": "38779186405936d7",
"name": "获取金额传送 ha",
"props": [],
"repeat": "",
"crontab":"30 12 * * *",
"once": false,
"onceDelay": 0.1,
"topic":"",
"x": 330,
"y": 320,
"wires": [
[
"7d0f63506e84a788"
]
]
},
{
"id": "7d0f63506e84a788",
"type": "http request",
"z": "38779186405936d7",
"name": "",
"method":"GET",
"ret":"txt",
"paytoqs":"ignore",
"url":"http://10.0.0.101:5000/electricity",
"tls":"",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType":"",
"senderr": false,
"headers": [],
"x": 500,
"y": 320,
"wires": [
[
"ed8f9e6df1266058"
]
]
},
{
"id": "ed8f9e6df1266058",
"type": "json",
"z": "38779186405936d7",
"name": "",
"property":"payload",
"action":"",
"pretty": false,
"x": 690,
"y": 320,
"wires": [
[
"9ec9700618b91aef",
"96790ef81083e8e2"
]
]
},
{
"id": "9ec9700618b91aef",
"type": "debug",
"z": "38779186405936d7",
"name": "debug 1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload.data.expense",
"targetType": "msg",
"statusVal": "",
"statusType":"auto",
"x": 920,
"y": 240,
"wires": []
},
{
"id": "96790ef81083e8e2",
"type": "ha-sensor",
"z": "38779186405936d7",
"name": "输出电费",
"entityConfig": "493ba168cb0b5e6f",
"version": 0,
"state": "payload.data.expense",
"stateType": "msg",
"attributes": [
{
"property": "consBal",
"value": "payload.data.expense",
"valueType": "msg"
}
],
"inputOverride": "allow",
"outputProperties": [],
"x": 920,
"y": 420,
"wires": [
[]
]
},
{
"id": "fb93ce1b71aab09d",
"type": "inject",
"z": "38779186405936d7",
"name": "强制更新电费",
"props": [],
"repeat": "",
"crontab":"00 12 * * *",
"once": false,
"onceDelay": 0.1,
"topic":"",
"x": 320,
"y": 180,
"wires": [
[
"6bbefa8981ab9026"
]
]
},
{
"id": "6bbefa8981ab9026",
"type": "http request",
"z": "38779186405936d7",
"name": "",
"method":"POST",
"ret":"txt",
"paytoqs":"ignore",
"url":"http://10.0.0.101:5000/getelectricity",
"tls":"",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType":"",
"senderr": false,
"headers": [],
"x": 500,
"y": 180,
"wires": [
[]
]
},
{
"id": "493ba168cb0b5e6f",
"type": "ha-entity-config",
"server": "4195dd0343dfc562",
"deviceConfig": "",
"name":" 电费 ",
"version":"6",
"entityType":"sensor",
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
},
{
"property": "entity_category",
"value": ""
},
{
"property": "entity_picture",
"value": ""
},
{
"property": "device_class",
"value": ""
},
{
"property": "unit_of_measurement",
"value": ""
},
{
"property": "state_class",
"value": ""
}
],
"resend": false,
"debugEnabled": false
},
{
"id": "4195dd0343dfc562",
"type": "server",
"name": "Home Assistant",
"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
}
]
常见问题
待完善~