Add Sensor state type #503
-
ContextFor Sensor Entity I can specify unit by ProposalAdd |
Beta Was this translation helpful? Give feedback.
Replies: 21 comments 4 replies
-
|
For Home Assistant itself, that makes no sense. If there isn't a unit to measure, what would it measure? Could you provide a more concrete example that justifies such a change? |
Beta Was this translation helpful? Give feedback.
-
|
It might be related to this: home-assistant/frontend#6453 A numeric counter is currently rendered in the HA frontend not as a line graph but as a state bar. |
Beta Was this translation helpful? Give feedback.
-
|
Well in the linked case, the unit of measurement should be added (not a UI fix), so that issue is actually in the wrong repository at this moment. |
Beta Was this translation helpful? Give feedback.
-
|
I quite like the proposed idea there that the frontend defaults to "#" if no unit is provided, because for a counter for example I don't want a unit. It should just count. |
Beta Was this translation helpful? Give feedback.
-
|
I add workaround with customization and unit of " " (space), but everytime I do it I feel it's something wrong with that approach ;-) |
Beta Was this translation helpful? Give feedback.
-
|
@spacegaier I do not agree. Defaulting to |
Beta Was this translation helpful? Give feedback.
-
|
In my case is sensor value is result of equation defined by user. But I can imagine other cases. For example, the number of visitors. |
Beta Was this translation helpful? Give feedback.
-
|
@martindybal "visitors", "people" or "persons" sound like a viable unit of measurement for those cases. Any reason why it could not be that? |
Beta Was this translation helpful? Give feedback.
-
|
Sorry I was too slow with my response. In my case is result of equation I can use workaround " ". |
Beta Was this translation helpful? Give feedback.
-
UI doesn't handle that well all the times, especially if in native language that can be longer word.. |
Beta Was this translation helpful? Give feedback.
-
|
I confirm that workaround works for me. |
Beta Was this translation helpful? Give feedback.
-
@frenck That would look weird in the UI: E.g. an entity row: You have a counter named "Visitors today" and then the value is "3 visitors"? That is redundant and requires for screen space than needed to convey the info to the user. But I get your point about not making assumptions, but I think we should then have a way to tell HA that a sensor is numeric, but does not carry any further unit text, so that users do not have to use empty units which feels error-prone. Which brings us back to the original proposal from OP to allow "int" or perhaps more generic "number" or "#" as valid units in the backend. Then the HA frontend can use that to decide if a graph should be shown. And it might also help with external rendering integrations, such as Grafana, where I remember also seeing issues on GitHub if no unit was present. |
Beta Was this translation helpful? Give feedback.
-
|
Stays the same, You can specify |
Beta Was this translation helpful? Give feedback.
-
|
This is related: #469 There are cases for no unit... |
Beta Was this translation helpful? Give feedback.
-
|
My Sensative Strip device defines 6 sensor entities without units (mirroring what's exposed in the zwave protocol) and i don't see how they could be given reasonable units. Is anyone arguing that those sensors should be defined differently? |
Beta Was this translation helpful? Give feedback.
-
|
COP of heat pump is also without unit: https://en.wikipedia.org/wiki/Coefficient_of_performance |
Beta Was this translation helpful? Give feedback.
-
|
I think this would be a good change, there are many examples of unitless quantities, and we shouldn't rely on the unit being a non-empty string to decide if the sensor's data should be rendered as a line graph or not. Strictly speaking I'm not sure we should have a |
Beta Was this translation helpful? Give feedback.
-
|
I think the biggest feeling against this for me personally, is not caused by the reason for this proposal. The reason is to have graphed data, even if there is no unit of measurement set. 👍
👎 That is what buggers me. The point is, is what we basically are doing here is compensating for the fact state is always a string; thus storing the scalar type of separately (instead of using actual types). Although it is a quick/fast solution for the problem at hand maybe... It becomes even weirder considering state attributes do have a type (they can be a native int for example). |
Beta Was this translation helpful? Give feedback.
-
|
I wonder if the title of this issue/discussion already solutionizes for a problem that was not properly understood. Looking around I found quite a few tickets and discussions about the topic. They are mostly related to
I think this discussion goes beyond the most prominent side-effect, the line/discrete graph. The problem is often discussed and people add the " " space unit as a hack but the underlying issue is that the UI currently does not have a better way to identify continuous measurements. ProposalHere are two alternative suggestions:
I hope this is helpful and am looking forward to discuss! |
Beta Was this translation helpful? Give feedback.
-
|
I would propose a The core could set it bases on the current properties we already have |
Beta Was this translation helpful? Give feedback.
-
|
We are currently introducing |
Beta Was this translation helpful? Give feedback.
We are currently introducing
state_class(for e.g., the energy dashboard and statistics) which already indicates if something is a measurement. This will become the base for solving this issue in the near future.