Switch template

I have a house that 50 years ago was modern, it has latching relays that operate all the lights. I want to automate them and so got a 16 relay board and it works turning lights on and off with a pulse sent.
Problem is we have wall switches as well as using the relay board so the switch never know its state. I got a 16 channel analog input working that tells me via MQTT if it has voltage or not.
Now i need to bring it all together but can’t for the life of me see how it works. I think it will be done with a template switch in /config/configuration.yaml. If anyone could steer me in the correct direction it would be most appreciated.
Listed is the MQTT messages coming in and the switch I tried and failed to get to work:
Coming in:

12/16/2020, 7:57:26 PMnode: 696b6aee.f21344Voltage Input : msg.payload : string[14]

“Sensor 13: OFF”

12/16/2020, 7:57:26 PMnode: 696b6aee.f21344Voltage Input : msg.payload : string[14]

“Sensor 14: OFF”

12/16/2020, 7:57:26 PMnode: 696b6aee.f21344Voltage Input : msg.payload : string[14]

“Sensor_15: OFF”

12/16/2020, 7:57:27 PMnode: 696b6aee.f21344Voltage Input : msg.payload : string[13]

“Sensor 0: OFF”

12/16/2020, 7:57:27 PMnode: 696b6aee.f21344Voltage Input : msg.payload : string[13]

“Sensor 1: OFF”

12/16/2020, 7:57:27 PMnode: 696b6aee.f21344Voltage Input : msg.payload : string[13]

“Sensor 2: OFF”
‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
And my template:

switch:

  • platform: template
    switches:
    lights4:
    friendly_name: “Back Porch Lights”
    value_template: “{{ is_state_attr(‘switch.back_porch_lights’, ‘Sensor_15: on’) }}”
    turn_on:
    service: switch.toggle
    data:
    entity_id: switch.back_porch_lights
    turn_off:
    service: switch.toggle
    data:
    entity_id: switch.back_porch_lights