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:
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.
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