Show "Unavailable Entity" as a static icon or image

As the topic suggests, I was wondering if there was a way to change the “Unknown Entity” to a static icon (preferably) or a static image?

Use Case: I have battery monitors that are only used when charging certain batteries not permanently connected to a charger (Car battery, spare battery etc) and just wanted a static icon to show when the node is not physically connected. Side note, these entities that go offline are volt gauges with min/max etc.

Is there a special card that can accommodate this, or maybe more importantly, can this be done?

You want to see a device / entity when it has a defined state?

Option 1: create a entity card for each entry. Card is shown when state is “unknonw in the sample below”.

type: entities
entities:
  - entity: input_button.hdmi2
visibility:
  - condition: state
    entity: input_button.hdmi2
    state: unknown

Option 2: When there are more devices you could use teh auto-entities card and search all entities in status unknown. Irrevant devices can be excluded using a dedicated label (or other way arround and include label only)

type: custom:auto-entities
card:
  type: entities
  title: Inactive
filter:
  include:
    - state: unavailable
  exclude:
    - label: Ignore_Inactive
sort:
  method: friendly_name
````

Hi thanks for the reply, but I actually just want to display an icon in place of the “Unknown Entities” box that crops up when an entity goes offline for a prolonged period of time. I just find the whole:

Unknown Entity

thing a little off-putting on an otherwise clean dashboard.

Apologies, for the misunderstanding, I do tend to be vague when explaining things sometimes.

I think what morlies is suggesting is to use visibility to show/hide what you want to see. You can hide the offending entity. You can also use another card with inverse visibility settings to display in its place. That way you can show whatever you like.

Noob question, how would I go about using “another card with inverse visibility settings to display in its place”? as that may be an option for me to display 1 or 2 sensors from another entity on the same card I don’t already have showing (If that makes any sense at all)

Depending on the layout you use and where it is in your layout, you may just be able to put both cards below each other, because you’ll only ever see one.

So it would look something like this:

          - type: tile
            entity: light.woonkamer
            visibility:
              - condition: state
                entity: light.woonkamer
                state_not: unavailable
          - type: tile
            entity: light.eetkamertafel
            visibility:
              - condition: state
                entity: light.woonkamer
                state: unavailable

Oh, excellent, would this also work with a gauge card (Just the standard card that HA gives you as default)? Like the example bellow:

  - square: false
    type: grid
    cards:
      - type: gauge
        entity: sensor.bm1_bus_voltage
        name: BM1 Bus
        min: 11
        max: 14.6
        severity:
          green: 12.3
          yellow: 12.03
          red: 10
      - type: gauge
        entity: sensor.bm2_bus_voltage
        name: BM2 Bus
        min: 11
        max: 14.6
        severity:
          green: 12.3
          yellow: 12.03
          red: 10

Or would I need a specific type of card for this?

Apologies for all the questions, but the dashboard is not even remotely something I am comfortable writing code for as it always kicks my butt.

Edit: Also, what happens in the case with your scenario, where both entities are actually available, would this not cause problems which one it displays, or would the first card then take precedence?

  - square: false
    type: grid
    cards:
      - type: gauge
        entity: sensor.bm1_bus_voltage
        visibility:
          - condition: state
            entity: sensor.bm1_bus_voltage
            state_not: unavailable
        name: BM1 Bus
        min: 11
        max: 14.6
        severity:
          green: 12.3
          yellow: 12.03
          red: 10
      - type: gauge
        entity: sensor.cottage_bed_daily_energy
        visibility:
          - condition: state
            entity: sensor.cottage_bed_daily_energy
            state: unavailable
        name: Bed Daily
        min: 0
        max: 32
        severity:
          green: 0
          yellow: 28
          red: 30
      - type: gauge
        entity: sensor.bm2_bus_voltage
        visibility:
          - condition: state
            entity: sensor.bm2_bus_voltage
            state_not: unavailable
        name: BM2 Bus
        min: 11
        max: 14.6
        severity:
          green: 12.3
          yellow: 12.03
          red: 10
      - type: gauge
        entity: sensor.cottage_bed_total_wh
        visibility:
          - condition: state
            entity: sensor.cottage_bed_total_wh
            state: unavailable
        name: Bed Total
        min: 0
        max: 45
        severity:
          green: 0
          yellow: 40
          red: 42

Have this thus far, but the unavailble entities are not hidden as expected

You want to set a default value or placeholder when your sensor is offline.

I would create a template sensor for your dashboard. The template sensor has the same value when the original is online. Otherwise set a default value like “offline”, “0” or whatever you prefer.

I don’t want to steal recognition. Check that thread, probably it helps. Check the post which is marked as solution.

Another idea … only thinking loud … what is your underlaying protocol? Is it MQTT? If yes, you could set a retain and/or LWT message.

I’m afraid you are heading into turbulent waters here with template sensors etc lol, I manage to scrape by with the bare minimum on HA, so templates have not even been touched by me yet. I am currently just using HA raw with it’s own sql, no MQTT.

I think I may just rethink my strategy here, as I was hoping it would be as simple as:

      - type: gauge
        entity: sensor.bm1_bus_voltage
        visibility:
          - condition: state
            entity: sensor.bm1_bus_voltage
            state_not: unavailable
        name: BM1 Bus
        min: 11
        max: 14.6
        severity:
          green: 12.3
          yellow: 12.03
          red: 10
      - type: picture
        visibility:
          - condition: state
            entity: sensor.bm1_bus_voltage
            state_not: unavailable
        image: https://demo.home-assistant.io/stub_config/offline.png
  

type of thing :confused:

I don’t know what sensor or implementation you are using. But when it’s MQTT you should check on your device if you have the option to set retain flag or LWT.

The technical background, retain means, the last message is kept in the queue and HA shows the last update but entity is still available.

LWT means “last will and testament” - > when a sensor (actor) goes offline in a planned way like a shutdown it sends a message which is kept and HA knows that it’s offline but still exists.

You need to check the implemention or documentation. I assume it’s described and covered somehow.

Sorry, I did mention I am not good at explaining.

I do not have MQTT, I only have HA’s sql that comes with Home Assistant (Changed my previous comment to state this, as I saw where the confusion I created came from).

For now I think I need to just live with the Unavailable Entity thing, until I have progressed far enough to actually start making templates etc (it’s been a real learning curve as it is, having no past experience in coding, so you can imagine the fun I had with all the nodes).

Thank you anyway, for your time trying to help. :smiley:

I miss-read, my bad. I started a few weeks back but I’m a developer in real life so that’s not a problem for me.

Do some testing and define what’s important. When you are familiar with the architecture throw away your playground and start from scratch. Probably the issue solves by itself …

1 Like

It will work with any card. Visibility options are quite new, some places it does not work yet, if not you can use a conditional card and put the card you want to hide in it.

As for two available entities: you asked for putting another entity in place if the first one is unavailable. So I made them look at the same entity. If you let each one look at their own availability, both might show, or both might disappear. If you build the view right, that may also look nice.

1 Like

I honestly doubt you miss-read, as I mentioned, I have a bad habit of explaining things terribly :/.

There’s so much going on in my HA currently, that I would dread starting from scratch, but yes, I do understand your reasoning behind that remark, it would actually benefit me, if I eventually did that, just in terms of getting rid of bad code/habits lol.

Thanks, I will give that a go later on :+1:

I think I did find a place it doesn’t work (Gauges) but I’ll verify my suspicions later tonight, thanks for the tip.

Gauges is not a place, but a card type. But where you want to put it matters a bit. But regardless, place a conditional card where you want the gauge, then inside that, put the gauge. The effect is the same.

Thanks Edwin, will give that a go :+1:

Edit. I’m missing something obvious here, the code I have for the 2 conditional cards are to only show the card when the state is Not unavailable. It seems that whether I change this to the normal state or state not, the gauge just keeps being displayed.

I did notice that while I was moving the 2 cards to the front of the que where the current gauges were (With the arrows left and right in the card while under edit), it would vanish for a split second and then re-appear

  - square: false
    type: grid
    cards:
      - type: conditional
        conditions:
          - condition: state
            entity: sensor.bm1_bus_voltage
            state_not: unavailable
        card:
          type: gauge
          min: 11
          max: 14.6
          severity:
            green: 12.3
            yellow: 12.03
            red: 10
          entity: sensor.bm1_bus_voltage
          name: BM1 Bus
      - type: conditional
        conditions:
          - condition: state
            entity: sensor.bm1_bus_voltage
            state: unavailable
        card:
          type: picture
          alt_text: Offline
          tap_action:
            action: none
          hold_action:
            action: none
          image: /api/image/serve/f364607b60bbc14a4b7b0e094175a2ef/512x512
      - type: conditional
        conditions:
          - condition: state
            entity: sensor.bm2_bus_voltage
            state_not: unavailable
        card:
          type: gauge
          entity: sensor.bm2_bus_voltage
          name: BM2 Bus
          min: 11
          max: 14.6
          severity:
            green: 12.3
            yellow: 12.03
            red: 10
      - type: conditional
        conditions:
          - condition: state
            entity: sensor.bm2_bus_voltage
            state: unavailable
        card:
          type: picture
          alt_text: Offline
          image: /api/image/serve/3eacf16b1952b2b1da99ca74079d8680/512x512
      - type: gauge
        entity: sensor.cottage_bath_bus_voltage
        name: Bath Bus
        severity:
          green: 12.3
          yellow: 12.03
          red: 10
        min: 11
        max: 14.6
      - type: gauge
        entity: sensor.cottage_bed_bus_voltage
        name: Bed Bus
        min: 11
        max: 14.6
        severity:
          green: 12.2
          yellow: 12.03
          red: 10
      - type: gauge
        entity: sensor.cottage_bed_current
        name: Bed Amp
        min: 0
        max: 0.18
        severity:
          green: 0
          yellow: 0.12
          red: 0.15
      - type: gauge
        entity: sensor.cottage_bed_total_ah
        name: Bed Consumed
        min: 0
        max: 4000
        severity:
          green: 0
          yellow: 3200
          red: 3600
    columns: 3
columns: 1

Edit. Edit. Never mind, I was being a putz, it works, thanks Edwin and Herbert :slight_smile:

It does leave gaps where the cards were, however, this is still better than showing a block with “This entity is unavailable”

After a bit of fiddling:


Thanks for bearing with me

1 Like