rccoleman
(Rob Coleman)
April 13, 2021, 9:48pm
6
Right, it just needs to have some unit_of_measurement
, doesn’t matter what it is. Sometimes previous values without a uom can delay the graph displaying until they’re flushed out with new data.
1 Like
CaptTom
(Tom)
April 14, 2021, 1:07am
7
rccoleman:
To be clear, unit_of_measurement
is just a string and can be anything you want. There are only a few “special” uom values, such as “°C” and “°F”, where HA actually converts values to your locale settings when it sees them.
Thank you for explaining. Is there a list of the “special” uom values which get converted?
rccoleman
(Rob Coleman)
April 14, 2021, 1:20am
8
petro
(Petro)
April 14, 2021, 1:38am
9
Only c and f get converted. Everything else remains untouched
rccoleman
(Rob Coleman)
April 14, 2021, 1:53am
10
That’s what I thought, and then I saw the conversion functions for other things. I guess those are just helpers for integrations to use when they want. Incidentally, the frontend changes the icon when it sees a temperature unit: frontend/sensor_icon.ts at dc79fc2919d836ae28ce0c065aacd6ef52f47dc7 · home-assistant/frontend · GitHub
const unit = stateObj?.attributes.unit_of_measurement;
if (unit === UNIT_C || unit === UNIT_F) {
return "hass:thermometer";
}
drcoolzic
(Jean)
September 5, 2021, 11:01am
11
This does not seem to be true for long term statistic see problem reported here
CJason
August 29, 2022, 3:10pm
12
To historize the states of my Venstar thermostat attribute: hvac_action
what unit_of_measurement should be used for different text strings like idle, cooling, etc.?
So far, with this configuration:
when I pull it up in history it’s trying to trend a numerical value.
CJason
August 29, 2022, 11:21pm
13
To clarify, the variable is acquiring the data:
But the history is either not being stored or retrieved properly:
Is unit of measure the problem, or something else?
Ideally, the trend would show up like the weather forecast:
petro
(Petro)
August 30, 2022, 1:22am
14
if you add a unit of measurement, it attempts to graph it. So don’t add a unit of measurement.
1 Like
i have a similar issue. i have no uom but i still see a line graph. any thoughts?
petro
(Petro)
September 14, 2022, 10:21pm
17
that’s the only thing that causes it unless something changed recently.
1 Like
Would state_class:
being present perhaps cause this behaviour too?
petro
(Petro)
September 14, 2022, 11:48pm
19
It could. To be honest, I haven’t been paying attention to those details lately.
1 Like
felipecrs
(Felipe Santos)
December 26, 2022, 6:11pm
20
This doesn’t make sense. Does it mean that Home Assistant only supports dollars, euros and cents as currency unit of measurements? What about the rest of the world?
1 Like
And if you want graphs, but there simply isn’t a unit of measurement for the data (ratio’s, dimensionless numbers, …), you can add a blank unit of measurement:
unit_of_measurement: “”
2 Likes
CybDis
(Stefan)
May 11, 2023, 9:01am
22
this answer does not seem to be valid anymore with 2023-05 they “assume” a numeric value and cast it to decimal, what causes an exception, what causes the sensor to dispaly “unknown”.
There seems to have been a breaking change
1 Like
petro
(Petro)
May 11, 2023, 12:11pm
23
Not sure what you’re talking about. The solution is still valid as is the information in this post. If your value is numeric, add a unit_of_measurement and the information will be graphed.
123
(Taras)
May 11, 2023, 12:26pm
24
Since 2023.5.0, several people have reported that their Template Sensors now indicate unknown
(as opposed to previous versions). It appears that the rules for how unit_of_measurement
is handled have become more strict. Given that Template Sensors are no longer behaving like they did in the past, it’s effectively an undocumented breaking change.
opened 08:22AM - 06 May 23 UTC
### The problem
The following template sensor don't work in 2023.05 and I don't… know, whats the problem. In 2023.04 this work without any problem...
`
#Sonnenaufgang lokal Zeit
- platform: template
sensors:
sun_sonnenaufgang_local:
friendly_name: Sonnenaufgangszeit
unit_of_measurement: "h"
value_template: "{{ as_timestamp(state_attr('sun.sun','next_rising')) | timestamp_custom('%H:%M') }}"
#Sonnenuntergang lokal Zeit
- platform: template
sensors:
sun_sonnenuntergang_local:
friendly_name: Sonnenuntergangszeit
unit_of_measurement: "h"
value_template: "{{ as_timestamp(state_attr('sun.sun','next_setting')) | timestamp_custom('%H:%M') }}"
`
Look at this:
![grafik](https://user-images.githubusercontent.com/59682922/236612310-638702f0-c32f-4763-9616-8a51da2210fe.png)
and this:
![grafik](https://user-images.githubusercontent.com/59682922/236612344-ecbbd4d8-10c2-4ae1-a0d7-5d2f9c0ab3a0.png)
### What version of Home Assistant Core has the issue?
core-2023.5.2
### What was the last working version of Home Assistant Core?
core-2023.4.6
### What type of installation are you running?
Home Assistant OS
### Integration causing the issue
_No response_
### Link to integration documentation on our website
_No response_
### Diagnostics information
_No response_
### Example YAML snippet
```yaml
#Sonnenaufgang lokal Zeit
- platform: template
sensors:
sun_sonnenaufgang_local:
friendly_name: Sonnenaufgangszeit
unit_of_measurement: "h"
value_template: "{{ as_timestamp(state_attr('sun.sun','next_rising')) | timestamp_custom('%H:%M') }}"
#Sonnenuntergang lokal Zeit
- platform: template
sensors:
sun_sonnenuntergang_local:
friendly_name: Sonnenuntergangszeit
unit_of_measurement: "h"
value_template: "{{ as_timestamp(state_attr('sun.sun','next_setting')) | timestamp_custom('%H:%M') }}"
```
### Anything in the logs that might be useful for us?
_No response_
### Additional information
_No response_
Another user believes this may be the PR responsible for the new behavior (tagged as a ‘Code quality improvement’) :
home-assistant:dev
← epenet:sensor-value
opened 12:57PM - 10 Jan 23 UTC
## Proposed change
<!--
Describe the big picture of your changes here to com… municate 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.
-->
~~DO NOT MERGE BEFORE `2023.4.0dev`~~
As follow-up to #85513 and #85863, we can now validate numeric sensors
## 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)
- [x] 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]
- [ ] The code has been formatted using Black (`black --fast 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/en/development_checklist.html
[manifest-docs]: https://developers.home-assistant.io/docs/en/creating_integration_manifest.html
[quality-scale]: https://developers.home-assistant.io/docs/en/next/integration_quality_scale_index.html
[docs-repository]: https://github.com/home-assistant/home-assistant.io
1 Like
petro
(Petro)
May 11, 2023, 12:28pm
25
Right, but that doesn’t change the solution to this thread, which is what I’m referring to. If you put a unit_of_measurement on a sensor, it will turn it into a graph. The original question was “what do I place on a voltage sensor” and the answer was “v”. None of that has changed…
Also, if you output None
instead of 'unkonwn'
or 'unavailable'
in your template sensors, then you’ll avoid this strictness. That’s the proper way to set a sensor to unknown or unavailable. The other option is to use availability templates (which sets None
under the hood).
We ended up finding a series of issues in Beta with this change. Properly created template sensors would be unaffected. When you explicitly set a numeric sensor to a string state, you’ll get this error.