Where can we find the available device_classes?

Trying to find out a device_class for a time related template sensor, I am unable to find the available options. https://www.home-assistant.io/components/binary_sensor/#device-class lists the binary_sensors, and so does the source code for binary_sensor on https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/binary_sensor/init.py but they don’t list eg device_class: timestamp, which is use in the googlehome component.

found also this in the Sensors source https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/sensor/init.py listing the timestamp, and the classes for Cover on https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/cover/init.py

Which should then be the complete listing of classes for sensor, binary_sensor and cover?

Now how could I ask the devs if an ‘unknown’ state for device_class: timestamp could be displayed as ‘not set’ instead of the currently showing ‘Invalid date’…

1 Like

Are you looking for this?

1 Like

well not really, that page is rather lacking on info on the available device_classes…I think Ive listed the available ones in the source code for those components, though am not sure if that is complete.

Im struggling with the device_class: timestamp, showing an ugly state for my alarms, when not set. If the alarm is set, it shows a beautiful ‘in xx minutes’, and even counts down the final minute, and first minute past the alarm. If not set, the state is unknown, and consequently shows ‘Invalid date’. Which is silly, because it should simply state ‘Not set’…

I think you are looking for this:


Which then leads to 3 sub pages.
2 Likes

please check this What's this timestamp/string? for some background on the issue Im trying to solve

Either there is no timestamp or the documentation is incomplete. I generally feel the docs are VERY confusing. Always looking for properties or functions but i never find a clear and good documentation for them.

For example device_class should be a type/enum which has its own site showing all possible values. Same for functions like state_attr(), is_state_attr etc.

5 Likes

If you want to improve the docs, the source is available on Github for editing.

2 Likes

Here’s the device_class documentation for:

I compared each documentation page to the corresponding component’s source code and it’s all up to date. The timestamp device_class is part of the sensor component.

You’re looking for the Templating page.

9 Likes

Bosbofne im not even close enough in the code to write any documentation.

123 Nope i know this page, still its a struggle. Look at Angular API docs for example: You can click on functions and types and they will lead you to separate pages explaining every little detail of inputs and outputs and example usage. On Home Assistant it is just searching, not finding answers and guessing.

2 Likes

It’s seven bullet items about state.

  • The first three describe state.

  • The remaining four describe functions you can use with state.

I fail to see how that’s ‘a struggle’. Nevertheless, it’s community-run project, the docs are in Github, so if you want to enhance them, you can.

2 Likes

ok, thnks, I guess we can assume all device_classes are described then, as I hoped to have found and shared in my first post, and @123 re-listed above.

now how would we have to go about changing the outcome of the timestamp device_class. It is programmed to be ‘unknown’ if not set, and then the frontend translates that to ‘Invalid date’.
Imho that is rather unfortunate, because, as in my case when used on several timer and alarm sensors, shows a list of ‘Invalid dates’ while they are simply not set.

27

Before, we could customize that using @andrey s custom-ui using _stateDisplay, but that has been deprecated unfortunately.

as tried in this topic ( see the test template in the screenshot) I’ve tried to mimic the device_class using a rather large template sensor, but that only is successful halfway. (the original timestamp has a very nice last minute countdown per second, and also displays how much time has passed since the set alarm.

really only need the ‘Not set’ to be changed…

So I figure the only thing left is a PR on that device_class?

Well, not just ‘re-listed’.

Your topic title asks “Where can we find the available device_classes?” and several people replied, directing you to the documentation. I did as well, plus I also compared the code to the documentation and confirmed it is correct.

In addition, you stated the timestamp class was ‘not listed’, based on binary_sensor code. I explained it is listed as a sensor class . So 90% of your first post was answered/clarified/corrected. That’s much more than simply having ‘re-listed’ what you wrote.

The final question in your first post is effectively a Feature Request. I agree with you that displaying an unknown date as Invalid date is undesirable. I would vote for a Feature Request to have it display Unknown which more accurately reflects the situation.

So I figure the only thing left is a PR on that device_class?

Yes, as a Pull Request if you wish to submit code modifications/enhancements. Otherwise, this is a Feature Request (which are not accepted in the Github repo). If you believe it’s a bug, then it can be submitted as an Issue. I’d say this is a ‘cosmetic bug’ (wrong label) and submit it as an Issue.

2 Likes

ok cool, and appreciated, as always!

to even be able to try a PR, I would need to know how these device_classes work, or are programmed. The source codes we discussed above don’t show that don’t they?
I mean where are the icons and states described, which replace the default on/off icons and states.

That must be done in some other HA source file, but havent found that yet.

really sorry you feel like I have been complaining about the documentation. Never had the intention to do so. Added to that, I always try to be as complete as possible so others can take advantage of that, if and when they are looking for answers to shared issues.

Please refrain from judging and blaming others.
Makes this community so much more enjoyable.
thanks.

3 Likes

Here you’ll find a list:

8 Likes

Came across this old thread when looking the supported values for device_class in configuration.yaml … perhaps Sensor - Home Assistant?

(So so difficult to find … I’m don’t think there’s any reasonable way to find it by clicking through the website.)

When I tried using ‘battery_charging’ or ‘plug’ in my configuration.yaml for a sensor within mqtt I received an error message which included the list of expected device_class values:

  • ‘date’,
  • ‘enum’,
  • ‘timestamp’,
  • ‘apparent_power’,
  • ‘aqi’,
  • ‘atmospheric_pressure’,
  • ‘battery’,
  • ‘carbon_monoxide’,
  • ‘carbon_dioxide’,
  • ‘current’,
  • ‘data_rate’,
  • ‘data_size’,
  • ‘distance’,
  • ‘duration’,
  • ‘energy’,
  • ‘energy_storage’,
  • ‘frequency’,
  • ‘gas’,
  • ‘humidity’,
  • ‘illuminance’,
  • ‘irradiance’,
  • ‘moisture’,
  • ‘monetary’,
  • ‘nitrogen_dioxide’,
  • ‘nitrogen_monoxide’,
  • ‘nitrous_oxide’,
  • ‘ozone’,
  • ‘ph’,
  • ‘pm1’,
  • ‘pm10’,
  • ‘pm25’,
  • ‘power_factor’,
  • ‘power’,
  • ‘precipitation’,
  • ‘precipitation_intensity’,
  • ‘pressure’,
  • ‘reactive_power’,
  • ‘signal_strength’,
  • ‘sound_pressure’,
  • ‘speed’,
  • ‘sulphur_dioxide’,
  • ‘temperature’,
  • ‘volatile_organic_compounds’,
  • ‘volatile_organic_compounds_parts’,
  • ‘voltage’,
  • ‘volume’,
  • ‘volume_storage’,
  • ‘volume_flow_rate’,
  • ‘water’,
  • ‘weight’,
  • ‘wind_speed’

Which matches the list in the documentation, here: Sensor - Home Assistant

1 Like

Go to integrations, type the domain you’re looking for, select it. boom list of device_classes.

If you don’t see a list, that domain doesn’t support them. Try it with the binary_sensor domain. You’ll see it’s quite easy to find.