Having trouble with automation differentiating between off and unavailable device

I set up an automation recently so that when I turn my tv on or off, my philips hue sync box will also turn on or off with it. I noticed the other day when watching tv that the sync box and lights would keep turning off randomly and then I realized, it’s turning off because the wi-fi is dropping my from my LG TV and the automation is recognizing this as “off”.

I updated my script (below) so that it specifically checks from an “on” state to off AND that the state is not “unavailable” but if I disconnect my tv wifi it still turns off.

What is the best way to handle this scenario for wifi drops?

alias: Turn Sync Box Off
description: ""
triggers:
  - entity_id:
      - media_player.lg_tv
    from:
      - "on"
      - playing
      - paused
    to:
      - "off"
    trigger: state
conditions:
  - condition: not
    conditions:
      - condition: state
        entity_id: media_player.lg_tv
        state: unavailable
actions:
  - type: turn_off
    device_id: c307838310b84b444d0063f46d41af98
    entity_id: b0d837eefe47f3f5d56a4b607b395611
    domain: switch
  - type: turn_off
    device_id: c307838310b84b444d0063f46d41af98
    entity_id: 8b1f552a4db65d3eb585f1ad98fe96fb
    domain: switch
  - type: turn_off
    device_id: 622fc40a66055d5f46d634299c7a0b43
    entity_id: e186f5b773ec95a2a33d0cb62f8167ee
    domain: light
mode: single

This:

triggers:
  - entity_id:
      - media_player.lg_tv
    from:
      - "on"
      - playing
      - paused
    to:
      - "off"
    trigger: state

can not trigger from or to unavailable. It can only trigger when going from (on or playing or paused) to off.

Something else is going on.

Check the Activity panel (in the left hand menu). Was there any context given for turning off your philips hue sync box?

e.g.

image

I would also recommend replacing your device actions. See: Why and how to avoid device_ids in automations and scripts

e.g. replace this:

actions:
  - type: turn_off
    device_id: c307838310b84b444d0063f46d41af98
    entity_id: b0d837eefe47f3f5d56a4b607b395611
    domain: switch

with:

actions:
  - action: switch.turn_off
    target:
      entity_id: switch.your_switch_here
1 Like

I’ve modified my script. I guess it was setup that way with the device ID’s because I used the visual editors.

So I just tested by removing my tv from the wifi connection and you can see the trigger activates, but it looks like for some reason the wifi disconnection is sending a “Turned off” followed by a “Became unavailable” about 10 seconds later. I did not turn off the TV at these times, just disconnected from the wifi.


You are not going to be able to filter that out. There is no way to tell if the TV turned off because you turned it off or because you disconnected the wifi.

You need to open an issue for whatever integration you are using to connect the TV to home assistant.

Yeah, unfortunate. I’ll have to see if I can tie this to something else. Maybe I can just check to make sure the tv has been off for x minutes before I shut off the sync box, that way momentary drops don’t trigger it.

Yeah that could work.

triggers:
  - trigger: state
    entity_id:
      - media_player.lg_tv
    from:
      - "on"
      - playing
      - paused
    to:
      - "off"
    for: 30 

You should still open an issue though. Get it fixed.

Will do, thank you!

Looks like there are several issues already open around this so I won’t add another one. Thanks again.

1 Like