How can I check if a binary sensor state is generically 'on' or 'off'?

How can I create a generic check to see if any entity is on or off, regardless of its type?

Doing {% if states(entity) %} doesn’t work (always true), and {{ is_state(entity, 'on') }} doesn’t work if it’s a cover entity because it’s not on it’s open.

The closest I’ve found is {{ is_state(entity, ['on', 'open', 'detected', ..etc..]) }} but there’s a lot of states, and it’s impossible to handle any added in later versions.

I assume there’s got to be a function or something for this that I just haven’t come across?

The links you posted leads to the many device_classes for a binary_sensor but none represent different states. A binary_sensor’s nominal states are on and off exclusive of the device_class. Everything in that list simply represents how on/off is translated for display purposes in the UI only.

So if you are looking for a list of states for all entity domains, that link isn’t it and, to my knowledge, there’s no such list because there’s normally little need to gather them together.

A lock can be locked/unlocked, a cover can be open/opening/closing/closed, a device_tracker can be home/not_home, a climate entity can have several states, etc.

A binary_sensor’s nominal states are on and off exclusive of the device_class

Ah right, I am mixing up domains in my question.

Really I’m looking for the different domains and their states:

Domain Off On
automation off on
binary_sensor off on
climate off heat, cool, heat/cool, ?
cover closed open, opening, closing
device_tracker home not_home
fan ?
input_boolean off on
light off on
lock locked unlocked
media_player off buffering, playing, idle
script off on
sensor unlimited states
switch off on

there’s no such list because there’s normally little need to gather them together.

Well, it’s useful for blueprints to be able to have a selector that works with any type. I’m trying to create an event trigger that can tell ‘off’ vs ‘on’ for updating an LED state.

From this, I think the closest I can get to is going to be off, closed, locked, home vs not unknown. If that’s correct, it’s not that bad (just took a fair amount of research to figure out).

Usually a blueprint’s selector is used with the domain option to constrain the choice of domains. For example, if the blueprint’s focus is to control a lock entity then you prevent the user from selecting something else like a climate entity.

FWIW, media_player and climate have more state values then shown above and there are other domains such as person and zone.

The bool filter is able to interpret on and off as true and false. You could submit a Feature Request to have it enhanced to interpret other state values as booleans (or submit a PR in the GitHub Core repo if you have the requisite python development skills). Be advised that a Feature Request amounts to a wish and its prompt implementation is unlikely.