Chromecast unavailable state sense

Hi all, I have been lurking for a while for some solutions to things I have been trying to accomplish. I’m pretty new to home assistant and Linux etc but I am an automation engineer by trade and I was fed up with the very basic options in Hue and lack of integration with other manufacturers as well as endless bloody boxes. That’s when I stumbled upon this project and it’s sort of gone on from there learning from posts from this community so Thankyou!

I’m struggling with an automation for a fairly basic light presence routine. Background is I have set a light to come on in detection of a PIR after sunset. I want to turn this off when I’m going to bed, I turn the tv off and after time the light will go off. My issue is chromecast is powered by usb I’m unwilling to change this so is there a way to check for states other that idle pause etc?

Ideally I want to keep it within the UI, I’m sure I could work this out in YAML but given the intent to move away from this.

Trigger
PIR stops detecting motion for a set time.

Condition

Chromecast state is unavailable Or off

Action

turn off light after time.

Could somebody help me with the condition please, I have tried device then editing as yaml changed to unavailable from off and also tried state to unavailable but that doesn’t seem to work either. Anybody got a solution to this?

Thanks

You would need an ‘or’ condition as conditions by default use ‘and’. There will be a better way than my clumsy layout below but at least it’s easy to understand as you grow more condiment with yaml.

trigger:
  - platform: state
    entity_id:
      - binary_sensor.master_bedroom_pir
      - binary_sensor.entry_foyer_pir
      - binary_sensor.rumpus_pir
    from: 'on'
    to: 'off'
    for:
      minutes: 5
condition:
  condition: or
  conditions:
    - condition: state
      entity_id: 'media_player.chromecast'
      state: 'unknown'
    - condition: state
      entity_id: 'media_player.chromecast'
      state: 'unavailable'
    - condition: state
      entity_id: 'media_player.chromecast'
      state: 'off'

Remove motion sensor entities as you see fit. You should be able to do all of this in the GUI? Trouble with your automation is that whenever your motion sensor/s goes from on to off (for more than 5 minutes) and the Chromecast is in one of the above states, it’s going to turn off your light.

Are you able to integrate your TV into HA directly? If not, maybe you’re better to use the Chromecast going from x to ‘unknown’ as the trigger and then the motion sensor (and maybe time) as a condition? So when you turn the TV off, the Chromecast dies and changes to unknown which is an indication your heading to bed. HA then waits for the motion sensor (which we’re assuming got tripped when you got up) to go from on to off for x amount of time. Just thinking out aloud

Thanks for your reply!

Your thinking out loud is about right, it’s basically a tv used pretty much for gaming. Kids go to bed and I or we go to the den and watch a film (chromecast) or play playstation. Tv goes off a motion would have already triggered. Was my thinking too

Thanks I hadn’t thought about it going the other way. Given it’s scenario based that may well also work for getting rid of some erroneous triggers. So let me see if I get this, states would be defined as like you written

state: ‘off’ Or state: 'unknown’…

So would this also work

state: from ‘off’ to ‘unknown?

Yep, just switch the condition into a trigger. If you don’t need the ‘for:’, just remove it.

trigger:
  - platform: state
    entity_id: media_player.chromecast
    from: 'off'
    to: 'unknown'
    for:
      minutes: 5

You can also pop a time condition in there to be doubly safe if you want?

    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: binary_sensor.pir
          state: 'off'
            for:
              minutes: 1
              seconds: 5
        - condition: time
          after: '20:00:00'
          before: '23:30:00'

Thanks for your reply! I might do this in the YAML. I think I’m making it a little more difficult trying to just use the UI.

1 Like