Automation to set scene depending on media player

I’d like to have an automation that runs 45 minutes before sundown that set’s a scene based on if I’m watching something on TV at the time. I think I’m almost there but I’m new to home assistant and the template so I’m not sure what I’ve got wrong.

Here’s what I have so far:

  trigger:
  - platform: sun
    event: sunset
    offset: -00:45:00
  action:
  - scene:
      value_template: >
        {% if is_state('media_player.living_room_tv', 'off') %}
          living_room evening
        {% else %}
          watching_tv
        {% endif %}

I’m making a couple assumptions, but I think what you are looking for is something like:

trigger:
  - platform: sun
    event: sunset
    offset: -00:45
action:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ is_state('media_player.living_room_tv', 'off') }}"
        sequence:
          - scene: scene.living_room_evening
    default:
        - scene: scene.watching_tv

That worked, thanks :smiley: