Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create kwh integration sensor for direct use in energy dashboard #83

Merged
merged 11 commits into from
Aug 20, 2021

Conversation

bramstroker
Copy link
Owner

@bramstroker bramstroker commented Aug 17, 2021

@github-actions
Copy link
Contributor

github-actions bot commented Aug 17, 2021

🎉 HACS repository validator action summary 🎉
✅ The repository is not archived
✅ manifest.json file exist
✅ All required keys are present in manifest.json
✅ hacs.json has the 'name' key set
✅ The repository has a description
✅ powercalc is added to https://github.com/home-assistant/brands NICE!
✅ The repository has topics
✅ The repository has issues enabled
✅ This day ends with an 'y' (Friday)
✅ README.md exists
✅ HACS load check

@bramstroker bramstroker marked this pull request as draft August 17, 2021 20:31
@bramstroker
Copy link
Owner Author

Todo

  • Choose another default icon
  • Update readme

@bramstroker
Copy link
Owner Author

@NachtaktiverHalbaffe this feature is almost complete.
I have also updated the readme in this PR. Can you have a look please if anything is missing or you have any additions?

@nepozs
Copy link
Contributor

nepozs commented Aug 19, 2021

So many votes in 2 days only!
Are links to strawpol somewhere else?

@bramstroker bramstroker marked this pull request as ready for review August 19, 2021 20:42
@bramstroker
Copy link
Owner Author

Also added the links to the forum post on the HA forum.

@nepozs
Copy link
Contributor

nepozs commented Aug 19, 2021

BTW Shelly as energy icon uses
hass:lightning-bolt
i don't know like is looks in other integrations

@bramstroker
Copy link
Owner Author

Already implemented which had the most votes. The naming for the energy sensors is configurable, because I saw there were multiple opinions for energy and kwh

@bramstroker
Copy link
Owner Author

BTW Shelly as icon uses
hass:lightning-bolt
i don't know like is looks in other integrations

I have used mdi:flash, which is the same. This is what all my energy sensors have in my real HA installation

@nepozs
Copy link
Contributor

nepozs commented Aug 19, 2021

As I know TPlink uses also hass:lightning-bolt as energy and mdi:flash as power, just like Shelly
shelly_icons_Screenshot 2021-08-19 at 22-46-21 Poziomo - Home Assistant

And at the end :P official energy panel also has hass:lightning-bolt

@bramstroker
Copy link
Owner Author

Yeah I see thanks, they have a minor difference. Will change it before merging this pr

@NachtaktiverHalbaffe
Copy link
Contributor

@bramstroker Sorry had some days off. I think with this new feature you can cut out the part with the Riemann integration and add some explanations about the option to let automatically create energy sensors (or how to disable when you want to do it for yourself). I added a suggestion below (an below a codeblock so you can copy paste if you like)

If you want to use the virtual power sensors with the new energy integration, you have to create an energy sensor which utilizes the power of the powercalc sensor. Starting from v0.4 of powercalc it will automatically create energy sensors for you by default. No need for any custom configuration. These energy sensors then can be selected in the energy dashboard. If you want to create your energy sensors by your own with e.g. Riemann integration integration, then you can disable the automatic creation of energy sensors with the option create_energy_sensors in your configuration (see global configuration).

If you want to use the virtual power sensors with the new [energy integration](https://www.home-assistant.io/blog/2021/08/04/home-energy-management/), you have to create an energy sensor which utilizes the power of the powercalc sensor. Starting from v0.4 of powercalc it will automatically create energy sensors for you by default.  No need for any custom configuration. These energy sensors then can be selected in the energy dashboard. If you want to create your energy sensors by your own with e.g. [Riemann integration integration](https://www.home-assistant.io/integrations/integration/), then you can disable the automatic creation of energy sensors with the option `create_energy_sensors` in your configuration (see [global configuration](#global-configuration)).

The part with the energy groups is generally fine imo. If you wish you can change the example with the servers with a more common usecase like lights. I originally added this example because I copy pasted my servers out of my configuration because it was the cleanest and I wanted to keep the examples konsistent with the section with creating a Riemann integration sensor.
Another optional thing is the yaml example. My version works, but this way of creating template sensors seems to be deprecated. I added the yaml example with the new official preferred way below (copy&paste ready). I like the old way more, but its your choice which of the examples you want to include.

template:
  - sensor:
      - unique_id: "energy_server"
        name: "All Server Energy Consumption"
        unit_of_measurement: kWh
        state_class: measurement
        device_class: energy
        attributes:
          last_reset: "1970-01-01T00:00:00+00:00"
        icon: mdi:counter
        state: >-
            {{states('sensor.kingkong_energy') | float + states('sensor.kinglouie_energy')|float}}    

One question to the feature: Is it possible to add the function to enable/disable the creation of energy sensors on the level of each powercalc sensor for backwards compatibility? It's not a nightmare if I lose the data gathered from my old energy sensors, but using the new feature on new powercalc sensors and keeping my own old ones would be the last 5% to make it perfect.

If its merged into master, then I can hop again onto this branch and do some testing. In general I like the direction this custom integration is going, good work 👍

@bramstroker
Copy link
Owner Author

Ability to disable energy creation per entity has also been implemented.

sensor:
  - platform: powercalc
    create_energy_sensor: false

Also added your suggestion to the readme. Will do some final testing this weekend and than merge this feature.

@bramstroker bramstroker merged commit 7a94923 into master Aug 20, 2021
@bramstroker
Copy link
Owner Author

This feature is complete as far as I'm concerned.
@NachtaktiverHalbaffe and maybe others, are you able to do some testing on the master branch? Because this is quite a big change I wan't to make sure it does not cause any unforseen problems before I release it.

@NachtaktiverHalbaffe
Copy link
Contributor

@bramstroker Don't know where to post the results of my testing, so I'm doing it here. Hopped onto master branch some minutes ago. Disabling the creation on the level of powercalc sensor works and also disabling it for all powercalc sensors. The created sensors are also picked up by the energy dashboard. Now I only have to look if the energy sensors itself delivers the right values, but I think there cannot go something wrong. Looks like everything is working right now, good work 👍

@bramstroker
Copy link
Owner Author

Thanks for starting some testing. Hope we can soon release the feature.
I also did some testing today and it is looking good so far.

Screenshot 2021-08-21 at 16 18 12

@bramstroker
Copy link
Owner Author

@NachtaktiverHalbaffe is everything working correctly for you now you have it running for 1 day?

@NachtaktiverHalbaffe
Copy link
Contributor

@bramstroker Yep values are right and nothing else broke. This feature seems ready for release from my perspective

@bramstroker
Copy link
Owner Author

Great thanks for the feedback

@bramstroker bramstroker deleted the feature/kwh-sensor branch August 24, 2021 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants