HomeAssistant接入国家电网(电费余额用电量查询)
HomeAssistant接入国家电网数据(电费余额用电量查询)(理论已经是支持全国)
欢迎加入本站交流群(245996886)
sgcc_electricity
容器地址:https://registry.hub.docker.com/r/dscao/sgcc_electricity
镜像加速拉取命令:docker pull dockerproxy.com/dscao/sgcc_electricity:latest
部署 docker
以群晖部署 docker 为例,其他 docker 举一反三哈
1. 高级设置里面的,变量需要按下面填入:
PHONE_NUMBER # 填入国家电网手机号
PASSWORD # 填入国家电网密码
HASS_URL #HA 局域网地址
HASS_TOKEN #令牌,点 ha 头像 拉到最下面创建填入即可
2.docker 文件夹文件不需要关联,直接下一步
3. 启动容器
4.ha 里面会生成一个实体,实体注册表里面搜索 95598 就出来
实体属性
本应用在启动后和每隔 8 小时抓取一次数据,并在 HA 里更新以下一个实体及其六个属性:
sensor.electricity_95598:电费余额 / 上期账单金额
is_pay: 是否当期已结清
need_pay: 账单欠费金额(后付费用户)
last_electricity_usage:最近一天用电量
thismonth_electricity_usage: 本月用电量
yearly_electricity_usage:今年以来用电量
yearly_electricity_charge: 今年以来电费
last_date: 数据更新的最后日期
手动添加实体
进入configuration.yaml,添加以下代码
template: - trigger: - platform: event event_type: "state_changed" event_data: entity_id: sensor.electricity_95598 sensor: - name: electricity_charge_balance_entity unique_id: electricity_charge_balance_entity state: "{{ states('sensor.electricity_95598') }}" state_class: measurement unit_of_measurement: "CNY" - name: electricity_balance_is_pay_entity unique_id: electricity_balance_is_pay_entity state: "{{ state_attr('sensor.electricity_95598', 'is_pay') }}" - name: last_electricity_usage_entity unique_id: last_electricity_usage_entity state: "{{ state_attr('sensor.electricity_95598', 'last_electricity_usage') }}" state_class: measurement unit_of_measurement: "KWH" - name: yearly_electricity_usage_entity unique_id: yearly_electricity_usage_entity state: "{{ state_attr('sensor.electricity_95598', 'yearly_electricity_usage') }}" state_class: measurement unit_of_measurement: "KWH" - name: yearly_electricity_charge_entity unique_id: yearly_electricity_charge_entity state: "{{ state_attr('sensor.electricity_95598', 'yearly_electricity_charge') }}" state_class: measurement unit_of_measurement: "CNY" - name: electricity_need_pay unique_id: electricity_need_pay state: "{{ state_attr('sensor.electricity_95598', 'need_pay') }}" state_class: measurement unit_of_measurement: "CNY" - name: thismonth_electricity_usage_entity unique_id: thismonth_electricity_usage_entity state: "{{ state_attr('sensor.electricity_95598', 'thismonth_electricity_usage') }}" state_class: measurement unit_of_measurement: "KWH" - name: electricity_last_date_entity unique_id: electricity_last_date_entity state: "{{ state_attr('sensor.electricity_95598', 'last_date') }}"
总结
就此就结束了~,可以通过调用实体的属性来查询各类的账单 / 金额等等,如果容器异常,看一下日志~
接入南方电网请查看: https://blog.cnod.net/post/55.html