Unit_of_measurement variants lacks "Packets" and maybe some other networking units

Hello!
The short:
It would be nice to see “Packets” and maybe “Frames” added to the list of possible Data units/Information units.

The long:
I have a tool that query throughput of interfaces and specific firewall rules activities on my MikroTik router and pushes this JSON-ed data into MQTT.
The data pair for each of measured entities is the number of bytes and packets passed through.
What I see is there are Byte-based values only for the “data_size:”, but upon playing with the YAML templates I found that there is nothing close to the network data packet unit.
Topics are not persistent, so if there are gaps in data, the traffic monitoring in history cards is prone to switch to enumeration-based striped lines graphs, because of “unavailable” or similar, non-numeric state.
Also the statistics card does not allow such unit-less entities to be selected.

So the minimum, “Packets” will the working solution for this, and “Frames” will be nice if someone will want to monitor low-level stuff.

Thanks!

Aren’t you free to define any arbitrary unit_of_measurement you want? I thought any string was valid.

Well, for example, device_class: should be accompanied with specific unit_of_measurement or HA will complain at you.
And there is just two device_class for data: data_rate and data_size.
Unfortunately both are not quite fit for the proposed feature as I see.

Anyway, I looked at the HA code and in the const.py there are a lot of these very specific strings as enumerations. Whether they could be used to display accurately scaled graphs for different units (say kilo and mega on the same diagram) I don’t know.

Here I assume that arbitrary unit could be added to the list without too much problems.
But again it could broke the consistency across the existing device class list of accepted values.

Leave the device_class at none, and you can add any unit_of_measurement you want. Then just change the icon.

1 Like

Any suggestion for integrations that demand specific device classes?

You can make template sensors, customize.yaml, or write up an issue against the integration that isn’t providing a device_class.

Sorry, let me back up a moment because I didn’t explain sufficiently.

Problem: some device_class require specific unit_of_measurement or HA will complain.
Solution: leave device_class at None so you can use the unit_of_measurement you want.
Problem: some integrations demand a specific device_class.
Solution: ???

What integration demands a device class?

energy, generic_hygrostat, generic_thermostat, mold_indicator… there’s probably others.

All those device classes have proper units of measurement. Can you explain your actual problem because it is sounding like an xy problem, maybe we can help you tackle it.

All of those integrations require known unit of measurements for calculations.