mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-14 06:40:05 +00:00
Improve MQTT switch support.
This commit is contained in:
+8
-1
@@ -156,7 +156,14 @@ class Controller {
|
||||
}
|
||||
|
||||
// Convert the MQTT message to a Zigbee message.
|
||||
const json = JSON.parse(message);
|
||||
let json = null;
|
||||
try {
|
||||
json = JSON.parse(message);
|
||||
} catch (e) {
|
||||
// Cannot be parsed to JSON, assume state message.
|
||||
json = {state: message.toString()};
|
||||
}
|
||||
|
||||
Object.keys(json).forEach((key) => {
|
||||
// Find converter for this key.
|
||||
const converter = mqtt2zigbee[key];
|
||||
|
||||
@@ -195,7 +195,7 @@ const parsers = [
|
||||
devices: ['ZNCZ02LM'],
|
||||
cid: 'genOnOff',
|
||||
type: 'attReport',
|
||||
convert: (msg) => {return {state: msg.data.data['onOff'] === 1 ? '{"state": "ON"}': '{"state": "OFF"}'}}
|
||||
convert: (msg) => {return {state: msg.data.data['onOff'] === 1 ? "ON" : "OFF"}}
|
||||
},
|
||||
{
|
||||
devices: ['ZNCZ02LM'],
|
||||
|
||||
@@ -122,8 +122,8 @@ const homeassistant = {
|
||||
type: 'switch',
|
||||
object_id: 'switch',
|
||||
discovery_payload: {
|
||||
payload_off: '{"state": "OFF"}',
|
||||
payload_on: '{"state": "ON"}',
|
||||
payload_off: 'OFF',
|
||||
payload_on: 'ON',
|
||||
value_template: '{{ value_json.state }}',
|
||||
command_topic: true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user