I have a Tuya based kWh meter, but it does not show in the energy dashboard.
What can I do to add it to the energy dashboard ?
At this moment it measures the consumption of my airco, but I would like to use it for my solar panel production.
francisp
(Francis)
July 11, 2024, 6:19pm
2
It only shows a power sensor, not an energy sensor. You need to create an integral helper, and add that to your energy dashboard
And don’t forget to use the left method for the integral helper, seems to trip-up most people.
Thanks for pointing me to the integral helper, I did not know it existed.
I created it, and add it to the energy dashboard.
I have no idea about the method to choose, I chose the trapeze method because the docs indicated that it was the most accurate.
Can you explain why the left method would be better please, I would like to learn more about it, and my math and statistics courses are a very long time ago, so I surely forgot some of it.
It comes down to how HA stores values, specifically when they don’t change over time. Search the forum and you’ll find a lot of detailed explanations. In more ‘normal’ situations, trapezoidal does tend to be a better method for approximating an integral, but in this particular use-case the left method is DRAMATICALLY better.
makai
July 12, 2024, 6:11am
7
Even with the latest updates to this integration?
See:
home-assistant:dev
← home-assistant:integration_sensor_last_reported
opened 08:55AM - 20 Mar 24 UTC
<!--
You are amazing! Thanks for contributing to our project!
Please, DO N… OT DELETE ANY TEXT from this template! (unless instructed).
-->
## Proposed change
<!--
Describe the big picture of your changes here to communicate to the
maintainers why we should accept this pull request. If it fixes a bug
or resolves a feature request, be sure to link to that issue in the
additional information section.
-->
Use `state_reported` instead of `state_changed` events in Riemann sum sensor.
Unlike `state_changed` events, `state_reported` events are fired every time an integration writes the sensor state, even when state and attributes are unchanged.
This fixes bugs where the calculated integral is incorrect for sensors which don't set `force_update` to True
Test PRs which should be merged first:
- https://github.com/home-assistant/core/pull/120316
- https://github.com/home-assistant/core/pull/120326
## Type of change
<!--
What type of change does your PR introduce to Home Assistant?
NOTE: Please, check only 1! box!
If your PR requires multiple boxes to be checked, you'll most likely need to
split it into multiple PRs. This makes things easier and faster to code review.
-->
- [ ] Dependency upgrade
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [ ] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
## Additional information
<!--
Details are important, and help maintainers processing your PR.
Please be sure to fill out additional details, if applicable.
-->
- This PR fixes or closes issue: fixes #
- This PR is related to issue:
- Link to documentation pull request:
## Checklist
<!--
Put an `x` in the boxes that apply. You can also fill these out after
creating the PR. If you're unsure about any of them, don't hesitate to ask.
We're here to help! This is simply a reminder of what we are going to look
for before merging your code.
-->
- [ ] The code change is tested and works locally.
- [ ] Local tests pass. **Your PR cannot be merged unless tests pass**
- [ ] There is no commented out code in this PR.
- [ ] I have followed the [development checklist][dev-checklist]
- [ ] I have followed the [perfect PR recommendations][perfect-pr]
- [ ] The code has been formatted using Ruff (`ruff format homeassistant tests`)
- [ ] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated for [www.home-assistant.io][docs-repository]
If the code communicates with devices, web services, or third-party tools:
- [ ] The [manifest file][manifest-docs] has all fields filled out correctly.
Updated and included derived files by running: `python3 -m script.hassfest`.
- [ ] New or updated dependencies have been added to `requirements_all.txt`.
Updated by running `python3 -m script.gen_requirements_all`.
- [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
- [ ] Untested files have been added to `.coveragerc`.
<!--
This project is very active and we have a high turnover of pull requests.
Unfortunately, the number of incoming pull requests is higher than what our
reviewers can review and merge so there is a long backlog of pull requests
waiting for review. You can help here!
By reviewing another pull request, you will help raise the code quality of
that pull request and the final review will be faster. This way the general
pace of pull request reviews will go up and your wait time will go down.
When picking a pull request to review, try to choose one that hasn't yet
been reviewed.
Thanks for helping out!
-->
To help with the load of incoming pull requests:
- [ ] I have reviewed two other [open pull requests][prs] in this repository.
[prs]: https://github.com/home-assistant/core/pulls?q=is%3Aopen+is%3Apr+-author%3A%40me+-draft%3Atrue+-label%3Awaiting-for-upstream+sort%3Acreated-desc+review%3Anone+-status%3Afailure
<!--
Thank you for contributing <3
Below, some useful links you could explore:
-->
[dev-checklist]: https://developers.home-assistant.io/docs/development_checklist/
[manifest-docs]: https://developers.home-assistant.io/docs/creating_integration_manifest/
[quality-scale]: https://developers.home-assistant.io/docs/integration_quality_scale_index/
[docs-repository]: https://github.com/home-assistant/home-assistant.io
[perfect-pr]: https://developers.home-assistant.io/docs/review-process/#creating-the-perfect-pr
home-assistant:dev
← ronweikamp:dev-maxdt-integral
opened 10:23PM - 15 Feb 24 UTC
## Proposed change
### Summary of what has changed and how users can benefit fr… om this
The Riemann sum integral sensor has a new config `max_sub_interval` which allows the integral sensor to also change over time when the source stays constant. Arguably an important feature of an integral. Workarounds like sampling fake changes of the source sensor or reloading the source sensor to trigger integral updates for constant periods are not necessary anymore with this new config.
### More detail
A drawback of the current implementation is that it only changes based on changes of the source sensor (also see linked issues). With this PR the integral sensor can change if the source has a constant valid numeric value for a duration of `max_sub_interval`, allowing for both integration based on _state changes_ and _elapsed time_.
The idea is that after every calculation a timer will be scheduled to trigger after `max_sub_interval`. If before the time elapses a state change of the source occurs, the timer will be cancelled and integration will be done based on state change. If the timer is not cancelled, meaning there was no state change, meaning the source is constant, integration will be triggered based on time. Allowing for both fine grained state change based integration and integration during constant periods of the source. Also credits to @hberntsen for the approach. See picture of this new functionality in action (_speed_ is source, _distance_ is integral):
<img width="1311" alt="riemann_edit" src="https://github.com/home-assistant/core/assets/15732230/4f74e1e6-131a-448f-8b29-9e003d86cca2">
Here the red rectangles update the distance during constant speed. Effectively the `max_sub_interval` config enforces a max width of the Riemann 'rectangles' in the integration approximation. I expect that with this change the integral helper sensor will be more usable. The documentation simplifies because the implicit disclaimer about accurateness-when-the-source-updates-often can be removed, see related documentation PR.
## Type of change
<!--
What type of change does your PR introduce to Home Assistant?
NOTE: Please, check only 1! box!
If your PR requires multiple boxes to be checked, you'll most likely need to
split it into multiple PRs. This makes things easier and faster to code review.
-->
- [ ] Dependency upgrade
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [x] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
## Additional information
- This PR fixes or closes issue: fixes https://github.com/home-assistant/core/issues/88940 , https://github.com/home-assistant/core/issues/102057
- This PR is related to issue:
- Link to documentation pull request: https://github.com/home-assistant/home-assistant.io/pull/31453
## Checklist
<!--
Put an `x` in the boxes that apply. You can also fill these out after
creating the PR. If you're unsure about any of them, don't hesitate to ask.
We're here to help! This is simply a reminder of what we are going to look
for before merging your code.
-->
- [x] The code change is tested and works locally.
- [x] Local tests pass. **Your PR cannot be merged unless tests pass**
- [x] There is no commented out code in this PR.
- [x] I have followed the [development checklist][dev-checklist]
- [x] I have followed the [perfect PR recommendations][perfect-pr]
- [x] The code has been formatted using Ruff (`ruff format homeassistant tests`)
- [x] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [x] Documentation added/updated for [www.home-assistant.io][docs-repository]
If the code communicates with devices, web services, or third-party tools:
- [ ] The [manifest file][manifest-docs] has all fields filled out correctly.
Updated and included derived files by running: `python3 -m script.hassfest`.
- [ ] New or updated dependencies have been added to `requirements_all.txt`.
Updated by running `python3 -m script.gen_requirements_all`.
- [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
- [ ] Untested files have been added to `.coveragerc`.
<!--
This project is very active and we have a high turnover of pull requests.
Unfortunately, the number of incoming pull requests is higher than what our
reviewers can review and merge so there is a long backlog of pull requests
waiting for review. You can help here!
By reviewing another pull request, you will help raise the code quality of
that pull request and the final review will be faster. This way the general
pace of pull request reviews will go up and your wait time will go down.
When picking a pull request to review, try to choose one that hasn't yet
been reviewed.
Thanks for helping out!
-->
To help with the load of incoming pull requests:
- [ ] I have reviewed two other [open pull requests][prs] in this repository.
[prs]: https://github.com/home-assistant/core/pulls?q=is%3Aopen+is%3Apr+-author%3A%40me+-draft%3Atrue+-label%3Awaiting-for-upstream+sort%3Acreated-desc+review%3Anone+-status%3Afailure
<!--
Thank you for contributing <3
Below, some useful links you could explore:
-->
[dev-checklist]: https://developers.home-assistant.io/docs/development_checklist/
[manifest-docs]: https://developers.home-assistant.io/docs/creating_integration_manifest/
[quality-scale]: https://developers.home-assistant.io/docs/integration_quality_scale_index/
[docs-repository]: https://github.com/home-assistant/home-assistant.io
[perfect-pr]: https://developers.home-assistant.io/docs/review-process/#creating-the-perfect-pr