本帖最后由 jmkl1028 于 2024-12-31 23:21 编辑
原作者已经更新github库,下面的教程可能已经不能正确拉取!
用好了,你倒是说一声啊
看到ARCW这个帖子2024 Homeassistant 国家电网电费获取 - 『HomeAssistant』综合讨论区 - 『瀚思彼岸』» 智能家居技术论坛 - Powered by Discuz!
尝试安装成功
1.青龙面板
(1))订阅任务(这一步已经失效)
运行一次
(2)安装mqtt依赖
如果安装不成功,尝试更换镜像源。我是用系统自带的镜像源
(3)添加环境变量
export WSGW_USERNAME="" #网上国网账号
export WSGW_PASSWORD="" #网上国网密码
export WSGW_RECENT_ELC_FEE="true" #是否获取最近电费
export WSGW_mqtt_host="" #mqtt服务器地址 192.168.1.7
export WSGW_mqtt_port="" #mqtt服务器端口 1883
export WSGW_mqtt_username="" #mqtt服务器用户名
export WSGW_mqtt_password="" #mqtt服务器密码
这里的export WSGW_mqtt_host="" #mqtt服务器地址 ,我不知道是否正确,网上找了一个免费的。可以从下面任选一个试试
Mosquitto公共MQTT Broker服务器
test.mosquitto.org 协议: TCP 端口: 1883 MQTT版本: 5.0/3.1.1 备注: 无加密,无认证 test.mosquitto.org 协议: TCP 端口: 1884 MQTT版本: 5.0/3.1.1 备注: 无加密,有认证 test.mosquitto.org 协议: TCP/TLS 端口: 8883 MQTT版本: 5.0/3.1.1 备注: 有加密,无认证 test.mosquitto.org 协议: TCP/TLS 端口: 8884 MQTT版本: 5.0/3.1.1 备注: 有加密,客户端证书 test.mosquitto.org 协议: TCP/TLS 端口: 8885 MQTT版本: 5.0/3.1.1 备注: 有加密,有认证^2^。
2.HA设置
(1)找到configuration.yaml 文件添加mqtt传感器
mqtt:
sensor:
- name: "电费余额"
icon: 'mdi:lightning-bolt'
unique_id: 'yong_dian_xin_xi'
state_topic: "nodejs/state-grid"
value_template: "{{ value_json.sumMoney }}"
unit_of_measurement: '元'
json_attributes_topic: "nodejs/state-grid"
json_attributes_template: "{{ value_json | tojson }}"
- name: 'Electricity Usage Day 1'
state_topic: 'nodejs/state-grid'
value_template: '{{ value_json.dayList[0].dayElePq }}'
unique_id: "electricity_usage_day1"
device_class: "energy"
unit_of_measurement: "度"
icon: "mdi:chart-bell-curve"
json_attributes_topic: "nodejs/state-grid"
json_attributes_template: "{{ value_json.dayList[0] | tojson }}"
- name: 'Electricity Usage Day 2'
state_topic: 'nodejs/state-grid'
value_template: '{{ value_json.dayList[1].dayElePq }}'
unique_id: "electricity_usage_day2"
device_class: "energy"
unit_of_measurement: "度"
icon: "mdi:chart-bell-curve"
json_attributes_topic: "nodejs/state-grid"
json_attributes_template: "{{ value_json.dayList[1] | tojson }}"
- name: 'Electricity Usage Day 3'
state_topic: 'nodejs/state-grid'
value_template: '{{ value_json.dayList[2].dayElePq }}'
unique_id: "electricity_usage_day3"
device_class: "energy"
unit_of_measurement: "度"
icon: "mdi:chart-bell-curve"
json_attributes_topic: "nodejs/state-grid"
json_attributes_template: "{{ value_json.dayList[2] | tojson }}"
- name: 'Electricity Usage Day 4'
state_topic: 'nodejs/state-grid'
value_template: '{{ value_json.dayList[3].dayElePq }}'
unique_id: "electricity_usage_day4"
device_class: "energy"
unit_of_measurement: "度"
icon: "mdi:chart-bell-curve"
json_attributes_topic: "nodejs/state-grid"
json_attributes_template: "{{ value_json.dayList[3] | tojson }}"
- name: 'Electricity Usage Day 5'
state_topic: 'nodejs/state-grid'
value_template: '{{ value_json.dayList[4].dayElePq }}'
unique_id: "electricity_usage_day5"
device_class: "energy"
unit_of_measurement: "度"
icon: "mdi:chart-bell-curve"
json_attributes_topic: "nodejs/state-grid"
json_attributes_template: "{{ value_json.dayList[4] | tojson }}"
- name: 'Electricity Usage Day 6'
state_topic: 'nodejs/state-grid'
value_template: '{{ value_json.dayList[5].dayElePq }}'
unique_id: "electricity_usage_day6"
device_class: "energy"
unit_of_measurement: "度"
icon: "mdi:chart-bell-curve"
json_attributes_topic: "nodejs/state-grid"
json_attributes_template: "{{ value_json.dayList[5] | tojson }}"
- name: 'Electricity Usage Day 7'
state_topic: 'nodejs/state-grid'
value_template: '{{ value_json.dayList[6].dayElePq }}'
unique_id: "electricity_usage_day7"
device_class: "energy"
unit_of_measurement: "度"
icon: "mdi:chart-bell-curve"
json_attributes_topic: "nodejs/state-grid"
json_attributes_template: "{{ value_json.dayList[6] | tojson }}"
重新加载configuration.yaml
(2)添加卡片模版
依次添加vertical-stack,flex-table-card,apexcharts-card
(3)安装MQTT集成
mqtt服务器地址与前面青龙里设置的ip对应,其它的好像都不需要改动了
(4)仪表盘添加卡片
依次添加用电量、7日用电量、12月份用电统计
type: vertical-stack
cards:
- type: grid
columns: 2
cards:
- type: entity
entity: sensor.dian_fei_yu_e
name: 电费余额
attribute: sumMoney
unit: 元
icon: mdi:currency-usd
- type: entity
entity: sensor.electricity_usage_day_1
name: 昨日用电
icon: mdi:lightning-bolt
- type: entity
entity: sensor.dian_fei_yu_e
name: 年度总电费
attribute: totalEleCost
unit: 元
icon: mdi:currency-usd
- type: entity
entity: sensor.dian_fei_yu_e
name: 年度总电量
attribute: totalEleNum
unit: 度
icon: mdi:lightning-bolt
square: false
- type: entity
entity: sensor.electricity_usage_day_1
name: 昨日日期
attribute: day
icon: mdi:calendar-today
- type: entity
entity: sensor.dian_fei_yu_e
name: 更新日期
attribute: amtTime
icon: mdi:clock-time-three
title: 用电统计
type: custom:flex-table-card
title: 过去7天用电情况
entities:
include: sensor.electricity_usage_day*
columns:
- name: 日期
data: day
- name: 用电量
data: state
suffix: 度
- name: 电费
data: state
modify: parseFloat(x*0.5).toFixed(2)
suffix: 元
type: custom:apexcharts-card
graph_span: 12month
header:
show: true
title: 最近12个月电量统计数据
show_states: true
colorize_states: true
series:
- entity: sensor.dian_fei_yu_e
name: 用电量
unit: 度
type: column
data_generator: |
return entity.attributes.monthList.map((peak, index) => {
return [entity.attributes.monthList[index].endDate, entity.attributes.monthList[index].monthEleNum];
});
前面操作正确就会有对应的卡片显示,否则就是有问题了
免费的MQTT有使用时间限制,也可以自己搭建
搭建本机自己的MQTT服务器
Ubuntu设备搭建本地MQTT服务器 - 『HomeAssistant』综合讨论区 - 『瀚思彼岸』» 智能家居技术论坛 - Powered by Discuz!
|