Automation for turning off Govee lights when Samsung TV turns off

Hello All,

Some info on my situation:
System: Home Assistant OS on RBP model 3B+
Automation purpose: When Samsung tv turns on, turn on Govee TV leds.
TV: Samsung UE55RU7172UXXH
Led Lights: Govee Immersion Wi-Fi TV Backlights
Integrations used: Custom integration for Govee and Samsung integration
Yaml code:

- id: '1635700813261'
  alias: TV uitdoen
  description: ''
  trigger:
  - platform: device
    device_id: 5ff0fe5c44d439677741ffdc852e65f0
    domain: media_player
    entity_id: media_player.samsung_7_series_55
    type: turned_off
  condition: []
  action:
  - type: turn_off
    device_id: 8a03500a2cf02dcd3c892803b2eb3459
    entity_id: light.tv_lights
    domain: light
  mode: single

The automation which I made turns off the Govee lights only the TV doesn’t turn off/on. What is it that I am doing wrong?

PS. If there is something I missed please let me know so i can provide more information.

Please post your automation in the forum and not somewhere else.

For more information, see guideline 11 in the FAQ.

Thanks, now i did paste it in the OP

The automation you posted is designed to turn off light.tv_lights at the moment when media_player.samsung_7_series_55 is turned off. In other words, when someone turns off the TV, the lights will also be turned off.

You requirements are unclear. You stated you want an automation that turns on the lights when the TV is turned on but you posted an automation that does the opposite (turns off the lights when TV is turned off). Then you asked why the TV isn’t also turned off.

What exactly do you want the automation to do?

Sorry for the haziness. I want my lights to turn on when my TV turns on and my lights to turn off when my TV turn off. The lights are kind of ambient lights. So I want there state to be the same as my TV.
TV on = Lights on, TV off = Lights off

A light has two possible state values, on and off, whereas a media_player has several: off, idle, playing, paused.

In the following simple example, the light is turned off if the media_player’s state is off, otherwise it is turned on.

- id: '1635700813261'
  alias: TV uitdoen
  description: ''
  trigger:
  - platform: state
    entity_id: media_player.samsung_7_series_55
    to:
    - 'off'
    - 'playing'
    - 'paused'
    - 'idle'
  condition: []
  action:
  - service: "light.turn_{{ 'off' if trigger.to_state.state == 'off' else 'on' }}"
    target:
      entity_id: light.tv_lights
  mode: single

The automation is triggered whenever the TV’s state changes to off, playing, paused or idle. The automation’s action turns off the light if the TV’s state is off otherwise it turns on the light.


Here is a more sophisticated version. When the TV is turned on, the light will be turned on but only if the light is currently off and not if it is already on. In other words, it won’t control the light needlessly (like turning it on if it’s already on or turning it off if it’s already off). In addition, it will turn off the light if the TV’s state is unavailable.

- id: '1635700813261'
  alias: TV uitdoen
  description: ''
  variables:
    player_state: "{{ 'off' if trigger.to_state.state in ['off', 'unavailable'] else 'on' }}"
    light: 'light.tv_lights'
  trigger:
  - platform: state
    entity_id: media_player.samsung_7_series_55
    to:
    - 'off'
    - 'playing'
    - 'paused'
    - 'idle'
    - 'unavailable'
  condition: "{{ player_state != states(light) }}"
  action:
  - service: "light.turn_{{ player_state }}"
    target:
      entity_id: "{{ light }}"
  mode: single
2 Likes