Integration of light between HA and Domoticz

Hello,
A light is setup with mqtt and I managed to get this working
From Domoticz (dz) to HA: On/Off and brightness level
From HA to dz: only brightness.
I can’t get On and Off working (I successfully published the expected json data with mqtt explorer). I guess the On/Off is triggered when one click on the light itself. I would expect to have a state_command_topic with a state_command_template I guess as there is for receiving commands. Indeed , dz expects a different command to set the state which is:

{"command": "switchlight", "idx": 2450, "switchcmd": "On/Off" } 

The current code is the following

  - platform: mqtt
    enabled_by_default: true
    name: "Suspension principale"
    object_id: "389"
    unique_id: "389"
    state_topic: "domoticz/out/389"
    state_value_template: "{{ value_json.nvalue}}"
    payload_on:  "2"
    payload_off: "0"
    brightness_state_topic: "domoticz/out/389"
    brightness_scale: "100"
    brightness_value_template: "{{ value_json.svalue1 }}"

    command_topic: "domoticz/in"
    brightness_command_topic: "domoticz/in"
    brightness_command_template:  '{"command": "switchlight", "idx": 389 , "switchcmd": "Set Level", "level" : {{value}} }'
    optimistic: false
    qos: 0
    retain: true

Thank you

Edit
I ended up using the template model instead of the default one. Still one thing to achieve for a little later on, store the last brightness value on order to recall it when going from Off to On.

  - platform: mqtt
    schema: template
    name: "Suspension principale"
    object_id: "389"
    unique_id: "389"
    state_topic: "domoticz/out/389"
    state_template: "{% if value_json.nvalue == 2 %}on{% else %}off{% endif %}"
    brightness_template: '{{ value_json.svalue1 | multiply (2.55) | round (0)}}'
    command_topic: "domoticz/in"
    command_off_template : '{"command": "switchlight", "idx": 389, "switchcmd": "Off" }'
    command_on_template : >
      {%- if brightness is defined -%} 
        {"command": "switchlight", "idx": 389 , "switchcmd": "Set Level", "level" : {{ brightness | multiply(100/255) | round(0)}} }
      {%- else -%}
        {"command": "switchlight", "idx": 389 , "switchcmd": "Set Level", "level" : {{ 50 }} }
      {%- endif -%}
    optimistic: false
    qos: 0
    retain: true

This is the final code with slider memorization in order to have the light switch on to the last dimming value
An input number has been defined in Helper named: suspension_brightness
Then two aliases in automation

- alias : "DZ 389 slider value"
  trigger:
    platform: mqtt
    topic: "domoticz/out/389"
  condition: "{{ trigger.payload_json.nvalue !=0 }}"
  action:
    service: input_number.set_value
    target: 
      entity_id: input_number.suspension_brightness
    data:
      value: "{{trigger.payload_json.svalue1 }}"
- alias : "HA 389 slider storage"
  trigger:
    platform: state
    entity_id: input_number.suspension_brightness
    action:
      service: mqtt.publish
      data:
        topic: "domoticz/out/389"
        retain: true
        payload: "{{ states('input_number.suspension_brightness') | int }}"

And then the light code featuring mqtt:

  - platform: mqtt
    schema: template
    name: "Suspension principale"
    object_id: "389"
    unique_id: "389"
    state_topic: "domoticz/out/389"
    state_template: "{% if value_json.nvalue == 2 %}on{% else %}off{% endif %}"
    brightness_template: '{{ value_json.svalue1 | multiply (2.55) | round (0)}}'
    command_topic: "domoticz/in"
    command_off_template : '{"command": "switchlight", "idx": 389, "switchcmd": "Off" }'
    command_on_template : >
      {%- if brightness is defined -%} 
        {"command": "switchlight", "idx": 389 , "switchcmd": "Set Level", "level" : {{ brightness | multiply(100/255) | round(0)}} }
      {%- else -%}
        {"command": "switchlight", "idx": 389 , "switchcmd": "Set Level", "level" : {{ states(input_number.suspension_brightness) }} }
      {%- endif -%}
    optimistic: false
    qos: 0
    retain: true

I would not stress enough that using MQTT explorer is a must and correct usage of single or double quotes as well.
I’m really amazed by the fact updates are done instentaneously on both side