Comments (9)
其实挺简单的,添加几个实体(比如本月用电量、本月电费),然后从数据库里拿出来本月 1 号到今天的用电量合计,写一个计算阶梯价格的函数,结果更新到这俩实体就行了。
我自己瞎写了一下,就不往这里合并了,你可以参考一下:
Tuisku-L@bb0f457
from sgcc_electricity_new.
很强,我去研究一下
from sgcc_electricity_new.
其实挺简单的,添加几个实体(比如本月用电量、本月电费),然后从数据库里拿出来本月 1 号到今天的用电量合计,写一个计算阶梯价格的函数,结果更新到这俩实体就行了。 我自己瞎写了一下,就不往这里合并了,你可以参考一下: Tuisku-L@bb0f457
请问下实体的哪个怎么弄呀
from sgcc_electricity_new.
其实挺简单的,添加几个实体(比如本月用电量、本月电费),然后从数据库里拿出来本月 1 号到今天的用电量合计,写一个计算阶梯价格的函数,结果更新到这俩实体就行了。 我自己瞎写了一下,就不往这里合并了,你可以参考一下: Tuisku-L@bb0f457
请问下实体的哪个怎么弄呀
在 HA configuration.yaml 的 template 下添加实体就可以了,比如我加的某两个:
- trigger:
- platform: event
event_type: "state_changed"
event_data:
entity_id: sensor.month_electricity_usage_db
sensor:
- name: 本月累计用电量
unique_id: month_electricity_usage_db
state: "{{ states('sensor.month_electricity_usage_db') }}"
attributes:
present_date: "{{ state_attr('sensor.month_electricity_usage_db', 'present_date') }}"
last_updated: "{{ state_attr('sensor.month_electricity_usage_db', 'last_updated') }}"
state_class: total_increasing
unit_of_measurement: "kWh"
device_class: energy
- trigger:
- platform: event
event_type: "state_changed"
event_data:
entity_id: sensor.month_electricity_charge_db
sensor:
- name: 本月累计电费
unique_id: month_electricity_charge_db
state: "{{ states('sensor.month_electricity_charge_db') }}"
state_class: total_increasing
unit_of_measurement: "CNY"
device_class: monetary
对应的更新实体的代码在我的分支上有,可以根据关键字搜一下
from sgcc_electricity_new.
其实很简单的,添加几个实体(比如本月用电量、本月电费),然后从数据库里来本月 1 号到今天的用电量,写一个计算阶梯价格的函数,结果更新到这俩实体就行了。我自己瞎写了一下,就不往这里合并了,你可以参考一下:Tuisku-L@bb0f457
好奇下实体的哪个怎么弄呀
在HA配置.yaml的模板下添加实体就可以了,比如我加的一些:
- trigger: - platform: event event_type: "state_changed" event_data: entity_id: sensor.month_electricity_usage_db sensor: - name: 本月累计用电量 unique_id: month_electricity_usage_db state: "{{ states('sensor.month_electricity_usage_db') }}" attributes: present_date: "{{ state_attr('sensor.month_electricity_usage_db', 'present_date') }}" last_updated: "{{ state_attr('sensor.month_electricity_usage_db', 'last_updated') }}" state_class: total_increasing unit_of_measurement: "kWh" device_class: energy - trigger: - platform: event event_type: "state_changed" event_data: entity_id: sensor.month_electricity_charge_db sensor: - name: 本月累计电费 unique_id: month_electricity_charge_db state: "{{ states('sensor.month_electricity_charge_db') }}" state_class: total_increasing unit_of_measurement: "CNY" device_class: monetary
对应的更新实体的代码在我的分支上有,可以根据关键字搜一下
好的,能源面板用last_electricity_usage的你会刷新数据出来吗,我这边只会显示0
from sgcc_electricity_new.
其实很简单的,添加几个实体(比如本月用电量、本月电费),然后从数据库里来本月 1 号到今天的用电量,写一个计算阶梯价格的函数,结果更新到这俩实体就行了。我自己瞎写了一下,就不往这里合并了,你可以参考一下:Tuisku-L@bb0f457
好奇下实体的哪个怎么弄呀
在HA配置.yaml的模板下添加实体就可以了,比如我加的一些:
- trigger: - platform: event event_type: "state_changed" event_data: entity_id: sensor.month_electricity_usage_db sensor: - name: 本月累计用电量 unique_id: month_electricity_usage_db state: "{{ states('sensor.month_electricity_usage_db') }}" attributes: present_date: "{{ state_attr('sensor.month_electricity_usage_db', 'present_date') }}" last_updated: "{{ state_attr('sensor.month_electricity_usage_db', 'last_updated') }}" state_class: total_increasing unit_of_measurement: "kWh" device_class: energy - trigger: - platform: event event_type: "state_changed" event_data: entity_id: sensor.month_electricity_charge_db sensor: - name: 本月累计电费 unique_id: month_electricity_charge_db state: "{{ states('sensor.month_electricity_charge_db') }}" state_class: total_increasing unit_of_measurement: "CNY" device_class: monetary
对应的更新实体的代码在我的分支上有,可以根据关键字搜一下
好的,能源面板用last_electricity_usage的你会刷新数据出来吗,我这边只会显示0
这个不太确定,我没用 HA 的能源面板,我是自定义了几个卡片显示了信息;我感觉能源面板不适合社会主义**(……),现在我们能拿到的数据精细化程度满足不了能源面板的需求;
不过我看 last_electricity_usage
可能缺少个 last_reset
的属性,你可以试下改成:
- trigger:
- platform: event
event_type: "state_changed"
event_data:
entity_id: sensor.last_electricity_usage
sensor:
- name: 最近一天用电量
unique_id: last_electricity_usage_entity
state: "{{ states('sensor.last_electricity_usage') }}"
attributes:
present_date: "{{ state_attr('sensor.last_electricity_usage', 'present_date') }}"
last_updated: "{{ state_attr('sensor.last_electricity_usage', 'last_updated') }}"
last_reset: "{{ now().strftime('%Y-%m-%dT00:00:00+00:00') if now().hour == 0 and now().minute == 0 else state_attr('sensor.last_electricity_usage_entity', 'last_reset') }}"
state_class: total
unit_of_measurement: "kWh"
device_class: energy
不确定行不行(
from sgcc_electricity_new.
其实很简单的,添加几个实体(比如本月用电量、每月电费),然后从数据库里来本月1号到今天的用电量,写一个计算阶梯价格的函数,结果更新到这两个实体就行了。我自己瞎写了一下,不往这里合并了,你可以参考一下:Tuisku-L@bb0f457
好奇下实体的哪个怎么弄呀
在HA配置.yaml的模板下添加实体就可以了,比如我加的一些:
- trigger: - platform: event event_type: "state_changed" event_data: entity_id: sensor.month_electricity_usage_db sensor: - name: 本月累计用电量 unique_id: month_electricity_usage_db state: "{{ states('sensor.month_electricity_usage_db') }}" attributes: present_date: "{{ state_attr('sensor.month_electricity_usage_db', 'present_date') }}" last_updated: "{{ state_attr('sensor.month_electricity_usage_db', 'last_updated') }}" state_class: total_increasing unit_of_measurement: "kWh" device_class: energy - trigger: - platform: event event_type: "state_changed" event_data: entity_id: sensor.month_electricity_charge_db sensor: - name: 本月累计电费 unique_id: month_electricity_charge_db state: "{{ states('sensor.month_electricity_charge_db') }}" state_class: total_increasing unit_of_measurement: "CNY" device_class: monetary
对应的更新实体的代码在我的分支上有,可以根据关键字搜一下
好的,能源面板用last_electricity_usage的你会刷新数据出来吗,我的演讲只显示0
这个不确定,我没用HA的能源面板,我是自定义了几个反馈显示了信息;我感觉能源面板不适合社会主义**(……),现在我们能够获得的数据精细化程度满足无法能源面板的需求;
我看
last_electricity_usage
可能缺少一个last_reset
属性,你可以尝试下改成:- trigger: - platform: event event_type: "state_changed" event_data: entity_id: sensor.last_electricity_usage sensor: - name: 最近一天用电量 unique_id: last_electricity_usage_entity state: "{{ states('sensor.last_electricity_usage') }}" attributes: present_date: "{{ state_attr('sensor.last_electricity_usage', 'present_date') }}" last_updated: "{{ state_attr('sensor.last_electricity_usage', 'last_updated') }}" last_reset: "{{ now().strftime('%Y-%m-%dT00:00:00+00:00') if now().hour == 0 and now().minute == 0 else state_attr('sensor.last_electricity_usage_entity', 'last_reset') }}" state_class: total unit_of_measurement: "kWh" device_class: energy
不确定行不行(
不行 用reset的话得出的是今天减昨天的,能源就显示个位数了
from sgcc_electricity_new.
其实挺简单的,添加几个实体(比如本月用电量、本月电费),然后从数据库里拿出来本月 1 号到今天的用电量合计,写一个计算阶梯价格的函数,结果更新到这俩实体就行了。 我自己瞎写了一下,就不往这里合并了,你可以参考一下: Tuisku-L@bb0f457
感谢,我按你说的搞定了实时月用电量,但是实时月电费是没法实现了,因为我家开通了峰谷用电,以现有的数据是没法计算每天的电价的,比较可惜。还有你代码里计算的上月用电量似乎并没有必要,原代码里的sensor.month_electricity_usage就是上个月的用电量
from sgcc_electricity_new.
其实挺简单的,添加几个实体(比如本月用电量、本月电费),然后从数据库里拿出来本月 1 号到今天的用电量合计,写一个计算阶梯价格的函数,结果更新到这俩实体就行了。 我自己瞎写了一下,就不往这里合并了,你可以参考一下: Tuisku-L@bb0f457
我按你说的搞定了实时月用电量,但是实时月电费是没法实现了,因为我家开通了峰谷用电,以现有的数据是没法计算每天的电价的,比较可惜
应该也可以,电网的数据好像是有给峰谷电的,但是脚本里没去爬,要修改的更深一点了
from sgcc_electricity_new.
Related Issues (20)
- 按照示例添加实体报错 HOT 5
- 为啥只能获取到T-2的日期消耗电量呢?想看昨日的如何查看呢? HOT 14
- 大佬可以贴一下HA里数据展示的代码吗? HOT 3
- 状态刷新失败 HOT 4
- docker打包优化探讨 HOT 3
- 新版NumPy报错 HOT 13
- V1.4.2编译启动报错 HOT 4
- 运行报错 HOT 1
- 运行时报错 HOT 4
- 能源面板问题 HOT 3
- 能否增加峰谷用电详情及占比 HOT 1
- 验证码滑块拖动一直报错 HOT 9
- 定时执行不会更新数据库
- 95598登录一直报错
- 创建容器后可以运行但日志报错 HOT 2
- pushplus配置后余额小于配置余额时没有提醒 HOT 15
- 是否考虑支持 bark 推送
- homeassistant重启后实体消失了
- 大佬 看看这是什么情况
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sgcc_electricity_new.