Turn other light on when last person one goes to bed

I can turn my side lamps on/off for our bedroom from my headboard. control by HA

this got me thinking about how I can turn on the other bedside lamp when I turn off the TV in the lounge

first I Created a template sensor but watch for the OFF state

- trigger:
    - platform: state
      entity_id:
        - light.her_side
        - light.his_side
      to: "off"
  sensor:
    - unique_id: 51f05e35-22f5-417d-9614-12b79c80caa7
      name: Auto on Side lamp
      state: >      
        {%- set what = trigger.entity_id %}
        {% if what == 'light.her_side' %}
        {{'light.his_side'}}
        {%else %}
        {{'light.her_side'}}
        {%endif%}

so now I know which lamp was turn off last hold the other lamp in the sensor

now in my turn off tv automation I added
so I thought this should work

  - data_template:
      entity_id: {{states.sensor.auto_on_side_lamp.state}}
    service: light.turn_on

but I get a config error

mmmmmmm

so with a bit of thinking I did this

  - data_template:
      entity_id: light.{{states.sensor.auto_on_side_lamp.state.split('.')[1]}}
    service: light.turn_on

that worked well no error in config

so now when the 1st person goes to bed and turns off their side lamp and the next person turns the TV off, the other side lamp comes on.