How to use "unavailable" as a trigger/status

So I thought I had stumbled onto an easy tv status fix using a chromecast device, but can’t seem to figure it out.

For my main TV I found the specific IR code to turn OFF the tv only. So when I run my “good bye” routine, if the tv is off it stays off, if it is on, it turns off. Exactly what I want.

I use a 2nd smaller TV, call it my monitor. That is where I have my cam live feeds and sometime stream to it via a chromecast. There is no dedicated OFF IR code, so same code turns tv on and tv off. But home assistant only knows the correct state if I use HA to turn on and off the tv.

I didn’t plan to integrate chromecast onto HA, but it found it itself, and with one or two clicks it integrated. I noticed when tv is off, chromecast is unavailable (it pulls the 5v from the USB from the TV). When TV is on, chromecast has a status of on or off.

When trying to set up automation, I am able to pull it up as a device and use the “status” to trigger an event, but the only status I have access to are on or off.

I am trying to set up an automation or script, that when the chromecast is “unavailable”, it would set the monitor status to “off” (chromecast is only available when monitor is on), and well when chromecast is available, for the monitor status to be “on”, even though the chromecast itself might be “off”, but “available/connected”

Is it possible? Pretty sure it logs the time the chromecast is “unavailable”, so there should be a way to access that to trigger an event no?

Why not power the ChromeCast from it’s own supply so it stays on and then get it to control the TV via CEC?

Short answer? Cause not really sure what CEC is. Pretty sure it has to do with chromecast controlling the tv via the HTLM. For example I might be on input 1 watching my cam feeds, but when I stream something to chromecast, chromecast changes the tv to input 3, and starts streaming.

Assuming I was to learn how to use CEC, would I be able to use CEC to determine if the TV is on or Off? Would it update automatically or would a script have to run? For example, if a turn on the TV a few seconds later chromecast shows as available. does CEC work the same way, or would I have to set up a script to run every x amount of seconds to check the tv status via CEC?

It seems if I was able to use the unavailable state of chromecast to trigger an event, it would be easy peacy. When unavailable true, monitor status off, when unavailable false, monitor status on

correct

not sure, I haven’t played with it in HA yet, but I’m playing to soon in the hope to control an old non-smart TV

I see, so you are on the same boat as me right? I am no expert, but I do know a bit about programming, IT, networks, etc. For me it is not a HUGE deal to have the correct state of my monitor TV update on HA, but would be a nice plus.

Obviously something is tracking the unavailable status of the chromecast, my guess is that it shouldn’t be hard to use that status as a trigger somehow. I would even bet 100 Mexican pesos that the access to that status is already available, I just don’t know how to access it

You can definitely get the ‘unavailable’ status.
image

You could you the command line platform.

Just ping the chromecast. Havent tried it but i dont see why it wouldnt work.

That is what I mean, something is tracking weather chromecast is on, off, or unavailable. (Available is not an option).

If I go to the automation section, it allows me to use “on” or “off” as a trigger, but I don’t get the option to select if “unavailable” then. It seems it should be a given that you should be able to use that trigger for an event.

Something in HA is keeping track of when the chromecast connects to the internet, and when it disconnects. Ideally I would like to piggy back on that, so that when chromecast changes into unaviable, or out of unavailable, an event is triggered.

Again, what I want to do seems so straight forward, that I am pretty sure it can already be done; I just don’t know how.

1 Like

Which version of ha are you using. In 0.111, i can set the status by typing, not selecting options

Anand, I am guessing there are different work arounds. Like you mentioned a script could be set up to ping the chromecast, if it hits, its on, if it doesn’t its off. But now I am adding an additional task that would run I don’t know, once a minute, once every two minutes?

But there is already something tracking the state of the chromecast, on, off, or unavailable. Adding a script to ping the chromecast would be a solution, but redundant.

Thinking of a cam… I probably would want to get a notification if one of my cameras became “unavailable”… If “on” means there was movement, send me the video, if “off” there is no movement, but camera is working, if “unavailable” I would like to be notified so that I know something is up with my camera… (again, I want to think we can use the unavailable status, but it doesn’t seem to be a straight forward option)

Anand, I am using 0.111.3. Not sure what you mean you can set the status by typing. I don’t want to manually change the status of anything.

I am trying to find a way to use the “unavailable” state of the chromecast, to trigger an event. If I go to the automation interface I can set triggers when the chromecast turns on, or off, but can’t seem to set triggers when chromecast goes onto unavailable.

You will probably need to create the automation using yaml rather than the GUI editor

trigger:
  - platform: state
    entity_id: media_player.your_monitor_chromecast
    to: 'unavailable'

Or use a state trigger instead of a device trigger.

1 Like

See if this image makes any sense.

I think you just lead me to my solution. A bit late now so will test tomorrow. I had assumed it wasn’t working properly, since I was expecting a drop down menu when I clicked on “from”, but seems I can type from “unavailable” to “off”. Guess just have to read up on how to add “ands” and “ors”.

From Unavailable to on or off, would change monitor status to on, and other automation from on or off, to unavailable would change monitor status to off.

you don’t need to have both from: and to:, you can just have from: 'unavailable' and not worry about whether it goes to on or off.

1 Like

If im not mistaken, triggers are always or. Condition can be or / and

And like dave stated, you don’t have to enter both states

Did you get this working? I’m having the same problem where I can’t seem to get an “unavailable” state to trigger an automation.

Make a binary_sensor that is on if the sensor is available or off if it’s not. Then trigger off that

1 Like

unavailable is just another word. There’s nothing special about it. If an entity’s state changes to unavailable, then it should trigger an automation that is looking for that state (just like on, off, open, unknown, or any other state string.)

Maybe you could share your automation and tell us a little about the entities used in its trigger.