howanghk / homebridge-ewelink

Homebridge plugin to control Sonoff relays with OEM firmware
MIT License
81 stars 46 forks source link

Sonoff micro #81

Closed galaxydpw closed 4 years ago

galaxydpw commented 4 years ago

It just fails with sonoff micro. It is populated into homekit, but with an error icon

gsvan commented 4 years ago

Hi,

I also have some issues with SONOFF MICRO - 5V WIRELESS USB SMART ADAPTOR. Link: https://www.itead.cc/sonoff-micro-5v-usb-smart-adaptor.html

To elaborate on this:

1) It adds the device with no issues to homebridge and to homekit but it does not work.

2) If I toggle the switch from homebridge or homekit it toggles but does not change the state of the physical device. i.e device stays in whatever state it currently is.

3) If I toggle the switch from the eWeLink app device changes state as normal but homebridge logs problems see below. Not sure why it is trying to add 4ch when it's only 1 micro switch.


[3/15/2020, 13:41:57] [eWeLink] WebSocket messge received: {"action":"update","deviceid":"1000d4b4bf","apikey":"198d4687-3321-4571-aea5-6c1fa5eb87a3","userAgent":"app","sequence":"1584279717334","ts":0,"params":{"switches":[{"switch":"off","outlet":0},{"switch":"off","outlet":1},{"switch":"off","outlet":2},{"switch":"off","outlet":3}]},"tempRec":"1000d4b4bf"} [3/15/2020, 13:41:57] [eWeLink] Update message received for device [1000d4b4bf] [3/15/2020, 13:41:57] [eWeLink] { action: 'update', deviceid: '1000d4b4bf', apikey: '198d4687-3321-4571-aea5-6c1fa5eb87a3', userAgent: 'app', sequence: '1584279717334', ts: 0, params: { switches: [ [Object], [Object], [Object], [Object] ] }, tempRec: '1000d4b4bf' } [3/15/2020, 13:41:57] [eWeLink] Adding accessory for deviceId [1000d4b4bfCH1]. [3/15/2020, 13:41:57] [eWeLink] Found Accessory with Name : [G’s Audio CH 1], Manufacturer : [Micro], Status : [off], Is Online : [true], API Key: [198d4687-3321-4571-aea5-6c1fa5eb87a3] [3/15/2020, 13:41:57] [eWeLink] Device type for 77 is [3/15/2020, 13:41:57] [eWeLink] Can't add [G’s Audio CH 1], because device [Micro] has only [0] switches. [3/15/2020, 13:41:57] [eWeLink] Error updating non-exist accessory with deviceId [1000d4b4bfCH1]. [3/15/2020, 13:41:57] [eWeLink] Adding accessory for deviceId [1000d4b4bfCH2]. [3/15/2020, 13:41:57] [eWeLink] Found Accessory with Name : [G’s Audio CH 2], Manufacturer : [Micro], Status : [off], Is Online : [true], API Key: [198d4687-3321-4571-aea5-6c1fa5eb87a3] [3/15/2020, 13:41:57] [eWeLink] Device type for 77 is [3/15/2020, 13:41:57] [eWeLink] Can't add [G’s Audio CH 2], because device [Micro] has only [0] switches. [3/15/2020, 13:41:57] [eWeLink] Error updating non-exist accessory with deviceId [1000d4b4bfCH2]. [3/15/2020, 13:41:57] [eWeLink] Adding accessory for deviceId [1000d4b4bfCH3]. [3/15/2020, 13:41:57] [eWeLink] Found Accessory with Name : [G’s Audio CH 3], Manufacturer : [Micro], Status : [off], Is Online : [true], API Key: [198d4687-3321-4571-aea5-6c1fa5eb87a3] [3/15/2020, 13:41:57] [eWeLink] Device type for 77 is [3/15/2020, 13:41:57] [eWeLink] Can't add [G’s Audio CH 3], because device [Micro] has only [0] switches. [3/15/2020, 13:41:57] [eWeLink] Error updating non-exist accessory with deviceId [1000d4b4bfCH3]. [3/15/2020, 13:41:57] [eWeLink] Adding accessory for deviceId [1000d4b4bfCH4]. [3/15/2020, 13:41:57] [eWeLink] Found Accessory with Name : [G’s Audio CH 4], Manufacturer : [Micro], Status : [off], Is Online : [true], API Key: [198d4687-3321-4571-aea5-6c1fa5eb87a3] [3/15/2020, 13:41:57] [eWeLink] Device type for 77 is [3/15/2020, 13:41:57] [eWeLink] Can't add [G’s Audio CH 4], because device [Micro] has only [0] switches. [3/15/2020, 13:41:57] [eWeLink] Error updating non-exist accessory with deviceId [1000d4b4bfCH4].

adipoos commented 4 years ago

Same issue here :(

dhutchison commented 4 years ago

This is just a note that I've got a bit of tidying up to do before submitting a PR, but I've got it to work with a few changes to the plugin. Half these changes are additional debug logging. It does report from the API as a 4 channel device, with only channel 1 actually controlling the switch state. It doesn't feel right showing 3 useless devices in Home.

I'll likely take another look at this over the next few days to see if I can tidy it up.

A diff of my current changes is below.

index 09dfeb3..dcbbd00 100644
--- a/index.js
+++ b/index.js
@@ -1034,6 +1034,8 @@ eWeLink.prototype.getPowerState = function (accessory, callback) {

     this.webClient.get('/api/user/device?' + this.getArguments(), function (err, res, body) {

+        platform.log(body)
+
         if (err) {
             if ([503].indexOf(parseInt(res.statusCode)) !== -1) {
                 // callback('An error was encountered while requesting a list of devices to interrogate power status for your device');
@@ -1081,6 +1083,8 @@ eWeLink.prototype.getPowerState = function (accessory, callback) {

             if (device.deviceid === deviceId) {

+                platform.log(device.params)
+
                 if (device.online !== true) {
                     accessory.reachable = false;
                     platform.log("Device [%s] was reported to be offline by the API", accessory.displayName);
@@ -2062,6 +2066,7 @@ eWeLink.prototype.getDeviceTypeByUiid = function (uiid) {
         56: "RGB_BALL_LIGHT_4",
         57: "MONOCHROMATIC_BALL_LIGHT",
         59: "MEARICAMERA",
+        77: "MICRO",
         1001: "BLADELESS_FAN",
         1002: "NEW_HUMIDIFIER",
         1003: "WARM_AIR_BLOWER"
@@ -2079,6 +2084,7 @@ eWeLink.prototype.getDeviceChannelCountByType = function (deviceType) {
         SOCKET_POWER: 1,
         GSM_SOCKET: 1,
         POWER_DETECTION_SOCKET: 1,
+        MICRO: 4,
         SOCKET_2: 2,
         GSM_SOCKET_2: 2,
         SWITCH_2: 2,
gsvan commented 4 years ago

Hi dhutchison, Thank you for having a look at it, i have no idea how to fix it or make it work. Looking forward to having it work finally. Let us know please when you manage it. Cheers

howanghk commented 4 years ago

I have merged the pull request from dhutchison and released a new version 0.1.21. Thank you.

gsvan commented 4 years ago

Thank you so much guys i just update, it works. it added all 4 channels and only channel 1 is controlling it as dhutchison mentioned in previous message. great job.