国网用电(余额、每日电量与电费)
把网上国网的用电数据接进面板:账户余额、本月电费、每天用了多少电、峰谷平尖各占多少,一屏看完,不用再翻国网 App。数据由你自己的服务器直连国网获取,不经过 BestNav 的服务器。
10 个小节 · 约 7 分钟读完
这张卡能看到什么
绑定一个户号之后,卡片分四个页签:概览、日用电、月账单、账户。它读的是你在网上国网 App 里能看到的同一份数据,只是换了个更顺手的摆法。
- 概览:账户余额、应缴电费、历史欠费,本月电量与电费,以及本月峰 / 谷 / 平 / 尖四段各用了多少
- 日用电:最近约 30 天的每日电量曲线与明细,点任意一根柱子看当天的分时拆分
- 月账单:近 12 个月的电量与电费,点柱子看当月明细
- 账户:户号、账户类型(预付费 / 后付费)、本年累计电量与电费,以及与上月的对比
- 长期曲线:面板会把每天的电量在本机累积,最多 400 天——国网接口本身只回最近约 30 天
它读的是国网公布的数据,不是电表的实时读数。日电量 T+1(今天的数据明天才出),所以这张卡最快也是一天更新一次,看不到“此刻正在用多少瓦”。想看实时功率,得靠智能插座或电表本地采集,那是另一类卡片。
接入:三步,一次就好
前提:你有一个网上国网账号(手机号或邮箱登录),并且能在 App 里看到自己的户号。这里填的是国网账号,不是本站的 admin 账号。
- 第一步 · 配置:在卡片上点「配置国网账号」,填网上国网的手机号或邮箱、密码;有需要可以再填一个备用登录邮箱
- 第二步 · 登录并获取户号:点「登录并获取户号」,登录成功后会把该账号名下的户号列出来
- 第三步 · 选户号保存:选中要展示的户号,保存。之后卡片会自己按间隔取数,不用再管
密码只保存 MD5 摘要(摘要本身再加密存盘),明文不落盘、也不进日志;登录会话同样加密保存在 data 目录。卡片默认显示,未配置时只给配置引导,不会自己尝试登录。
覆盖范围与前提
- 只覆盖国家电网供电的 26 个省份;南方电网 5 省(广东、广西、云南、贵州、海南)不适用
- 一个账号下有多个户号可以随时切换;切换已列出的户号不会重新登录,也不消耗登录次数
- 预付费、后付费账户都支持;部分账单制账户的余额会一直显示 0,这时请以「应缴 / 历史欠费」为准
这张卡是中文界面专属:英文界面下全站不显示它(国网账号只能用国内手机号 / 邮箱登录,留着也是死路)。卡片默认仅管理员可见;管理员在配置里打开「允许成员查看数据」后,成员可以看,但不能改配置、不能触发取数。
什么时候更新:后台自动刷,不是每天零点
面板后台常驻一个检查任务:每 10 分钟看一次,距离上次成功取数已满「刷新间隔」才真正去国网取数。间隔在配置里可选 12 / 24 / 48 小时,默认 24 小时。
所以它不是固定在半夜 12 点刷新,而是按「上次成功 + 间隔」滚动计算。举例:上次成功是 16:26、选了 12 小时,下次取数就在次日 04:26 左右(检查每 10 分钟一次,实际会差几分钟)。卡片上会写「下次自动刷新 xx:xx」。
- 卡片每 5 分钟刷一次显示,但这只是读本机缓存,不会去国网取数
- 两个刷新周期(且不少于 24 小时)都没成功,卡片会提示「数据可能不是最新」
- 取数失败时会写明「当前显示 X 的缓存数据」,旧数据不会被清空
手动点「刷新」也受同一个间隔约束:没到时间只会重读缓存,不会去国网取数。所以别指望靠连点刷新把刚出的数据催出来——国网一天只出一次数,催也催不来。
刷新会消耗登录次数吗
大多数时候不会。面板会把国网登录会话加密持久化:会话还能用就只续令牌,不重新登录;续不上才完整登录一次。
- 只有「登录并获取户号」和「会话失效后的自动重登」会消耗登录次数
- 切换已缓存的户号:不登录
- 国网对登录标识有按天计算的登录额度(RK001,错误码 11401):用完后当天不再尝试,次日自动恢复,换 IP 或重装都没用
- 备用登录邮箱:手机号登录被限时,可以换登记在国网的邮箱再试一次
建议不要反复点「登录并获取户号」测试。配置好之后让它自己按间隔跑就行;只有改密码、换账号才需要重新登录一次。
为什么最近一两天显示 0.0
这通常是国网还没出数,不是没取到。国网日电量名义上 T+1,实际常常 T+2:这两天的行已经出现在返回列表里,但电量字段是空的,面板目前会按 0.0 显示。
- 概览的「最新一日」会自动跳过 0 值,取最后一个真有电量的日子
- 等国网出数后,下一轮刷新会把这两天补上——同一天以最新一次取到的值为准
- 判断方法:去国网 App 看这两天。App 也是 0 或空白,就是还没出;App 有数而面板还是 0,再等一轮刷新
这不是数据丢了,也不是刷新坏了:状态里会写清上次成功取数的时间,可以对照。
长期曲线是怎么来的
国网的日电量接口只回最近约 30 天,它自己不提供长历史。面板每取一轮,就把这一轮的日点并进本机累积序列,逐日留存,最多 400 天——用得越久,曲线越长。
累积数据存在 data 目录里。清空数据、或卸载时选择删除数据就会丢,重装后从头累积;迁移服务器时把整个 data 目录带走即可。
数据与隐私
- 账号、加密后的密码摘要、登录会话,全部只存在你这台服务器的 data 目录
- 取数请求由你的服务器直接发往国网,不经过 BestNav 的任何服务器,也没有第三方统计
- 默认仅管理员可见;打开「允许成员查看数据」后,成员只能看,不能改配置、不能刷新取数
- 每次手动刷新都会记一条操作日志:谁、什么时候、哪个户号;后台自动刷新不产生日志
国网密码明文不会保存,也不进日志。改密码时重新填写一次即可覆盖,留空表示保留已存的那一份。
风险与免责
这张卡走的是非官方通道。下面五条不是免责套话,而是配置后真会遇到的后果,请在填账号前看完。
- 与国网无隶属、合作或授权关系:接口来自网上国网对外服务,不是公开 API,可能随时变更、限流或关闭,我们不承诺它一直可用
- 可能违反网上国网的平台规则:自动化登录与取数不在其用户协议允许的范围内,账号存在被限制登录的风险。请只绑定本人名下账号,不要代他人取数
- 数据仅供参考:日电量通常 T+1、有时 T+2;余额、应缴与欠费可能为 0 或滞后。缴费、欠费与停复电请以网上国网 App、供电营业厅或国网官方渠道为准,本卡片不能作为依据
- 凭据不进备份:账号、加密密码摘要、会话令牌与户号只存在本机 data 目录,且不纳入内置备份(本地 JSON 备份、整站 zip 备份与 WebDAV 备份都不含)。换机恢复后需重新配置一次——这是刻意的,备份文件一旦外流,等于把国网的登录能力一起带走
- 成员可见需你确认:开启「允许成员查看」后,同一实例的其他账号能看到户号、余额与用电数据;不确定成员范围就保持默认关闭
如收到权利方通知,或我们认为存在合规风险,可随时移除该功能。停止使用只需在卡片上「删除配置」,本机不再保留任何国网凭据与用电数据。
常见问题
- 「账号或密码错误」:这里要填网上国网的手机号 / 邮箱和密码,不是本站管理员账号;先确认 App 能正常登录
- 「今日登录次数已用完,明日恢复」:触发了国网的日登录额度,当天别再试,第二天自动恢复
- 「刚刚连续失败,已暂停请求」:连续失败后的自动退避,从 30 分钟起逐次翻倍、最长 12 小时,到点自动重试
- 「所选户号已失效」:户号被解绑或更换了,重新「登录并获取户号」再选一个
- 换模板后找不到这张卡:经典视图、控制台、桌面视图支持;杂志流没有这张卡
- 卡片是灰的、或只有配置引导:还没配置账号,或当前登录的不是管理员
- 要不要钱:免费功能,不占 Pro 名额
What this card shows
Once an account number is bound, the card has four tabs: Overview, Daily, Monthly bills and Account. It shows the same data you see in the official 网上国网 app, arranged for a dashboard.
- Overview: balance, amount due, arrears, this month’s kWh and bill, plus how that power splits across sharp / peak / flat / valley periods
- Daily: the last ~30 days of usage as a chart and a list; click any bar for that day’s split
- Monthly bills: the last 12 months of kWh and cost; click a bar for that month’s detail
- Account: account number, account type (prepaid / postpaid), year-to-date kWh and cost, and last month for comparison
- Long-term curve: the panel accumulates each day locally, up to 400 days — the State Grid API itself returns only about 30 days
This reads State Grid’s published data, not a live meter. Daily usage is T+1 (today’s number appears tomorrow), so the card updates at most once a day and cannot show “watts right now”. Real-time power needs a smart plug or a local meter reader — a different kind of card.
Setup: three steps, once
Prerequisite: a 网上国网 account (phone or email login) that can already see your account number in the app. This is your State Grid account, not your BestNav admin login.
- Step 1 · Configure: on the card, click “Configure State Grid account” and enter the 网上国网 phone number or email plus the password; optionally add a backup login email
- Step 2 · Sign in and fetch account numbers: click the sign-in button; on success the account numbers under this login are listed
- Step 3 · Pick and save: select the account number to display and save. From then on the card refreshes on its own
The password is stored only as an MD5 digest (the digest itself encrypted on disk); the plaintext is never written and never logged. The login session is encrypted too, under the data directory. The card is shown by default; before configuration it only offers the setup prompt and never signs in on its own.
Coverage and prerequisites
- Covers the 26 provinces served by State Grid; the five China Southern Grid provinces (Guangdong, Guangxi, Yunnan, Guizhou, Hainan) are not supported
- Several account numbers under one login can be switched at any time; switching does not sign in again and does not consume a login
- Prepaid and postpaid accounts are both supported; some bill-based accounts always report a zero balance — read “amount due / arrears” instead
This card exists in the Chinese UI only; it is hidden across the site in English, because a State Grid account can only be opened with a mainland phone number or email. It is admin-only by default; turn on “Allow members to view” and members can read it (they still cannot edit config or trigger a fetch).
When it updates: in the background, not at midnight
A background task checks every 10 minutes and fetches from State Grid only once the configured refresh interval has elapsed since the last success. The interval is 12 / 24 / 48 hours; the default is 24.
So it does not refresh at midnight — it rolls forward from the last success. Example: last success at 16:26 with a 12-hour interval means the next fetch around 04:26 the following day (the 10-minute check adds a few minutes of jitter). The card shows the next auto refresh time.
- The card re-reads the local cache every 5 minutes; that never triggers an upstream fetch
- If two intervals (and at least 24 hours) pass without a success, the card warns that the data may be stale
- On failure the card says it is showing the cached data of a given date — old data is never wiped
The manual Refresh button obeys the same interval: before it elapses you only re-read the cache. Clicking repeatedly will not coax out a number State Grid has not published yet.
Does refreshing use up a login?
Usually not. The State Grid session is persisted encrypted: while it is still valid the panel only renews the token; only when that fails does it perform a full sign-in.
- Only “sign in and fetch account numbers” and an automatic re-login after session expiry consume a login
- Switching between already-listed account numbers: no login
- State Grid limits logins per login identifier per day (RK001, error 11401). Once exhausted, no more attempts that day — it recovers the next day; changing IP or reinstalling does not help
- Backup login email: when a phone-number login is rate-limited, try the email registered with State Grid
Avoid repeatedly clicking the sign-in button to test. Once configured, let the interval do its job; you only need to sign in again after changing the password or the account.
Why the last day or two shows 0.0
Usually State Grid has not published that day yet. Daily usage is nominally T+1 but often T+2 in practice: the row is already in the response while the kWh field is empty, and the panel currently renders that as 0.0.
- The Overview “latest day” skips zero values and uses the last day that actually has usage
- Once State Grid publishes, the next refresh fills those days in — the latest fetch always wins for the same date
- How to tell: check the State Grid app. If the app is also 0 or blank, the data is not out yet; if the app has a number and the panel still shows 0, wait for the next refresh cycle
No data is lost and nothing is broken: the status view records when the last successful fetch happened, so you can compare.
Where the long-term curve comes from
The State Grid daily API returns only about 30 days and offers no long history. On every fetch the panel merges that round’s points into a local series, day by day, up to 400 days — the longer you run it, the longer the curve.
The series lives under the data directory. Wiping data, or choosing to delete data on uninstall, loses it and accumulation starts over; when migrating servers, take the whole data directory with you.
Data and privacy
- The account, the encrypted password digest and the login session live only in your server’s data directory
- Fetches go from your server straight to State Grid — never through any BestNav server, and there is no third-party analytics
- Admin-only by default; with “Allow members to view” members can read but cannot change config or trigger refreshes
- Manual refreshes write an audit entry: who, when, and which account number; background refreshes do not
The plaintext password is never stored or logged. To change it, fill it in again; leaving the field blank keeps the saved one.
Risks & Disclaimer
This card uses an unofficial channel. The five points below are not boilerplate — they are what you will actually run into after setup, so please read them before entering an account.
- No affiliation, partnership or authorisation with State Grid: the interface is part of the 网上国网 service rather than a public API. It may change, throttle or shut down at any time, and we make no promise that it keeps working
- It may breach the 网上国网 platform rules: automated sign-in and data fetching are outside what its user agreement allows, and the account may be restricted. Bind only accounts in your own name and never fetch on someone else’s behalf
- For reference only: daily usage is usually T+1, sometimes T+2; balance, amount due and arrears may be zero or stale. For payment, arrears and supply decisions always rely on the 网上国网 app, a supply business hall or official State Grid channels — this card cannot be used as a basis
- Credentials stay out of backups: the account, encrypted password digest, session token and meter numbers live only in the local data directory and are excluded from the built-in backups (local JSON backup, full-site zip backup and WebDAV backup). After migrating to another machine you must configure it again — deliberately so, because a leaked backup would otherwise carry the ability to sign in for you
- Member visibility is your call: with “Allow members to view” enabled, other accounts on the same instance can see meter numbers, balance and usage data; keep it off unless you are sure who the members are
We may remove the feature at any time upon notice from a rights holder or where we see compliance risk. To stop using it, delete the configuration on the card; no State Grid credentials or usage data remain on your machine afterwards.
FAQ
- “Wrong account or password”: enter the 网上国网 phone / email and password, not your BestNav admin login; confirm the app can sign in first
- “Daily login limit reached, back tomorrow”: State Grid’s daily login quota is exhausted — stop trying today, it resets tomorrow
- “Paused after repeated failures”: automatic backoff starting at 30 minutes and doubling up to 12 hours, then it retries
- “Selected account number is invalid”: it was unbound or changed — sign in again and pick one
- Cannot find the card after switching templates: Classic, Console and Desktop include it; Magazine does not
- Card is greyed out or only shows a setup prompt: not configured yet, or you are not signed in as admin
- Does it cost anything: it is free and does not use a Pro seat