ilcato / homebridge-mqttswitch

Homebridge accessory plugin that create an HomeKit Switch based on MQTT topics
Apache License 2.0
31 stars 41 forks source link

How do I enable logging? #17

Closed SupraJames closed 6 years ago

SupraJames commented 6 years ago

Trying to diagnose an issue where my device actual status isn't being updated (Sonoff). Read through the other issues but they all pre-date the current revision.

I see the code logs certain messages but I don't see it in syslog even with *DEBUG= homebridge** set.

SupraJames commented 6 years ago

Oh, never mind - I can see the plugin doesn't actually do much logging at all. Going to add in some log output and track this issue.

bdavies commented 6 years ago

Hey SupraJames just wondering if you got anywhere with this? I'm having the same issue

SupraJames commented 6 years ago

I added some logging around the functions and it was then quite apparent I'd messed up the config. Basically I had set 'integerValue' to FALSE to use 'ON' and 'OFF' as my status, but the correct thing to do was not set integerValue to anything.

Here's the extract from index.js. It shows you message coming in and how they compare to what the code is expecting:

    this.client.on('message', function (topic, message) {
        that.log('MQTT RX: ' + topic + ' ' + message);
        if (topic == that.topicStatusGet) {
            var status = message.toString();
        that.log('STATUS is ' + status);
        that.log('that.onValue: ' + that.onValue + ' that.offValue: ' + that.offValue);
            if (status == that.onValue || status == that.offValue) {
        that.log('Updating HomeKit Status');
                that.switchStatus = (status == that.onValue) ? true : false;
                that.service.getCharacteristic(Characteristic.On).setValue(that.switchStatus, undefined, 'fromSetValue');
            }
        }
    });
bdavies commented 6 years ago

Thanks for the quick response! I also just realised my config was slightly incorrect and now all appears to be working.

I had ON/OFF values nested inside topics in the JSON.

SupraJames commented 6 years ago

nice one :)