Giter Club home page Giter Club logo

bj_sgcc_energy's Introduction

北京用电信息查询

hacs_badge Stable

通过“国网北京电力”微信公众号的接口,采集你的家庭用电信息。

使用之前

首先关注“国网北京电力”微信公众号,打开微营业厅->个人中心->户号关联,确保你至少已关联一个北京国网电力的户号。如果没有关联,在此进行户号关联操作。此时点开微营业厅,应已经可以看到关联的用户,点击用户,可以看到该用户的用电信息。

使用任何网络抓包软件,如安卓手机的Fiddler, 苹果手机的Stream,进行抓包,过滤条件可以选择"HTTP"。抓包时在微营业厅上进行操作,查看一下用电信息。看到HTTP HEADER中有内容为“user_openid=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”的内容,将user_openid=后的内容复制下来,如果最后是以\r\n结尾,则去掉\r\n,如果后部包含等于号"=",保留等于号。这个字符串就是openid,保存备用。

screenshot

安装

使用HACS以自定义存储库方式安装,或者从Latest release下载最新的Release版本,将其中的custom_components/bj_sgcc_engergy放到你的Home Assistant的custom_components/bj_sgcc_engergy中。

配置

通过UI配置,在集成-北京用电信息查询中,输入openid,然后选择户号即可。

config1

config2

特性

  • 支持多用户用电信息的采集。
  • 支持实时用电单价实体,可用于Home Assistant 2021.8.X最新的能源模块的实时电费计算。
  • 数据为定时更新,更新间隔为10分钟。
  • 支持北京市居民的阶梯用电计价策略
  • 支持北京市非居民的峰平谷用电计价策略(Beta)

传感器

包含的传感器

entity_id形式 含义 属性 备注
sensor.XXXXXXXXXX_balance 电费余额 last_update - 网端数据更新时间
sensor.XXXXXXXXXX_current_level 当前用电阶梯(峰平谷用户无此项)
sensor.XXXXXXXXXX_current_level_consume 当前阶梯用电(峰平谷用户无此项)
sensor.XXXXXXXXXX_current_level_remain 当前阶梯剩余额度(峰平谷用户无此项)
sensor.XXXXXXXXXX_current_pgv_type 当前电价类别(阶梯用户无此项) 可能的值:峰、平、谷、尖峰(?)
sensor.XXXXXXXXXX_current_price 当前电价
sensor.XXXXXXXXXX_year_consume 本年度用电量
sensor.XXXXXXXXXX_year_consume_bill 本年度电费
sensor.XXXXXXXXXX_history_* 过去12个月用电 name - 月份
consume_bill - 该月电费
*取值为1-12
sensor.XXXXXXXXXX_daily_* 过去30天用电 name - 日期
bill_time - 采集时间
day_consume1 - 平时用电
day_consume2 - 尖时用电?
day_consume3 - 峰时用电?
day_consume4 - 谷时用电?
*取值为1-30

其中XXXXXXXXXX为北京国电用户户号

示例

历史数据采用flex-table-card展示

type: vertical-stack
cards:
  - type: entities
    entities:
      - entity: sensor.XXXXXXXXXX_balance
      - entity: sensor.XXXXXXXXXX_current_level
      - entity: sensor.XXXXXXXXXX_current_level_consume
      - entity: sensor.XXXXXXXXXX_current_level_remain
      - entity: sensor.XXXXXXXXXX_current_price
      - entity: sensor.XXXXXXXXXX_year_consume
      - entity: sensor.XXXXXXXXXX_year_consume_bill
    title: 家1
  - type: custom:flex-table-card
    title: 过去12个月用电情况
    entities:
      include: sensor.XXXXXXXXXX_history_*
    columns:
      - name: 月份
        data: name
      - name: 用电量
        data: state
      - name: 电费
        data: consume_bill
  - type: custom:flex-table-card
    title: 过去30天用电情况
    entities:
      include: sensor.XXXXXXXXXX_daily_*
    columns:
      - name: 日期
        data: name
      - name: 用电量
        data: state
      - name: 尖时用电
        data: day_consume2
      - name: 峰时用电
        data: day_consume3
      - name: 平时用电
        data: day_consume1
      - name: 谷时用电
        data: day_consume4

screenshot

你也可以根据需要采用自己的展示形式

特别鸣谢

瀚思彼岸论坛@crazysiri,直接使用了他的部分代码。

bj_sgcc_energy's People

Contributors

georgezhao2010 avatar gonghao avatar imgbotapp avatar jianyun8023 avatar wrt54g avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bj_sgcc_energy's Issues

不可用

显示不可用
重置user_openid也不行
微信端查询正常
重新安装后,重启hass显示正确
等待一段时间后显示不可用
重启hass也不行

yaml加上了 hacs也集成了 不知道哪里出了问题

Logger: custom_components.bj_sgcc_energy.sgcc
Source: custom_components/bj_sgcc_energy/sgcc.py:135
Integration: 北京用电信息查询 (documentation, issues)
First occurred: 18:14:46 (1 occurrences)
Last logged: 18:14:46

getBalance response got error: HTTPConnectionPool(host='weixin.bj.sgcc.com.cn', port=80): Max retries exceeded with url: /ott/app/elec/account/query (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f02b1c61820>: Failed to establish a new connection: [Errno -2] Name does not resolve'))

阶梯第二阶段没有数据

非常感谢开发了这么好用的插件,但是我安装后有几个实体没有出现,
sensor.XXXXXXXXXX_current_level
sensor.XXXXXXXXXX_current_level_consume
sensor.XXXXXXXXXX_current_level_remain
sensor.XXXXXXXXXX_current_pgv_type
sensor.XXXXXXXXXX_current_price

家里是阶梯用电,目前处于第二阶梯用电中,电费余额、年度用电、本季度电费、历史用电量都没问题,就是关于阶梯的实体没有出来。

start bj_sgcc_energy error, data is none

2021-08-29 15:48:03 ERROR (MainThread) [custom_components.bj_sgcc_energy] Unexpected error fetching bj_sgcc_energy data: 'LEVEL_NUM'
Traceback (most recent call last):
File "/usr/local/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/update_coordinator.py", line 187, in _async_refresh
self.data = await self._async_update_data()
File "/usr/local/homeassistant/ha_config/custom_components/bj_sgcc_energy/init.py", line 46, in _async_update_data
data = await self._hass.async_add_executor_job(
File "/data/tools/python/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/homeassistant/ha_config/custom_components/bj_sgcc_energy/sgcc.py", line 149, in getData
self.getDetail(consNo)
File "/usr/local/homeassistant/ha_config/custom_components/bj_sgcc_energy/sgcc.py", line 98, in getDetail
self._info[consNo]["current_level"] = int(billDetails["LEVEL_NUM"])
KeyError: 'LEVEL_NUM'

I found that some return values do not have "level"_ Num ", so it is recommended to add a try
like:
try:
self._info[consNo]["current_level"] = int(billDetails["LEVEL_NUM"])
except:
self._info[consNo]["current_level"] = 0

您的请求已过期,请重新点击菜单尝试

Logger: custom_components.bj_sgcc_energy.sgcc
Source: custom_components/bj_sgcc_energy/sgcc.py:103
Integration: 北京用电信息查询 (documentation, issues)
First occurred: 20:17:01 (1 occurrences)
Last logged: 20:17:01

getConsNo error: 您的请求已过期,请重新点击菜单尝试。

getToken response got error

此错误来自自定义集成。

Logger: custom_components.bj_sgcc_energy.sgcc
Source: custom_components/bj_sgcc_energy/sgcc.py:67
Integration: 北京用电信息查询 (documentation, issues)
First occurred: 10:08:34 (1 occurrences)
Last logged: 10:08:34

getToken response got error: HTTPConnectionPool(host='weixin.bj.sgcc.com.cn', port=80): Max retries exceeded with url: /ott/app/auth/authorize?target=M_YECX (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fe3cbdd8a90>: Failed to establish a new connection: [Errno -3] Try again'))

这个是哪里有问题呀 还有会考虑把传感器改一下介入官方的能源吗 现在的能源里找不到对应的传感器(不太懂语言)

报错:请求超时

homeassistant日志中心报错请求超时:Error fetching bj_sgcc_energy data: Data update timed out
大佬看是否方便修复下

2022.4.0:属性缺失

hass升级到2022.4.0之后,sensor的attribute没有了,如sensor.XXXXXXXXXX_balance的last_update属性、sensor.XXXXXXXXXX_history_*的consume_bill属性均缺失。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.