MacWyznawca / homebridge-mqtt-switch-tasmota

Plugin to HomeBridge optimized to work with firmware Sonoff-Tasmota, MQTT.
MIT License
57 stars 18 forks source link

Offline devices don't appear as offline in homekit #29

Open robbgrrr opened 6 years ago

robbgrrr commented 6 years ago

Hello, I'm running Homebridge on a Mac connecting to 6 devices through a Mosquitto MQTT broker installed on the same machine. The devices are Sonoff (ESP8266) flashed with Tasmota MQTT enabled firmware. I'm using this plugin and most everything is working well; I can control state of the devices through Homekit and get real-time state of the device reported back to Homekit when the device is toggled manually.

My expectation is that when a device goes offline through a loss of power or network, Homekit should show the device as "offline" or some such. But there is no outward indication that the device is in trouble, in fact Homekit still lets me toggle the button on/off and behaves as though all is ok. I can see by monitoring the LWT topic that mosquito does report it as "offline" and if I open the "details" page for the device in Homekit I can see that "status active" = No.

It was suggested that the problem may be in the plugin. That doesn't seem right to me, but I'm asking anyway to be sure.

Is this normal? Any suggestions? [Cut from config.json below]

Thanks very much,

"accessories": [ { "accessory": "mqtt-switch-tasmota", "switchType": "other",

    "name": "POE Switch",

    "url": "mqtt://10.0.1.20",
    "username": "",
    "password": "",

    "topics": {
        "statusGet": "stat/poepwr01/RESULT",
        "statusSet": "cmnd/poepwr01/POWER",
        "stateGet": "tele/poepwr01/STATE"
        },
    "onValue": "ON",
    "offValue": "OFF",

    "activityTopic": "tele/poepwr01/LWT",
    "activityParameter": "Online",

    "startCmd": "cmnd/poepwr01/TelePeriod",
    "startParameter": "60",

    "manufacturer": "ITEAD",
    "model": "Sonoff Basic",
    "serialNumberMAC": "EC:FA:BC:06:1C:44"
    }]
daaf84 commented 6 years ago

I've the same 'problem'. Funny thing is, in the EVE-app, is does say offline....

mriksman commented 6 years ago

I can't make a test until I buy one of these devices, get back home and install the whole thing... But.

Check out; https://github.com/cflurin/homebridge-mvc/blob/master/lib/accessory.js#L225 See how it uses

if (this.reachable) {
...
callback("no_response");

I tested this on another plugin, and it worked.

So for this plugin, I would say for this code;

MqttSwitchTasmotaAccessory.prototype.getStatus = function(callback) {
    if (this.activeStat) {
        callback(null, this.switchStatus);
    } else {
        callback(null);     
    }
}

Change it to;

MqttSwitchTasmotaAccessory.prototype.getStatus = function(callback) {
    if (this.activeStat) {
        callback(null, this.switchStatus);
    } else {
        callback("no_response");        
    }
}

Should probably also modify this;

MqttSwitchTasmotaAccessory.prototype.setStatus = function(status, callback, context) {
    if (context !== 'fromSetValue') {
        this.switchStatus = status;
        this.client.publish(this.topicStatusSet, status ? this.onValue : this.offValue, this.publish_options);
    }
    callback();
}

To;

MqttSwitchTasmotaAccessory.prototype.setStatus = function(status, callback, context) {
    if (this.activeStat) {
              if (context !== 'fromSetValue') {
             this.switchStatus = status;
            this.client.publish(this.topicStatusSet, status ? this.onValue : this.offValue, this.publish_options);
         }
         callback();
    }   else {
        callback("no_response");        
    }
}

If anyone can test this out, I'd love to know if it solved the problem.

ntorring commented 6 years ago

I have just tested this, and it seems to work great! It was the only feature I was missing from this great plugin :)

iandronowicz commented 6 years ago

Is this going to be on the next release? I’m having the exact same problem: on the home app the accesory shows that is off but is actually on. I have to turn it on and then off to turn it off.

cgatnet commented 6 years ago

Good question. This feature would be a great addition 👍🏻😊

i3laze commented 5 years ago

Actually, that solution was pulled recently: https://github.com/MacWyznawca/homebridge-mqtt-switch-tasmota/pull/10

Unfortunately, the NPM-package still not up to date on npmjs.com HomeBridge repository - had to update local index.js manually.

ocombita commented 5 years ago

Updating index.js manually works great! Thanks!!!

iandronowicz commented 5 years ago

O upgraded the index file and now it shows the accesory as “not responding”. The thing is that the accesory is working, is connected to the WiFi, and it is responding... I have to restart homebridge to get it back online. On its own it’s never going back online.

It’s like when it isn’t responding for a moment it won’t even check ever again.

Kepete commented 5 years ago

@mriksman Would there also be a quick status fix for the temperature plugin? https://github.com/MacWyznawca/homebridge-mqtt-temperature-tasmota/blob/master/index.js