MQTT from Domoticz To Home-Assistant

Hello
I try add mqtt switch from Domoticz to Home-assistant.
I have temp sensors already working but switches won,t work.
I hope someone here can helping :innocent:
I have look already with mqtt-explorer data is here:
Off:--------------------------------------------------------------
{
“Battery” : 255,
“LastUpdate” : “2023-06-28 23:40:33”,
“RSSI” : 12,
“description” : “”,
“dtype” : “Light/Switch”,
“hwid” : “8”,
“id” : “0008000D”,
“idx” : 42,
“name” : “HW - lamp kast”,
“nvalue” : 0,
“stype” : “Switch”,
“switchType” : “On/Off”,
“unit” : 13
}

On:------------------------------------------------------------------
{
“Battery” : 255,
“LastUpdate” : “2023-06-28 23:46:11”,
“RSSI” : 12,
“description” : “”,
“dtype” : “Light/Switch”,
“hwid” : “8”,
“id” : “0008000D”,
“idx” : 42,
“name” : “HW - lamp kast”,
“nvalue” : 1,
“stype” : “Switch”,
“switchType” : “On/Off”,
“unit” : 13
}


This what i see in mqtt-explorer
I try publish on HA domoticz/out/42
“nvalue” : 1, “nvalue” : 0, “nvalue” : 2, and more but nothing will work.

Thanks

Here is how you add a mqtt switch to HA.

Hello good day

Thanks for your help :nickrout
I have add to HA but switch have status: unavailable


Here my Config
mqtt:
sensor:
- state_topic: “domoticz/out/74”
name: “Buiten”
unit_of_measurement: “°C”
device_class: temperature
value_template: “{{ value_json.svalue1 }}”
- state_topic: “domoticz/out/59”
name: “Zolder”
unit_of_measurement: “°C”
device_class: temperature
value_template: “{{ value_json.svalue1 }}”
- state_topic: “domoticz/out/60”
name: “Vloer R2”
unit_of_measurement: “°C”
device_class: temperature
value_template: “{{ value_json.svalue1 }}”
- state_topic: “domoticz/out/61”
name: “Ketel Aanvoer”
unit_of_measurement: “°C”
device_class: temperature
value_template: “{{ value_json.svalue1 }}”
- state_topic: “domoticz/out/62”
name: “Ketel Retour”
unit_of_measurement: “°C”
device_class: temperature
value_template: “{{ value_json.svalue1 }}”
- state_topic: “domoticz/out/65”
name: “Slaap Kamer”
unit_of_measurement: “°C”
device_class: temperature
value_template: “{{ value_json.svalue1 }}”
- state_topic: “domoticz/out/66”
name: “Vloer R3”
unit_of_measurement: “°C”
device_class: temperature
value_template: “{{ value_json.svalue1 }}”
- state_topic: “domoticz/out/67”
name: “Vloer Verdeler”
unit_of_measurement: “°C”
device_class: temperature
value_template: “{{ value_json.svalue1 }}”
- state_topic: “domoticz/out/68”
name: “Vloer R1”
unit_of_measurement: “°C”
device_class: temperature
value_template: “{{ value_json.svalue1 }}”
- state_topic: “domoticz/out/73”
name: “Garage”
unit_of_measurement: “°C”
device_class: temperature
value_template: “{{ value_json.svalue1 }}”
switch:
- command_topic: “domoticz/out/42/set”
- unique_id: HW - lamp kast
name: “HW - lamp kast”
state_topic: “domoticz/out/42”
command_topic: “domoticz/out/42/set”
availability:
- topic: “domoticz/out/42/available”
payload_on: “ON”
payload_off: “OFF”
state_on: “ON”
state_off: “OFF”
optimistic: false
qos: 0
retain: true


Thanks again

You’ll have to post it properly as yaml - see here:

Hi

I can’t open the link

Thanks

Ok I fixed that, sorry.

sorry this was not my intention.
i will try to solve it myself

Thanks

SOLVED !!!

switch:

name: "HW - lamp kast"
object_id: "42"
unique_id: "42"
state_topic: "domoticz/out/42"
command_topic: "domoticz/in"
value_template: "{{ value_json.nvalue }}"
state_on: "1"
state_off: "0"
payload_on:  '{"command": "switchlight", "idx": 42 , "switchcmd": "On" }'
payload_off: '{"command": "switchlight", "idx": 42, "switchcmd": "Off" }'
optimistic: false
qos: 0
retain: false

Thanks