Giter VIP home page Giter VIP logo

Comments (9)

Tuisku-L avatar Tuisku-L commented on August 10, 2024 2

其实挺简单的,添加几个实体(比如本月用电量、本月电费),然后从数据库里拿出来本月 1 号到今天的用电量合计,写一个计算阶梯价格的函数,结果更新到这俩实体就行了。
我自己瞎写了一下,就不往这里合并了,你可以参考一下:
Tuisku-L@bb0f457

from sgcc_electricity_new.

EricCorleone avatar EricCorleone commented on August 10, 2024

很强,我去研究一下

from sgcc_electricity_new.

lixinzai avatar lixinzai commented on August 10, 2024

其实挺简单的,添加几个实体(比如本月用电量、本月电费),然后从数据库里拿出来本月 1 号到今天的用电量合计,写一个计算阶梯价格的函数,结果更新到这俩实体就行了。 我自己瞎写了一下,就不往这里合并了,你可以参考一下: Tuisku-L@bb0f457

请问下实体的哪个怎么弄呀

from sgcc_electricity_new.

Tuisku-L avatar Tuisku-L commented on August 10, 2024

其实挺简单的,添加几个实体(比如本月用电量、本月电费),然后从数据库里拿出来本月 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.

lixinzai avatar lixinzai commented on August 10, 2024

其实很简单的,添加几个实体(比如本月用电量、本月电费),然后从数据库里来本月 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.

Tuisku-L avatar Tuisku-L commented on August 10, 2024

其实很简单的,添加几个实体(比如本月用电量、本月电费),然后从数据库里来本月 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.

lixinzai avatar lixinzai commented on August 10, 2024

其实很简单的,添加几个实体(比如本月用电量、每月电费),然后从数据库里来本月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.

EricCorleone avatar EricCorleone commented on August 10, 2024

其实挺简单的,添加几个实体(比如本月用电量、本月电费),然后从数据库里拿出来本月 1 号到今天的用电量合计,写一个计算阶梯价格的函数,结果更新到这俩实体就行了。 我自己瞎写了一下,就不往这里合并了,你可以参考一下: Tuisku-L@bb0f457

感谢,我按你说的搞定了实时月用电量,但是实时月电费是没法实现了,因为我家开通了峰谷用电,以现有的数据是没法计算每天的电价的,比较可惜。还有你代码里计算的上月用电量似乎并没有必要,原代码里的sensor.month_electricity_usage就是上个月的用电量

from sgcc_electricity_new.

Tuisku-L avatar Tuisku-L commented on August 10, 2024

其实挺简单的,添加几个实体(比如本月用电量、本月电费),然后从数据库里拿出来本月 1 号到今天的用电量合计,写一个计算阶梯价格的函数,结果更新到这俩实体就行了。 我自己瞎写了一下,就不往这里合并了,你可以参考一下: Tuisku-L@bb0f457

我按你说的搞定了实时月用电量,但是实时月电费是没法实现了,因为我家开通了峰谷用电,以现有的数据是没法计算每天的电价的,比较可惜

应该也可以,电网的数据好像是有给峰谷电的,但是脚本里没去爬,要修改的更深一点了

from sgcc_electricity_new.

Related Issues (20)

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.