Problem with wall switch connected to relay controller

Hello guys i need help with a problem.
I have 1 relay controller and 1 logical controller connected with HA by mqtt.
relay controller is: home automation local server – KC868-Server - Smart Home Automation | KinCony
logical controller is: Programmable Logic Controller(Ethernet+WiFi) – KC868-COLB - Smart Home Automation | KinCony

I renovate 1 room recently and i want to control 5 different lights so im sending 5 different wires for lights to relay controller. i follow the instructions of manufacturer and i manually add code to configuration yaml file to create the entities, so far so good i can control my light from HA without error or anything. Relay controller have 16 binary sensors for connecting wall switch, i buy a 4 gang switch from the same company: glass touch momentary wall switch panel - Smart Home Automation | KinCony and i follow the instructions of manufacturer to connect with relay controller and HA and now starts my problems!!!
From MQTTBox i know that key 1 from switch refers as SW1 key 2 as SW2 and so on… I make 5 automations and example of code is:

alias: KC868-Server-SW1-1click
description: ""
trigger:
  - platform: mqtt
    topic: server/XXXXXXXXXXXXXXXXX/state
    payload: "{\"SW1\":{\"on\":1}}"
condition: []
action:
  - service: switch.toggle
    data: {}
    target:
      entity_id: switch.output_1
mode: single

I forgot to mention that my lights are connected to relay1,relay2,relay3,relay4,relay5
When i press any key in the switch the light that i defined was succesfully ON but HA appear this in log

* Error parsing value: 'dict object' has no attribute 'relay12' (value: {"SW1":{"on":1}}, template: {{ value_json.relay12.on }})
* Error parsing value: 'dict object' has no attribute 'relay13' (value: {"SW1":{"on":1}}, template: {{ value_json.relay13.on }})
* Error parsing value: 'dict object' has no attribute 'relay14' (value: {"SW1":{"on":1}}, template: {{ value_json.relay14.on }})
* Error parsing value: 'dict object' has no attribute 'relay15' (value: {"SW1":{"on":1}}, template: {{ value_json.relay15.on }})
* Error parsing value: 'dict object' has no attribute 'relay16' (value: {"SW1":{"on":1}}, template: {{ value_json.relay16.on }})

* Template variable error: 'dict object' has no attribute 'relay12' when rendering '{{ value_json.relay12.on }}'
* Template variable error: 'dict object' has no attribute 'relay13' when rendering '{{ value_json.relay13.on }}'
* Template variable error: 'dict object' has no attribute 'relay14' when rendering '{{ value_json.relay14.on }}'
* Template variable error: 'dict object' has no attribute 'relay15' when rendering '{{ value_json.relay15.on }}'
* Template variable error: 'dict object' has no attribute 'relay16' when rendering '{{ value_json.relay16.on }}'

Code for relays is:

mqtt:
  switch:
  - name: 'output-1'
    unique_id: output-1
    state_topic: 'server/XXXXXXXXXXXXXXX/state'
    command_topic: 'server/XXXXXXXXXXXXXXXXXXX/set'
    payload_on:  '{"relay1":{"on":1}}'
    payload_off:  '{"relay1":{"on":0}}'
    value_template: '{{ value_json.relay1.on }}'
    state_on: 1
    state_off: 0

Code for sensors is:
  - name: 'input-1'
    unique_id: input-1
    state_topic: 'server/XXXXXXXXXXXXXXXXX/state'
    value_template: '{{ value_json.input1.on }}'
    payload_on: 1
    payload_off: 0

Im not pro and im learning every day, i’m searching forum and google 4 days now but i cant figure out what to do can anyone help?

Im posting full log for further Information:

2022-09-30 21:21:13.537 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'input1' when rendering '{{ value_json.input1.on }}'

2022-09-30 21:21:13.543 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'input1' (value: {"SW3":{"on":1}}, template: {{ value_json.input1.on }})

2022-09-30 21:21:13.544 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'input2' when rendering '{{ value_json.input2.on }}'

2022-09-30 21:21:13.544 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'input2' (value: {"SW3":{"on":1}}, template: {{ value_json.input2.on }})

2022-09-30 21:21:13.545 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'input3' when rendering '{{ value_json.input3.on }}'

2022-09-30 21:21:13.545 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'input3' (value: {"SW3":{"on":1}}, template: {{ value_json.input3.on }})

2022-09-30 21:21:13.546 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'input4' when rendering '{{ value_json.input4.on }}'

2022-09-30 21:21:13.546 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'input4' (value: {"SW3":{"on":1}}, template: {{ value_json.input4.on }})

2022-09-30 21:21:13.547 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'input5' when rendering '{{ value_json.input5.on }}'

2022-09-30 21:21:13.547 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'input5' (value: {"SW3":{"on":1}}, template: {{ value_json.input5.on }})

2022-09-30 21:21:13.548 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'input6' when rendering '{{ value_json.input6.on }}'

2022-09-30 21:21:13.548 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'input6' (value: {"SW3":{"on":1}}, template: {{ value_json.input6.on }})

2022-09-30 21:21:13.548 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'input7' when rendering '{{ value_json.input7.on }}'

2022-09-30 21:21:13.549 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'input7' (value: {"SW3":{"on":1}}, template: {{ value_json.input7.on }})

2022-09-30 21:21:13.549 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'input8' when rendering '{{ value_json.input8.on }}'

2022-09-30 21:21:13.550 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'input8' (value: {"SW3":{"on":1}}, template: {{ value_json.input8.on }})

2022-09-30 21:21:13.550 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'analog1' when rendering '{{ value_json.analog1.value }}'

2022-09-30 21:21:13.551 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'analog2' when rendering '{{ value_json.analog2.value }}'

2022-09-30 21:21:13.553 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'analog3' when rendering '{{ value_json.analog3.value }}'

2022-09-30 21:21:13.554 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'analog4' when rendering '{{ value_json.analog4.value }}'

2022-09-30 21:21:13.554 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay1' when rendering '{{ value_json.relay1.on }}'

2022-09-30 21:21:13.555 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay1' (value: {"SW3":{"on":1}}, template: {{ value_json.relay1.on }})

2022-09-30 21:21:13.555 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay2' when rendering '{{ value_json.relay2.on }}'

2022-09-30 21:21:13.556 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay2' (value: {"SW3":{"on":1}}, template: {{ value_json.relay2.on }})

2022-09-30 21:21:13.556 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay3' when rendering '{{ value_json.relay3.on }}'

2022-09-30 21:21:13.557 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay3' (value: {"SW3":{"on":1}}, template: {{ value_json.relay3.on }})

2022-09-30 21:21:13.557 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay4' when rendering '{{ value_json.relay4.on }}'

2022-09-30 21:21:13.558 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay4' (value: {"SW3":{"on":1}}, template: {{ value_json.relay4.on }})

2022-09-30 21:21:13.559 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay5' when rendering '{{ value_json.relay5.on }}'

2022-09-30 21:21:13.559 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay5' (value: {"SW3":{"on":1}}, template: {{ value_json.relay5.on }})

2022-09-30 21:21:13.560 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay6' when rendering '{{ value_json.relay6.on }}'

2022-09-30 21:21:13.560 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay6' (value: {"SW3":{"on":1}}, template: {{ value_json.relay6.on }})

2022-09-30 21:21:13.561 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay7' when rendering '{{ value_json.relay7.on }}'

2022-09-30 21:21:13.562 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay7' (value: {"SW3":{"on":1}}, template: {{ value_json.relay7.on }})

2022-09-30 21:21:13.562 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay8' when rendering '{{ value_json.relay8.on }}'

2022-09-30 21:21:13.563 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay8' (value: {"SW3":{"on":1}}, template: {{ value_json.relay8.on }})

2022-09-30 21:21:13.564 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay9' when rendering '{{ value_json.relay9.on }}'

2022-09-30 21:21:13.564 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay9' (value: {"SW3":{"on":1}}, template: {{ value_json.relay9.on }})

2022-09-30 21:21:13.565 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay10' when rendering '{{ value_json.relay10.on }}'

2022-09-30 21:21:13.566 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay10' (value: {"SW3":{"on":1}}, template: {{ value_json.relay10.on }})

2022-09-30 21:21:13.566 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay11' when rendering '{{ value_json.relay11.on }}'

2022-09-30 21:21:13.567 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay11' (value: {"SW3":{"on":1}}, template: {{ value_json.relay11.on }})

2022-09-30 21:21:13.568 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay12' when rendering '{{ value_json.relay12.on }}'

2022-09-30 21:21:13.569 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay12' (value: {"SW3":{"on":1}}, template: {{ value_json.relay12.on }})

2022-09-30 21:21:13.569 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay13' when rendering '{{ value_json.relay13.on }}'

2022-09-30 21:21:13.570 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay13' (value: {"SW3":{"on":1}}, template: {{ value_json.relay13.on }})

2022-09-30 21:21:13.571 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay14' when rendering '{{ value_json.relay14.on }}'

2022-09-30 21:21:13.572 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay14' (value: {"SW3":{"on":1}}, template: {{ value_json.relay14.on }})

2022-09-30 21:21:13.573 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay15' when rendering '{{ value_json.relay15.on }}'

2022-09-30 21:21:13.574 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay15' (value: {"SW3":{"on":1}}, template: {{ value_json.relay15.on }})

2022-09-30 21:21:13.575 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay16' when rendering '{{ value_json.relay16.on }}'

2022-09-30 21:21:13.576 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay16' (value: {"SW3":{"on":1}}, template: {{ value_json.relay16.on }})

2022-09-30 21:21:16.437 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'input1' when rendering '{{ value_json.input1.on }}'

2022-09-30 21:21:16.439 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'input1' (value: {"SW3":{"on":1}}, template: {{ value_json.input1.on }})

2022-09-30 21:21:16.440 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'input2' when rendering '{{ value_json.input2.on }}'

2022-09-30 21:21:16.442 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'input2' (value: {"SW3":{"on":1}}, template: {{ value_json.input2.on }})

2022-09-30 21:21:16.443 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'input3' when rendering '{{ value_json.input3.on }}'

2022-09-30 21:21:16.445 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'input3' (value: {"SW3":{"on":1}}, template: {{ value_json.input3.on }})

2022-09-30 21:21:16.446 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'input4' when rendering '{{ value_json.input4.on }}'

2022-09-30 21:21:16.448 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'input4' (value: {"SW3":{"on":1}}, template: {{ value_json.input4.on }})

2022-09-30 21:21:16.449 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'input5' when rendering '{{ value_json.input5.on }}'

2022-09-30 21:21:16.451 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'input5' (value: {"SW3":{"on":1}}, template: {{ value_json.input5.on }})

2022-09-30 21:21:16.452 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'input6' when rendering '{{ value_json.input6.on }}'

2022-09-30 21:21:16.454 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'input6' (value: {"SW3":{"on":1}}, template: {{ value_json.input6.on }})

2022-09-30 21:21:16.455 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'input7' when rendering '{{ value_json.input7.on }}'

2022-09-30 21:21:16.456 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'input7' (value: {"SW3":{"on":1}}, template: {{ value_json.input7.on }})

2022-09-30 21:21:16.458 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'input8' when rendering '{{ value_json.input8.on }}'

2022-09-30 21:21:16.459 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'input8' (value: {"SW3":{"on":1}}, template: {{ value_json.input8.on }})

2022-09-30 21:21:16.461 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'analog1' when rendering '{{ value_json.analog1.value }}'

2022-09-30 21:21:16.462 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'analog2' when rendering '{{ value_json.analog2.value }}'

2022-09-30 21:21:16.464 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'analog3' when rendering '{{ value_json.analog3.value }}'

2022-09-30 21:21:16.465 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'analog4' when rendering '{{ value_json.analog4.value }}'

2022-09-30 21:21:16.468 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay1' when rendering '{{ value_json.relay1.on }}'

2022-09-30 21:21:16.469 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay1' (value: {"SW3":{"on":1}}, template: {{ value_json.relay1.on }})

2022-09-30 21:21:16.470 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay2' when rendering '{{ value_json.relay2.on }}'

2022-09-30 21:21:16.472 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay2' (value: {"SW3":{"on":1}}, template: {{ value_json.relay2.on }})

2022-09-30 21:21:16.474 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay3' when rendering '{{ value_json.relay3.on }}'

2022-09-30 21:21:16.475 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay3' (value: {"SW3":{"on":1}}, template: {{ value_json.relay3.on }})

2022-09-30 21:21:16.476 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay4' when rendering '{{ value_json.relay4.on }}'

2022-09-30 21:21:16.478 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay4' (value: {"SW3":{"on":1}}, template: {{ value_json.relay4.on }})

2022-09-30 21:21:16.479 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay5' when rendering '{{ value_json.relay5.on }}'

2022-09-30 21:21:16.480 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay5' (value: {"SW3":{"on":1}}, template: {{ value_json.relay5.on }})

2022-09-30 21:21:16.482 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay6' when rendering '{{ value_json.relay6.on }}'

2022-09-30 21:21:16.483 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay6' (value: {"SW3":{"on":1}}, template: {{ value_json.relay6.on }})

2022-09-30 21:21:16.484 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay7' when rendering '{{ value_json.relay7.on }}'

2022-09-30 21:21:16.486 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay7' (value: {"SW3":{"on":1}}, template: {{ value_json.relay7.on }})

2022-09-30 21:21:16.487 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay8' when rendering '{{ value_json.relay8.on }}'

2022-09-30 21:21:16.488 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay8' (value: {"SW3":{"on":1}}, template: {{ value_json.relay8.on }})

2022-09-30 21:21:16.490 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay9' when rendering '{{ value_json.relay9.on }}'

2022-09-30 21:21:16.491 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay9' (value: {"SW3":{"on":1}}, template: {{ value_json.relay9.on }})

2022-09-30 21:21:16.492 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay10' when rendering '{{ value_json.relay10.on }}'

2022-09-30 21:21:16.494 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay10' (value: {"SW3":{"on":1}}, template: {{ value_json.relay10.on }})

2022-09-30 21:21:16.495 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay11' when rendering '{{ value_json.relay11.on }}'

2022-09-30 21:21:16.496 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay11' (value: {"SW3":{"on":1}}, template: {{ value_json.relay11.on }})

2022-09-30 21:21:16.498 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay12' when rendering '{{ value_json.relay12.on }}'

2022-09-30 21:21:16.499 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay12' (value: {"SW3":{"on":1}}, template: {{ value_json.relay12.on }})

2022-09-30 21:21:16.500 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay13' when rendering '{{ value_json.relay13.on }}'

2022-09-30 21:21:16.501 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay13' (value: {"SW3":{"on":1}}, template: {{ value_json.relay13.on }})

2022-09-30 21:21:16.503 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay14' when rendering '{{ value_json.relay14.on }}'

2022-09-30 21:21:16.504 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay14' (value: {"SW3":{"on":1}}, template: {{ value_json.relay14.on }})

2022-09-30 21:21:16.505 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay15' when rendering '{{ value_json.relay15.on }}'

2022-09-30 21:21:16.507 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay15' (value: {"SW3":{"on":1}}, template: {{ value_json.relay15.on }})

2022-09-30 21:21:16.508 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'relay16' when rendering '{{ value_json.relay16.on }}'

2022-09-30 21:21:16.509 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'relay16' (value: {"SW3":{"on":1}}, template: {{ value_json.relay16.on }})

Post an example of the JSON payload published to the server/c5a1fc183767977261f992c4/state topic.

mqtt:
  switch:
  - name: 'output-1'
    unique_id: output-1
    state_topic: 'server/XXXXXXXXXXXXXXX/state'
    command_topic: 'server/XXXXXXXXXXXXXXXXXXX/set'
    payload_on:  '{"relay1":{"on":1}}'
    payload_off:  '{"relay1":{"on":0}}'
    value_template: '{{ value_json.relay1.on }}'
    state_on: 1
    state_off: 0

Code for sensors is:
  - name: 'input-1'
    unique_id: input-1
    state_topic: 'server/XXXXXXXXXXXXXXXXX/state'
    value_template: '{{ value_json.input1.on }}'
    payload_on: 1
    payload_off: 0

all examples above are from the same controller XXXXXXXXXXXX and c5a1fc183767977261f992c4 is from the same relay controller i just forget to delete the id

That’s not an example of the JSON payload received via the state_topic.

do you mean this?

{"relay1":{"on":0},"relay2":{"on":0},"relay3":{"on":0},"relay4":{"on":0},"relay5":{"on":0},"relay6":{"on":0},"relay7":{"on":0},"relay8":{"on":0},"relay9":{"on":0},"relay10":{"on":0},"relay11":{"on":0},"relay12":{"on":0},"relay13":{"on":0},"relay14":{"on":0},"relay15":{"on":0},"relay16":{"on":0},"input1":{"on":0},"input2":{"on":0},"input3":{"on":0},"input4":{"on":0},"input5":{"on":0},"input6":{"on":0},"input7":{"on":0},"input8":{"on":0},"analog1":{"value":1},"analog2":{"value":0},"analog3":{"value":1},"analog4":{"value":1}}

I extracting via MQTTBOX

Yes, that’s what I needed to see.

According to the following error message, it appears that sometimes the payload fails to contain a dictionary with the key you are referencing:

Template variable error: ‘dict object’ has no attribute ‘input1’ when rendering ‘{{ value_json.input1.on }}’

can you tell me what i have to do to correct it?

Do you get those error messages only when you restart Home Assistant or can they appear at any time?

they apper when i press the button of wall switch, if i control the lights from HA dashboard i dont have errors, doesnt matter if i restart or not problem remains same

Look what i receive when i press key1 from the wall switch and my light is ON

{"SW1":{"on":1}}
qos : 0, retain : false, cmd : publish, dup : false, topic : server/c5a1fc183767977261f992c4/state, messageId : , length : 55, Raw payload : 12334838749345812334111110345849125125
{"relay1":{"on":1},"relay2":{"on":0},"relay3":{"on":0},"relay4":{"on":0},"relay5":{"on":0},"relay6":{"on":0},"relay7":{"on":0},"relay8":{"on":0},"relay9":{"on":0},"relay10":{"on":0},"relay11":{"on":0},"relay12":{"on":0},"relay13":{"on":0},"relay14":{"on":0},"relay15":{"on":0},"relay16":{"on":0},"input1":{"on":0},"input2":{"on":0},"input3":{"on":0},"input4":{"on":0},"input5":{"on":0},"input6":{"on":0},"input7":{"on":0},"input8":{"on":0},"analog1":{"value":1},"analog2":{"value":1},"analog3":{"value":1},"analog4":{"value":1}}
qos : 0, retain : false, cmd : publish, dup : false, topic : server/c5a1fc183767977261f992c4/state, messageId : , length : 567, Raw payload : 12334114101108971214934581233411111034584912544341141011089712150345812334111110345848125443411410110897121513458123341111103458481254434114101108971215234581233411111034584812544341141011089712153345812334111110345848125443411410110897121543458123341111103458481254434114101108971215534581233411111034584812544341141011089712156345812334111110345848125443411410110897121573458123341111103458481254434114101108971214948345812334111110345848125443411410110897121494934581233411111034584812544341141011089712149503458123341111103458481254434114101108971214951345812334111110345848125443411410110897121495234581233411111034584812544341141011089712149533458123341111103458481254434114101108971214954345812334111110345848125443410511011211711649345812334111110345848125443410511011211711650345812334111110345848125443410511011211711651345812334111110345848125443410511011211711652345812334111110345848125443410511011211711653345812334111110345848125443410511011211711654345812334111110345848125443410511011211711655345812334111110345848125443410511011211711656345812334111110345848125443497110971081111034934581233411897108117101345849125443497110971081111035034581233411897108117101345849125443497110971081111035134581233411897108117101345849125443497110971081111035234581233411897108117101345849125125

and this is what i receive when i press it gain and my light is OFF


{"SW1":{"on":1}}
qos : 0, retain : false, cmd : publish, dup : false, topic : server/c5a1fc183767977261f992c4/state, messageId : , length : 55, Raw payload : 12334838749345812334111110345849125125
{"relay1":{"on":0},"relay2":{"on":0},"relay3":{"on":0},"relay4":{"on":0},"relay5":{"on":0},"relay6":{"on":0},"relay7":{"on":0},"relay8":{"on":0},"relay9":{"on":0},"relay10":{"on":0},"relay11":{"on":0},"relay12":{"on":0},"relay13":{"on":0},"relay14":{"on":0},"relay15":{"on":0},"relay16":{"on":0},"input1":{"on":0},"input2":{"on":0},"input3":{"on":0},"input4":{"on":0},"input5":{"on":0},"input6":{"on":0},"input7":{"on":0},"input8":{"on":0},"analog1":{"value":1},"analog2":{"value":1},"analog3":{"value":1},"analog4":{"value":1}}
qos : 0, retain : true, cmd : publish, dup : false, topic : server/c5a1fc183767977261f992c4/state, messageId : , length : 567, Raw payload : 12334114101108971214934581233411111034584812544341141011089712150345812334111110345848125443411410110897121513458123341111103458481254434114101108971215234581233411111034584812544341141011089712153345812334111110345848125443411410110897121543458123341111103458481254434114101108971215534581233411111034584812544341141011089712156345812334111110345848125443411410110897121573458123341111103458481254434114101108971214948345812334111110345848125443411410110897121494934581233411111034584812544341141011089712149503458123341111103458481254434114101108971214951345812334111110345848125443411410110897121495234581233411111034584812544341141011089712149533458123341111103458481254434114101108971214954345812334111110345848125443410511011211711649345812334111110345848125443410511011211711650345812334111110345848125443410511011211711651345812334111110345848125443410511011211711652345812334111110345848125443410511011211711653345812334111110345848125443410511011211711654345812334111110345848125443410511011211711655345812334111110345848125443410511011211711656345812334111110345848125443497110971081111034934581233411897108117101345849125443497110971081111035034581233411897108117101345849125443497110971081111035134581233411897108117101345849125443497110971081111035234581233411897108117101345849125125

It appears that when you press key1 it publishes two payloads.

First one:

{"SW1":{"on":1}}

Second one:

{"relay1":{"on":1},"relay2":{"on":0},"relay3":{"on":0},"relay4":{"on":0},"relay5":{"on":0},"relay6":{"on":0},"relay7":{"on":0},"relay8":{"on":0},"relay9":{"on":0},"relay10":{"on":0},"relay11":{"on":0},"relay12":{"on":0},"relay13":{"on":0},"relay14":{"on":0},"relay15":{"on":0},"relay16":{"on":0},"input1":{"on":0},"input2":{"on":0},"input3":{"on":0},"input4":{"on":0},"input5":{"on":0},"input6":{"on":0},"input7":{"on":0},"input8":{"on":0},"analog1":{"value":1},"analog2":{"value":1},"analog3":{"value":1},"analog4":{"value":1}}

The first one doesn’t contain input1 so that’s why the following template

{{ value_json.input1.on }}

fails and produces an error.

Test other keys and confirm they always publish two payloads (the first one short and the second one long).

yes all do the same

Replace this:

    value_template: '{{ value_json.input1.on }}'

with this:

    value_template: '{{ value_json.input1.on if value_json.input1 is defined else this.state }}'

You are the best!!! thank you very much!!!

But now i have a new problem logical controller, when i restart HA the state of sensors from logical controller are become unknown, if i restart logical controller state change to: (e.g OFF, 0 ºC etc) i try to add this line
retain = true

But doesn’t work
What i have to do to show the correct state after restarting HA?