odwide
February 10, 2024, 10:45pm
1
If the metric prefix or time unit of a derivative helper are changed the submission is saved but the unit stays the same.
A newly created derivative helper with unit_prefix: km, unit_time: h and source sensor for distance in meters yields the speed in km/h. Fine so far.
However, if I change either property it doesn’t take effect; the unit keeps showing as km/h. The config has been in fact saved to core.config_entries but it won’t matter, even if HA is restarted. If I delete the helper, purge statistics, restart HA and readd the helper with the same name, the unit still persists. The only workaround is adding the derivative with another name.
Where are these properties persisting, besides the database and the .storage folder? I’ve combed both, nuked all related data and still can’t figure how to make HA honor these unit changes.
5 Likes
tom_l
February 10, 2024, 10:59pm
2
So you are using the UI, not YAML?
I habe exactly the same problem, using the UI in HA 2024.6.3
Juchar
(Juchar)
July 7, 2024, 2:25pm
5
Same here, no solution so far.
kubasa
(Kuba Sawulski)
July 29, 2024, 3:02pm
6
I’ve investigated issue more and it can be bypassed by:
stopping ha core container
removing corresponding item from .storage/core.restore_state
starting core container again
2 Likes
luc-ass
(Lucas Gasenzer)
January 19, 2025, 12:42pm
7
Same issue here. Is there a fix on the horizon?
Jeppedy
(Jeffrey Herr)
August 18, 2025, 3:33pm
8
Anyone ever see a fix come through for this?
karwosts
(karwosts)
August 18, 2025, 3:40pm
9
Fix is here but waiting for review for a while.
dev ← karwosts:derivative_instant_unit
opened 06:13PM - 25 Jun 25 UTC
## Proposed change
Fix some issues with the derivative unit_of_measurement.
… 1. Fixes #136419, wherein once a derivative sensor was created, it's displayed unit of measurement could not be changed, even when user modifies it through options flow, making the actual state internally calculate using a different unit, leading to wildly incorrect value.
2. Improves derivative to calculate and set it's unit instantly when created based on the source sensor, instead of waiting for 2 updates of the source sensor when the first derivative could be calculated. The existing behavior is confusing, as after creating a sensor it could have no unit for many minutes or hours depending on how long it takes the source to change state. Also while it was waiting, it would ultimately be a problem for statistics, which would start recording data with unit `""`, and then when the real unit updated later, it would generate a statistics issue due to change of native unit.
3. (added late) Update the derivative unit of measurement anytime the source sensor changes unit_of_measurement. Reset the derivative to 0 if the unit changes, since we don't want to calculate huge jumps if a sensor changes from e.g. Wh to kWh.
## Type of change
- [ ] Dependency upgrade
- [x] 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
- This PR fixes or closes issue:
- fixes #136419
- fixes #84088
- fixes #121031
- fixes #106884
- fixes #73461
- fixes #95666
- This PR is related to issue:
- Link to documentation pull request:
- Link to developer documentation pull request:
- Link to frontend pull request:
## Checklist
- [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:
- [ ] 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.
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
[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
Generally you should look for bug reports and status on github, there are several issues open for this already there.
Issues usually aren’t tracked here on the forum.