I have created a card with conditional visibility:
type: entity
entity: sensor.glances_process_plex_media_serv
attribute: name
icon: mdi:server
name: Plex Media Server Status
state_color: true
visibility:
- condition: state
entity: sensor.glances_process_plex_media_serv
state_not: unavailable
When the sensor is available, the card is visible, but when sensor becomes unavailable, the card is not visible. This is how the card is expected to work.
But, the problem is that if the sensor remains unavailable for a long time, like 2-3 days, the card becomes visible again with an error that entity is not available. This should not happen. The card should stay invisible if the sensor is not available, no matter for how long.
This sensor tells me if Plex process is running on the PC. I keep this PC in standby mode most of the time, so the sensor becomes unavailable. But that is beside the point. The point is that this card behavior is not expected.
From my perspective, the entity is no longer reporting a status to HA or appears disconnected. I think you are confusing the sensor’s streaming status vs the entity status with HA.
Right now it is showing as unavailable and card is not visible. This is expected behavior. This is how conditional visibility works.
At some point, if the sensor still remains unavailable, it completely disappears from HA. If I search for this sensor, nothing comes up. That is when the card becomes visible again and shows an error.
Question is:
What is the time limit after which sensor will disappear if it is not reporting any status to HA? This is how the sensor is defined:
sensor:
- platform: rest
resource: http://mypc:61208/api/3/processlist
name: Glances - Process - Plex Media Serv
json_attributes_path: '$..[?(@.name=="Plex Media Serv")]'
value_template: "Ok"
json_attributes:
- name
- status
- username
- pid
Please check the conditional visibility clause of cards. Cards with conditional visibility are visible only when the specified condition is true, Otherwise, they remain hidden. This is the documented behavior.
See the section on:
Showing or hiding a card or badge conditionally
The entity became unknown. Since you has not provided a corresponding condition, the card is shown. If you say “but it worked before!” - then I will say that there was a bug which was fixed.
Condition is right there. The condition unfortunately is a double negative, so easy to misunderstand. state_not: unavailable.
Sensor is configured in configuration.yaml file, so no matter what happens, HA should never remove it. After 24-48 hours, HA completely removes sensor.glances_process_plex_media_serv. This is the root cause of the issue. Maybe someone can explain what exactly is wrong with my card definition or sensor definition.
I tested after putting in unknown and unavailable. When the sensor is available, the card shows up. When the sensor is unavailable, the card is hidden. Now I have to wait for the sensor to completely disappear from HA and see if the card shows up with error.
If nothing resolves the issue, I will just create an automation to WoL the PC and then put it in suspend after few minutes. This will make sure that sensor is always in available/unavailable state and HA does not get an opportunity to make it disappear completely.
My suspicion is that the sensor is making frequent REST calls to the Glances web server running on PC to get Plex Media Server’s process state as JSON. Maybe there is some kind of timeout in HA that removes the sensor if REST calls keep failing for a certain time. I do not see anything in HA documentation.
Yes, adding the unknown worked. Tested just now. The sensor had disappeared from HA but the card did not show up. Then I started up the PC and card showed up. Thanks for your help.