hi
actually i try to setup new MQTT light but i have some problems.
This setup as a switch is running:
switch:
- platform: mqtt
name: Licht Garage
state_topic: "stat/garage/RESULT"
value_template: "{{value_json.S29cmnd_D0.STATE }}"
payload_on: "ON"
payload_off: 'OFF'
state_on: "ON"
state_off: "OFF"
command_topic: "cmnd/garage/Sensor29"
payload_on: "0, ON"
payload_off: "0, OFF"
but if i set it up as light the state is noch changing. when i switch on the light the button jumps back to off. how can i fix it?
this code is not running, how can i read the state?
light:
- platform: mqtt
name: Licht Garage
state_topic: "stat/garage/RESULT"
value_template: "{{value_json.S29cmnd_D0.STATE }}"
payload_on: "ON"
payload_off: 'OFF'
# state_on: "ON"
# state_off: "OFF"
command_topic: "cmnd/garage/Sensor29"
payload_on: "0, ON"
payload_off: "0, OFF"
Check the documentation for the MQTT Light, value_template is not a valid option for an MQTT Light. Also you have two times payload_on, payload_off, one of them will be ignored, don’t know which one.
You need a state_value_template in the MQTT light, try like this:
light:
- platform: mqtt
name: Licht Garage
state_topic: "stat/garage/RESULT"
state_value_template: "{{value_json.S29cmnd_D0.STATE }}"
payload_on: 'ON'
payload_off: 'OFF'
command_topic: "cmnd/garage/Sensor29"
hi @Burningstone
thanks for you answer. the problem is that i need the payload in den command_topic like this “1, ON” that means Pin no. 1 ON.
if i set it up as an switch (like at the beginning of this thread) it is working
so this is not working:
light:
- platform: mqtt
name: Licht Garage test
state_topic: "stat/testtest/RESULT"
state_value_template: "{{value_json.S29cmnd_D1.STATE }}"
payload_on: 'ON'
payload_off: 'OFF'
command_topic: "cmnd/testtest/Sensor29"
this code is working but with out the state of the switch. if i switch on the light the button jumps back to OFF
light:
- platform: mqtt
name: Licht Garage test
state_topic: "stat/testtest/RESULT"
state_value_template: "{{value_json.S29cmnd_D1.STATE }}"
payload_on: '1, ON'
payload_off: '1, OFF'
command_topic: "cmnd/testtest/Sensor29"
in MQTT Explorer i get this message
state_topic: "stat/testtest/RESULT"
{
"S29cmnd_D1": {
"COMMAND": "ON",
"STATE": "ON"
}
}
Sorry I don’t understand,
What do you need to publish to which topic to turn on/off the light?
@Burningstone
to turn on and off i need to publish the following commands
command_topic: "cmnd/testtest/Sensor29"
payload_on: '1, ON'
payload_off: '1, OFF'
and then the State is published like the following:
{
"S29cmnd_D1": {
"COMMAND": "ON",
"STATE": "ON"
}
}
Ah oke, then try this:
light:
- platform: mqtt
name: Licht Garage test
state_topic: "stat/testtest/RESULT"
state_value_template: "1, {{value_json.S29cmnd_D1.STATE }}"
payload_on: "1, ON"
payload_off: "1, OFF"
command_topic: "cmnd/testtest/Sensor29"
1 Like
@Burningstone
perfect!!! thanks
now the code looks like this. i m using an MCP23017 with an Wemos D1 mini to control 8 Relay and 6 Inputs.
light:
- platform: mqtt
name: Licht Garage
state_topic: "stat/garage/RESULT"
state_value_template: "0, {{value_json.S29cmnd_D0.STATE }}"
payload_on: "0, ON"
payload_off: "0, OFF"
command_topic: "cmnd/garage/Sensor29"
- platform: mqtt
name: Licht Garagenweg
state_topic: "stat/garage/RESULT"
state_value_template: "1, {{value_json.S29cmnd_D1.STATE }}"
payload_on: "1, ON"
payload_off: "1, OFF"
command_topic: "cmnd/garage/Sensor29"
- platform: mqtt
name: Output3
state_topic: "stat/garage/RESULT"
state_value_template: "Pin2, {{value_json.S29cmnd_D2.STATE }}"
payload_on: "Pin2, ON"
payload_off: "Pin2, OFF"
command_topic: "cmnd/garage/Sensor29"
and so on...................... Pin 0 to Pin 15
1 Like