Sunset + playing netflix

I made a automation for turning up and down the brightness of my lights.

- alias: 'LTV Playing'
  trigger:
-  platform: state
   entity_id: media_player.living_room
   to: 'playing'
  condition:  
condition: and
conditions:
- condition: sun
  after: sunset
 
- condition: template
  value_template: '{{  states.media_player.living_room.attributes.app_name == "Netflix"  }}' 
  action:
service: scene.turn_on
entity_id: scene.WatchTelevision

- alias: 'LTV Pausing'
  trigger:
-  platform: state
   entity_id: media_player.living_room
   from:  'playing'
  condition:  
condition: and
conditions:
- condition: sun
  after: sunset
- condition:  time
  before:  '23:30:00'    
- condition: template
  value_template: '{{  states.media_player.living_room.attributes.app_name == "Netflix"  }}' 
  action:
service: scene.turn_on
entity_id: scene.RelaxMode

And this works all fine.

But now i want my lights to turn on when its sunset.
If i am playing something on my TV i want it to set it my television watching mode, and if i am not watching anything i want it to go to my relaxmode.

I think i need a new sunset script for this, but i dont know how to start this script, or atleast make him check what my tv is doing at that moment.

Could you format your code using the </> button in the editor please? It makes it easier to see whether there are obvious syntax/indentation issues
image

I hope it works now, there is nothing wrong with this part of the code. I’m just not sure how to trigger a lights_on with sunset but in the correct state.

If i’m allready watching television i dont the “relaxmode” to start but the “watchingtelevision” . I dont know how i make him check for the state of television when starting a automation.

This is not set up exactly for you, but maybe it will help come up with some ideas

- alias: TV Lighting after sunset if TV is turned on
  trigger:
  - platform: template
    value_template: "{{ states.sun.sun.attributes.elevation < 3 }}"
  - platform: state
    entity_id: remote.living_room_harmony_hub
    from: 'off'
    to: 'on'
  condition:
  - condition: state
    entity_id: remote.living_room_harmony_hub
    state: 'on'
  - condition: numeric_state
    entity_id: sun.sun
    value_template: '{{ state.attributes.elevation }}'
    below: 3.0  
  action:
  - service: script.turn_on
    entity_id: script.kitchen_tv_lights_hue_scene
  - service: script.turn_on
    entity_id: script.living_room_tv_lights_hue_scene

Thank you! Will take a look after dinner!

Would this be when the state of media_player.living_room is ‘playing’, and possibly the app_name attribute of media_player.living_room is ‘Netflix’? If so, then you can use this in a data_template:

- alias: Lights at Sunset
  trigger:
    platform: sun
    event: sunset
  action:
    service: scene.turn_on
    data_template: >
      {% if is_state('media_player.living_room', 'playing') and
            is_state_attr('media_player.living_room', 'app_name', 'Netflix') %}
        scene.WatchTelevision
      {% else %}
        scene.RelaxMode
      {% endif %}