Units when there's none?

I encounter a problem I can’t seem to be able to solve regarding units in HA. Consider my configuration :

sensor:
- platform: systemmonitor
  resources:
  - type: packets_in
    arg: enp3s0
- platform: statistics
  entity_id: sensor.packets_in_enp3s0
  name: packets_daily
  max_age:
    days: 1
- platform: template
  sensors:
    packets_daily:
      unit_of_measurement: "" #HERE
      value_template: >-
        {{ states.sensor.packets_daily_mean.attributes.change | float }} 

I get the following result in the Lovelace UI and the history component :
44 04

I was wanting a graph of the evolution of it but apparently there’s a problem here.
I found out that if this is caused by the units not being recognized. I can eventually make this work using "°" as unit but this is very ugly. I was wanting to either use "packets" or just nothing as this value is unitless.

I couldn’t find in HA’s source code the place where the units are handled and recognized and even the list of them.

I would be very grateful for any indication of where to find more information so I can submit a fix to this.

Replying to myself for anyone encountering this issue :
The unit affectation is unregulated except for temperature so far (HA 0.8.0). The code is in sensor/template.py and helpers/entity.py for those searching.

I fixed it by putting packet as a unit.

Yeah unit_of_measurement: will take anything. I used “PF” as a unit for power factor measurement (a unit-less ratio).

2 Likes

Actually I tested more and yes they does except that history graph is still a laggy colored bar code. So there’s something wrong there. I think I will investigate and at least file a bug repport for that.

Are you sure that all updated outputs have a numerical value? Even when initializing?

1 Like

You may be right since it turned into a graph when old values went out of scope.

There’s no bug after all :slight_smile: