MacWyznawca / homebridge-mqtt-switch-tasmota

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

No Status-Update for "Sonoff Dual" and "Sonoff T1" Dual Wall-Switch in HomeKit App #15

Closed Sonsi79 closed 6 years ago

Sonsi79 commented 7 years ago

Hi, im using "Sonoff T1 - 2 Channel" and "Sonoff Dual" switches which work similar with your Plugin. I'm able to switch every Button on and off by pressing button on switch and also by using HomeKit (Siri).

But if i press the button on the switch, the status isn't updated in HomeKit :-( In Homekit the Status is still "Off" but the Switch is turned "On". By double press in HomeKit i'm able to switch it Off. I also use Sonoff Touch (Same Wall Switch but only one Button) and this one works perfectly.

I think this error ist by using the State command or reading out the result in MQTT.

I have to use POWER1 and RESULT1 for the first Button, but STATE for getting the State of both Buttons.

Here's a part of my MQTT Log (in Sonoff Switch) during using Dual Switch:

09:30:26 MQTT: tele/Wohnzimmer/STATE = {"Time":"2017-09-30T09:30:26", "Uptime":0, "Vcc":3.111, "POWER1":"ON", "POWER2":"OFF", "Wifi":{"AP":1, "SSID":"Sonsi 2", "RSSI":76, "APMac":"6C:70:9F:DD:43:48"}} 09:30:26 MQTT: stat/Wohnzimmer/RESULT = {"POWER1":"ON"} 09:30:26 MQTT: stat/Wohnzimmer/POWER1 = ON 09:30:26 MQTT: stat/Wohnzimmer/RESULT = {"POWER2":"OFF"} 09:30:26 MQTT: stat/Wohnzimmer/POWER2 = OFF

Here's my Config for 1 Switch:

        {
        "accessory": "mqtt-switch-tasmota",
        "switchType": "switch",
        "url": "mqtt://192.168.1.190",
        "topics": {
            "statusGet": "stat/Wohnzimmer/RESULT1",
            "statusSet": "cmnd/Wohnzimmer/POWER1",
            "stateGet": "tele/Wohnzimmer/STATE"
        },
        "name": "Wohnzimmerschalter Links"
    },
    {
        "accessory": "mqtt-switch-tasmota",
        "switchType": "switch",
        "url": "mqtt://192.168.1.190",
        "topics": {
            "statusGet": "stat/Wohnzimmer/RESULT2",
            "statusSet": "cmnd/Wohnzimmer/POWER2",
            "stateGet": "tele/Wohnzimmer/STATE"
        },
        "name": "Wohnzimmerschalter Rechts"
    },

Where is my fault? Is it necessary to put both commands (POWER1 oder POWER2) as 1 Accessory in your Plugin?

Thanks for your great plugin an your help

Sonsi79 commented 7 years ago

I have found the fix. Maybe you can fix it global on Server. You posted that the "index.js" was updates 2 month ago. But installing your Plugin didn't use this (modified /fixed) version.

I just have to manually upload the modifies index.js an everything works great :-)

Sonsi79 commented 7 years ago

Damn :-( With this fix (modified index.js) the status of "normal" 1-way switch isn't updated during start of HomeKit App. When the app is open it work, but when Home app is closed and start up the status is every time "off"

sfanicola commented 7 years ago

Try to add this to your config file:

        "onValue": "TOGGLE",
        "offValue": "OFF",
                    "activityTopic": "tele/Wohnzimmer/LWT",
                    "activityParameter": "Online",
                    "startCmd": "cmnd/Wohnzimmer/TelePeriod",
                    "startParameter": "60"
sfanicola commented 7 years ago

Did it work? I have the opposite problem! With that configuration once I press to activate it remains on on homekit, even if with the PulseTime turns it off after a while.

sfanicola commented 6 years ago

Any news? Still the same issue here! I tried a lot without success. Neither my previous suggestion works.

Sonsi79 commented 6 years ago

I have fix it by edit the code in „Index.js“ I will Post my mods later this day It Works 100% with normal and Dual.

sfanicola commented 6 years ago

Great! Can’t wait to get it!

Sonsi79 commented 6 years ago

Hey sfanicola, sorry for my delay :-) Here are my mods in the index.js, just search, replace and restart. In my case the index.js ist located in /usr/local/lib/node_modules/homebridge-mqtt-switch-tasmota

Search in index.js for:

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

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();
}

and change it in:

MqttSwitchTasmotaAccessory.prototype.getStatus = function(callback) {
    if (this.activeStat) {
        this.log("Power state for '%s' is %s", this.name, this.switchStatus);
        callback(null, this.switchStatus);
    } else {
        this.log("'%s' is offline", this.name);
        callback('No Response');
    }
}

MqttSwitchTasmotaAccessory.prototype.setStatus = function(status, callback, context) {
    if (context !== 'fromSetValue') {
        this.switchStatus = status;
        this.log("Set power state on '%s' to %s", this.name, status);
        this.client.publish(this.topicStatusSet, status ? this.onValue : this.offValue, this.publish_options);
    }
    callback();
}

Have also a look on your config.json. You have to use 2 different statusSet for your Sonoff DUAL or Sonoff T1 2-Way or any other 2 or more way switches.

Here is my config of the config.json for my Sonoff Dual, which is working 100%. You have to edit the IP of your MQTT, your Topic set in Tasmota MQTT Settings (in my case "Wohnzimmer"), and the Name for HomeKit.

Button1 ist configured by:

        {
            "accessory": "mqtt-switch-tasmota",
            "switchType": "outlet",
            "url": "mqtt://192.168.1.190",
            "topics": {
                "statusGet": "stat/Wohnzimmer/RESULT",
                "statusSet": "cmnd/Wohnzimmer/POWER1",
                "stateGet": "tele/Wohnzimmer/STATE"
            },
            "activityTopic": "tele/Wohnzimmer/LWT",
            "activityParameter": "Online",
            "name": "Wohnzimmerschalter Links"
        },

Button2 ist configured by:

       {
            "accessory": "mqtt-switch-tasmota",
            "switchType": "outlet",
            "url": "mqtt://192.168.1.190",
            "topics": {
                "statusGet": "stat/Wohnzimmer/RESULT",
                "statusSet": "cmnd/Wohnzimmer/POWER2",
                "stateGet": "tele/Wohnzimmer/STATE"
            },
            "activityTopic": "tele/Wohnzimmer/LWT",
            "activityParameter": "Online",
            "name": "Wohnzimmerschalter Rechts"
        },

Have fun and a happy new year 2018 :-)

Sonsi79 commented 6 years ago

@MacWyznawca Is it possible to build in this changes into your code? It fix the issues with two or more way switches!

Thnx and a happy new year!

sfanicola commented 6 years ago

Happy New Year and thnx for the effort, but it's not working for me... Same issue as before; no update state for dual sonoff. Also many other (not all) basic sonoff's stopped working at all. I had the json already in that way. My index.js wasn't like you wrote it but:

MqttSwitchTasmotaAccessory.prototype.getStatus

 = function(callback) {
    callback(null, this.switchStatus);
}

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();
}

Honestly don't know why... @MacWyznawca please finally fix this!!!

Sonsi79 commented 6 years ago

Hey, did you install the actually Version from Github? Please reinstall it by "rpm -g install homebridge-mqtt-switch-tasmota"

I wrote this guide by using the actually index.js which is on GitHub Mainpage. Maybe there is an error or you have a different Version.

Otherwhise i will post you the complete index.js. Try so completely replace it.

Sonsi79 commented 6 years ago

My complete index.js looks like this. Please replace it completely and tell my your result. Im sure it will work as you wish

I reinstalled my raspberry few days ago. Install everything new and just replace this file and it works.

index.js.zip

imaxi96 commented 6 years ago

Hey,

if i use youre index.js all my devices show the status "not responding" .. I reinstalled everything but it did not work.. Any Idea what i can do?

Thanks!