Ignore unknown or unavailable last changed values?

Hey Everyone!

I have the “last changed” secondary information value displayed for a few of my listed entities. However, if I reboot Home Assistant (system update) or reboot my router (just because), there is now a gap placement value of “unknown” or “unavailable” inserted for that entity which causes the “last changed” value to use when calculating the duration.

Is there a system setting or something else I can easily set to ignore all of the “unknown” or “unavailable” entity state gaps and always calculate from the previously changed available “live” state?


Thanks and have a great day!

Use template in automation trigger

In automation trigger and condition

For anyone seeing this tread

Now we have has_value as template function

2 Likes

Sorry still trying to work out how to get this logic into an entity-filter dashboard whete I show secondary_info of whats playing on Plex, but the metadata often comes up with one of the fields as “unknown”. I just want the word to dissapear:

- entity: media_player.living_room_tv_shield_2
    attribute: message
    type: custom:secondaryinfo-entity-row
    secondary_info: >-
      <i>[[ sensor.living_room_shield_source ]]</i><br> <i>[[
      sensor.living_room_shield_media_artist ]]<br> [[
      sensor.living_room_shield_media_title ]]</i>
    apps:
      com.plexapp.android: Plex

you can probably just use the replace command

For example here is template sensor that replaces the actual state with other words. Just apply that logic to your shield input sensor.

sensor:
  - platform: template
    sensors:
     fan_direction_test:
       friendly_name: "Fan Direction Test"
       unique_id: fantest
       value_template: |
         {{ state_attr('fan.bedroom_fan', 'direction') | replace ( "forward", "yup")| replace ("reverse", "yup yup")}}    

Thanks for this I’ll try it. Does this go in my configuration.yaml or in the dashboard YALM itself under the - entity ? I’m confused, I think the secondary_info i’m surfacing on my dashboard are in fact attributes, so will this till work?

if it’s secondary info on the card you can still use this code. I was focusing on the code not the my code location.

secondary: |
  {{ state_attr('fan.bedroom_fan', 'direction') | replace ( "forward", "yup")| replace ("reverse", "yup yup")}}