home-assistant / frontend

:lollipop: Frontend for Home Assistant
https://demo.home-assistant.io
Other
3.95k stars 2.67k forks source link

Conditional card: if an entity is "unknown" - it is treated as "unavailable" (same about visibility) #21381

Open ildar170975 opened 2 months ago

ildar170975 commented 2 months ago

Checklist

Describe the issue you are experiencing

A non-existing entity has unknown state: image

Consider this code:

type: vertical-stack
cards:
  - type: conditional
    conditions:
      - condition: state
        entity: sun.su
        state: unavailable
    card:
      type: entity
      entity: sun.sun
  - type: conditional
    conditions:
      - condition: state
        entity: sun.su
        state_not: unavailable
    card:
      type: entity
      entity: zone.home

which shows this card: image

But the state is not unavailable - it is unknown. Then why the 1st condition is true?

Describe the behavior you expected

unknown should not be treated as unavailable

Steps to reproduce the issue

as above

What version of Home Assistant Core has the issue?

2024.7.1

What was the last working version of Home Assistant Core?

No response

In which browser are you experiencing the issue with?

Chrome 126.0.6478.127

Which operating system are you using to run this browser?

Win10x64

State of relevant entities

No response

Problem-relevant frontend configuration

No response

Javascript errors shown in your browser console/inspector

No response

Additional information

No response

ildar170975 commented 2 months ago

And compare with visibility options where unavailable & unknown are different cases - and anyway treated same way:

type: entity
entity: sun.sun
visibility:
  - condition: state
    entity: sun.su
    state: unavailable

image

image

If unknown is selected:

type: entity
entity: sun.sun
visibility:
  - condition: state
    entity: sun.su
    state: unknown

and the card is NOT shown - although it should be shown.

karwosts commented 2 months ago

Guess your issue probably comes from here. In conditional card validation logic an entity that does not exist is assumed to have state UNAVAILABLE. Perhaps that's not correct.

https://github.com/home-assistant/frontend/blob/db314522d78d3eb2277a0e22ad7abc7e816b02e8/src/panels/lovelace/common/validate-condition.ts#L77-L80

ildar170975 commented 2 months ago

In conditional card validation logic

Is same logic used for a visibility? Because it is buggy too.

karwosts commented 2 months ago

I would assume it is the same, but didn't check.