Combine movement sensor TV status and sun

I currently have a movement sensor in my living room that after sunset turns on a light for 10 minutes. I find sometimes when we are sitting still watching TV the light is turned off.

I was thinking of setting up something like:

After sunset if movement turn on the light then turn it off again after 10 minutes but if the TV is “home” don’t turn off the light until 10 minutes after its off.

I tried this but it doesn’t appear to have worked:

timed_lamp:
  alias: "Turn on lamp and set timer"
  sequence:
  # Cancel ev. old timers
    - service: script.turn_off
      data:
        entity_id: script.timer_off
    - service: light.turn_on
      data:
        entity_id: light.tv_light
      # Set new timer
    - service: script.turn_on
      data:
        entity_id: script.timer_off

timer_off:
  alias: "Turn off lamp after 5 minutes"
  sequence:
    - delay:
        minutes: 10
    - service: light.turn_off
      data:
        entity_id: light.tv_light
  condition:
    - condition: state
      entity_id: device_tracker.localhost
      state: 'not_home'

Has anyone set anything like this up. I am not sure if I am over complicating things and there is an easier way to achieve this :slight_smile:

In case anyone else finds this thread, this seems to have worked for me:

timed_lamp:
  alias: "Turn on lamp and set timer"
  sequence:
  # Cancel ev. old timers
    - service: script.turn_off
      data:
        entity_id: script.timer_off
    - service: light.turn_on
      data:
        entity_id: light.tv_light
      # Set new timer
    - service: script.turn_on
      data:
        entity_id: script.timer_off

timer_off:
  alias: "Turn off lamp after 5 minutes"
  sequence:
    - condition: state
      entity_id: device_tracker.localhost
      state: 'not_home'
    - delay:
        minutes: 5
    - service: light.turn_off
      data:
        entity_id: light.tv_light