Chromecast integration in Home Assistant is nice but it is annoying having the cards left there when the device is offline. This especially gets bad once you have more than one device:

So to fix this issue we will be using Node-RED to do the visibility toggling. Node-RED is just an alternative to using Home Assistant's built in automations.yaml file. It is flow based and makes automations way easier to setup as well as giving more options over the built in system. I build all my automations inside of it.

You will need the node-red-contrib-home-assistant-websocket package installed and configured in Node-RED to have it communicate with Home Assistant.

In order to hide Unavailable Chromecast's we need each Chromecast in it's own group inside of groups.yaml like this:

living_room_tv:
  name: Living Room TV
  view: false
  entities:
  - media_player.living_room
master_bedroom_tv:
  name: Bedroom TV
  view: false
  entities:
  - media_player.bedroom

Now that we have each Chromecast media_player in it's own group we can add those new groups to the default_view group. This will get them to show up on the front page of the HA. Here is an example:

default_view:
  view: true
  name: default_view
  icon: mdi:home
  entities
  - group.living_room_tv
  - group.master_bedroom_tv

Now you can reload the groups without having to restart Home Assistant by navigating to Configuration -> Server Control -> Reload Groups. Now you should be able to see each of your Chromecasts on the front page of Home Assistant.

Here is the flow I am using in Node-RED to accomplish hiding/showing my living room and bedroom chromecast devices:

[{"id":"b33bb2d8.d0f29","type":"server-state-changed","z":"ff717302.0c688","name":"","server":"233a9c63.e2baf4","version":"1","entityidfilter":"media_player.bedroom","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":410,"y":2720,"wires":[["990abb7e.29f9c8"]]},{"id":"b2c686e0.a70328","type":"api-call-service","z":"ff717302.0c688","name":"group.master_bedroom_tv hidden","server":"233a9c63.e2baf4","service_domain":"group","service":"set_visibility","data":"{\"entity_id\":\"group.master_bedroom_tv\",\"visible\":false}","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":940,"y":2760,"wires":[[]]},{"id":"20d20c58.713bf4","type":"api-call-service","z":"ff717302.0c688","name":"group.master_bedroom_tv visible","server":"233a9c63.e2baf4","service_domain":"group","service":"set_visibility","data":"{ \"entity_id\": \"group.master_bedroom_tv\", \"visible\": true }","mergecontext":"","x":940,"y":2720,"wires":[[]]},{"id":"10197a6b.2a97c6","type":"server-state-changed","z":"ff717302.0c688","name":"","server":"233a9c63.e2baf4","version":1,"entityidfilter":"media_player.living_room","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":420,"y":2820,"wires":[["877d0a50.ad4798"]]},{"id":"877d0a50.ad4798","type":"switch","z":"ff717302.0c688","name":"switch on/off","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"unavailable","vt":"str"},{"t":"eq","v":"unavailable","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":2840,"wires":[["6f74c85b.daa588"],["c97fe994.e883b8"]]},{"id":"c97fe994.e883b8","type":"api-call-service","z":"ff717302.0c688","name":"group.living_room_tv hidden","server":"233a9c63.e2baf4","service_domain":"group","service":"set_visibility","data":"{ \"entity_id\": \"group.living_room_tv\", \"visible\": false }","mergecontext":"","x":920,"y":2860,"wires":[[]]},{"id":"6f74c85b.daa588","type":"api-call-service","z":"ff717302.0c688","name":"group.living_room_tv visible","server":"233a9c63.e2baf4","service_domain":"group","service":"set_visibility","data":"{ \"entity_id\": \"group.living_room_tv\", \"visible\": true }","mergecontext":"","x":920,"y":2820,"wires":[[]]},{"id":"52b5bbeb.2c79c4","type":"comment","z":"ff717302.0c688","name":"Hide/Show Chromecast In Home Assistant","info":"","x":580,"y":2660,"wires":[]},{"id":"29cc029a.f3ad0e","type":"api-current-state","z":"ff717302.0c688","name":"","server":"233a9c63.e2baf4","version":"1","outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"media_player.bedroom","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":410,"y":2760,"wires":[["990abb7e.29f9c8"]]},{"id":"69c6ff92.4667","type":"api-current-state","z":"ff717302.0c688","name":"","server":"233a9c63.e2baf4","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"media_player.living_room","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":420,"y":2860,"wires":[["877d0a50.ad4798"]]},{"id":"990abb7e.29f9c8","type":"switch","z":"ff717302.0c688","name":"switch on/off","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"unavailable","vt":"str"},{"t":"eq","v":"unavailable","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":2740,"wires":[["20d20c58.713bf4"],["b2c686e0.a70328"]]},{"id":"39a7d6aa.e2ceba","type":"catch","z":"ff717302.0c688","name":"entity not found","scope":["69c6ff92.4667"],"uncaught":false,"x":700,"y":2880,"wires":[["c97fe994.e883b8"]]},{"id":"c17941a7.9138f","type":"catch","z":"ff717302.0c688","name":"entity not found","scope":["29cc029a.f3ad0e"],"uncaught":false,"x":700,"y":2780,"wires":[["b2c686e0.a70328"]]},{"id":"de377922.705de8","type":"inject","z":"ff717302.0c688","name":"every 60 seconds","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":true,"onceDelay":0.1,"x":130,"y":2800,"wires":[["29cc029a.f3ad0e","69c6ff92.4667"]]},{"id":"233a9c63.e2baf4","type":"server","z":"","name":"Home Assistant","legacy":true,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

There is basically 3 inputs:

  • inject node timer that fires every 60 seconds to check if Chromecasts visibility should be toggled (increase interval if you don't need it this intense)
  • state_changed node for firing whenever the state changes
  • catch node for catching "entity not found" errors from the timed check. This will happen if the device hasn't been detected yet in Home Assistant. Without this node a red card would display showing an error message.

It should be pretty easy to see what you have to duplicate to add another Chromecast. If you do have any questions about this feel free to leave a comment.

And that is it! I hope this helps others out. It's really nice to keep my home page for HA somewhat clean with only active devices displaying. I was using the device_tracker component for a while to do this triggering (would basically just check to see if it was connected to my WiFi). I kept having issues with my Ubiquiti AP staying connected to Home Assistant so I decided to just use the information Chromecast provides to HA instead.

Please leave a comment if this helped you in any way or if you have a better way of doing this. I really do love to hear back from my readers.