Improve MQTT switch support.

This commit is contained in:
Koen Kanters
2018-04-24 19:03:09 +02:00
parent 8673fa27e2
commit e0feacea0b
3 changed files with 11 additions and 4 deletions
+8 -1
View File
@@ -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];
+1 -1
View File
@@ -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'],
+2 -2
View File
@@ -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
}