Show entity in view, only when conditions are met

As the tittle says, I am looking for a way to show some entities only when some conditions are met.
For example, if KODI is ‘off’ then dont show media player in the view.
I actually want it to work like the known_devices.yaml where this applies:

  hide_if_away: true

But I want it to work for any entity I want and also for any state I want.

that would work with an automation
here is an example from my config where I only show the Xmas group when it’s Xmas time:

- alias: HASS Start Xmas Setup
  trigger:
    - platform: homeassistant
      event: start
  action:
    - service: group.set_visibility
      entity_id: group.xmas
      data:
        visible: False
    - condition: template
      value_template: '{{ (as_timestamp(now()) -(states.input_datetime.xmas_start.attributes.timestamp | default(0)) | int > 0)}}'
    - condition: template
      value_template: '{{ ((states.input_datetime.xmas_end.attributes.timestamp | default(0)) | int ) - as_timestamp(now()) >0 }}'
    - service: input_boolean.turn_on
      data:
        entity_id: input_boolean.xmas
    - service: group.set_visibility
      entity_id: group.xmas
      data_template:
        visible: >
          {% if is_state("input_boolean.xmas", "on") %}True
          {% else %}False
          {% endif %}
1 Like

That is a great idea. I didnt know you can hide or show groups by using a service!
Ok, if you dont mind, I have some questions about your automation. Please bear with me!

  • You are triggering it when HA starts. Why not trigger with the time?
    Doesnt that mean:HA starts=true then check datetime then if xmas then show xmasgroup?
    Why not when datetime=xmas>show xmasgroup?

  • As I said I want to hide or show entities. One of my examples is the Mediaplayer entity. When KODI is OFF then I want to hide the entity from the view tab.
    Is it possible to do this with only an entity? Not the entire group.

Thank you for the idea by the way.

no worries :slight_smile:
so for your first question, the reason I do it at HA start is that doing it at datetime=xmas will only trigger at that specific time. When starting HA, entities are either shown or hidden by default (depending on config) and I don’t want to edit my config based on time of year :wink:

I’m not sure you can set visibility at entity level, I think it’s only for groups, but nothing stops you from creating a group with only your media player in it…

2 Likes

I have a question. Can i make it the entity

type: sensor
entity: sensor.redminote13_battery_level
graph: line

in this code so whatever account is viewing (or what device) shows?