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