Help dimming lights when starting TV after sunset

Hi all,

I created two scenes, and they are working well.
Now, I want to automate them, but I run into an issue :

alias: TV Samsung Salon éteinte
  trigger:
    - platform: state
      entity_id: media_player.samsung_q60_series_65
      from: "off"
      to: "on"
  condition:
    - condition: state
      entity_id: sun.sun
      state: below_horizon
  action:
    service: scene.turn_on
    entity_id: scene.movie_playing
alias: TV Samsung Salon allumée
  trigger:
    - platform: state
      entity_id: media_player.samsung_q60_series_65
      to: "off"
      from: "on"
  condition:
    - condition: state
      entity_id: sun.sun
      state: below_horizon
  action:
    service: scene.turn_on
    entity_id: scene.movie_not_playing_anymore
alias: Dim lights when playing TV after sunset
description: ""

Can you let me know what I’m doing wrong ?

Hi

You are not giving much of an problem description but I guess your problem is that you trigger on

Media players usually have the states

  • paused
  • playing
  • idle
  • off
  • unavailable

So if you change it to

   to: “playing”

It will trigger the automation

You don’t have to specify both to: and from:
So by only stating the to: parameter it will trigger regardless of previous state.

1 Like

Yes indeed, thing is, when I check the history of this entity, here is what I can see :

Still, I see no “On” attribute when I use the visual editor ! strange isn’t it ? :wink:

I guess I’d rather point this thing to my plex media player entity, directly ?
Bonus question : can I also make netflix, disney plus, etc. appear as media_players ?

EDIT: I’ve changed from my my samsung device to the shield pro device, which actually do send “Playing” attributes. I’ll see how it works tonight (too lazy to remove the sunset condition to test it now) :smiley:

EDIT 2: indeed, it is important to use a media_player_* that shoots "playing. it now works great ! here is the final code:

alias: "Light Scene : Dim lights when TV is turned on after sunset"
description: ""
trigger:
  - platform: state
    entity_id:
      - media_player.android_tv_192_168_3_49
    to: playing
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
    enabled: true
action:
  - service: scene.turn_on
    target:
      entity_id: scene.movie_playing
    metadata: {}
mode: single

and to go back to normal:

alias: "Light Scene : Turn lights back to normal when TV is turned off after sunset"
description: ""
trigger:
  - platform: state
    entity_id:
      - media_player.android_tv_192_168_3_49
    from: playing
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
    enabled: true
action:
  - service: scene.turn_on
    target:
      entity_id: scene.movie_not_playing_anymore
    metadata: {}
mode: single