Ok, then I will try to figure that out on the Domoticz side. I am running the latest stable version. (Updated: Just upgraded to latest Beta, got Index now )
Got your switch example to work, but I am struggle to get the dimmable light example to work. When I validate it in HA it complains about this:
Invalid config for [switch.mqtt]: [schema] is an invalid option for [switch.mqtt]. Check: switch.mqtt->schema. (See ?, line ?).
I created a dedicated switches.yaml file where I place all the switches going forward. It looks like this:
- platform: mqtt
unique_id: 14
name: "Light-Hall2"
icon: mdi:lightbulb-outline
state_topic: "domoticz/out/14"
value_template: "{% if value_json.nvalue == 1 -%}ON{%- else %}OFF{%- endif %}"
command_topic: "domoticz/in"
payload_on: '{"command":"switchlight","idx":14,"switchcmd":"On"}'
payload_off: '{"command":"switchlight","idx":14,"switchcmd":"Off"}'
state_on: "ON"
state_off: "OFF"
optimistic: false
qos: 0
retain: false
- platform: mqtt
schema: template
unique_id: 364
name: "Light-Kitchen1"
state_topic: "domoticz/out/364"
command_topic: "domoticz/in"
state_template: "{% if value_json.nvalue >= 1 -%}on{%- else %}off{%- endif %}"
brightness_template: "{{ (value_json.Level*255/100) | round(0) }}"
command_off_template: '{"command":"switchlight","idx":364,"switchcmd":"Off"}'
command_on_template: >
{"command":"switchlight","idx":364,"switchcmd":
{%- if brightness is defined -%}
"Set Level","level":{{ (brightness*100/255) | round(0) }}
{%- else -%}
"On"
{%- endif -%}
}
Update, and a good one also
I reckoned it must have been something obvious, as I am on a very basic level with HA. If I read the error a couple of times I should have gotten it. “Switch” does not use “template”. So I went ahead and created an another element in my config.yaml point to lights: !include lights.yaml where I pasted in the dimmable light config.
switches.yaml:
- platform: mqtt
unique_id: 14
name: "Light-Hall2"
icon: mdi:lightbulb-outline
state_topic: "domoticz/out/14"
value_template: "{% if value_json.nvalue == 1 -%}ON{%- else %}OFF{%- endif %}"
command_topic: "domoticz/in"
payload_on: '{"command":"switchlight","idx":14,"switchcmd":"On"}'
payload_off: '{"command":"switchlight","idx":14,"switchcmd":"Off"}'
state_on: "ON"
state_off: "OFF"
optimistic: false
qos: 0
retain: false
Lights.yaml
- platform: mqtt
schema: template
unique_id: 364
name: "Light-Kitchen1"
state_topic: "domoticz/out/364"
command_topic: "domoticz/in"
state_template: "{% if value_json.nvalue >= 1 -%}on{%- else %}off{%- endif %}"
brightness_template: "{{ (value_json.Level*255/100) | round(0) }}"
command_off_template: '{"command":"switchlight","idx":364,"switchcmd":"Off"}'
command_on_template: >
{"command":"switchlight","idx":364,"switchcmd":
{%- if brightness is defined -%}
"Set Level","level":{{ (brightness*100/255) | round(0) }}
{%- else -%}
"On"
{%- endif -%}
}
Thanks alot for your help Bikey, now I have the basics and can progress a lot more on my own. Learnt something also during this