peterbuga / HASS-sonoff-ewelink

Home Assistant component to control Sonoff/eWeLink devices with original firmware
MIT License
794 stars 293 forks source link

New Device: eWeLink Essential Oil Diffuser #83

Open sfgabe opened 5 years ago

sfgabe commented 5 years ago

Thanks for this component!

FYI: The eWeLink Essential Oil Aromatherapy Diffuser works with this component, as outlined on the HA thread. It works for turning the device on/off (not for controlling the LED light though).

peterbuga commented 5 years ago

Hi @sfgabe thanks for reaching out! Maybe you've seen or maybe not but in the original thread in community.home-assistant.io someone already mentioned a similar device before but failed to follow up with the data I need to implement this.

Please run the sonoff-debug.py script and generate as many outputs as you can on/off, different light colours, different intensities (wouldn't hurt to attach a screenshot or 2) and name the outputs accordingly (something like here https://github.com/peterbuga/HASS-sonoff-ewelink/issues/78#issuecomment-478785461). without this info there's nothing much I can do, I could guess how it might work but it'll be a big trial'n'error on my side which i try to avoid.

PS: i would probably won't implement this anytime soon, as there are other devices in the queue (issues) that i want to take care of, i hope you understand.

rwlove commented 5 years ago

EDIT: I'm running branch 'master-HA0.88+'.

EDIT 2: Bug was a result of user error. On/Off works with the above branch on HAS v0.90.2.

peterbuga commented 5 years ago

@rwlove according to the history of edits, the dump clearly stated that "online": false, basically means that your device was unplugged or problems connecting to wifi.

btw, feel free to provide more sonoff-debug.py just like the one you removed it as i requested above. they are mandatory for me to be able to add this new device!

sfgabe commented 5 years ago

Hi Peter,

Here's my (working) output.

[
  {
    "__v": 0, 
    "_id": "[hidden]", 
    "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
    "brandLogoUrl": "", 
    "brandName": "KOMEITO", 
    "createdAt": "xxxx-xx-xxxxx:xx:xx.xxx", 
    "deviceStatus": "", 
    "deviceUrl": "", 
    "deviceid": "[hidden]", 
    "devicekey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
    "extra": {
      "_id": "[hidden]", 
      "extra": {
        "apmac": "xx:xx:xx:xx:xx:xx", 
        "brandId": "5971b5ce48b2ec2c22a03b86", 
        "description": "20181128002", 
        "mac": "xx:xx:xx:xx:xx:xx", 
        "manufacturer": "\u6df1\u5733\u5e02\u5e1d\u62d3\u7535\u5b50\u6709\u9650\u516c\u53f8", 
        "model": "PSA-BTA-GL", 
        "modelInfo": "59e5d1f95c1af3a660cdea90", 
        "staMac": "xx:xx:xx:xx:xx:xx", 
        "ui": "\u9999\u85b0\u673a", 
        "uiid": 25
      }
    }, 
    "group": "", 
    "groups": [], 
    "ip": "[hidden]", 
    "location": "", 
    "name": "[hidden]",, 
    "offlineTime": "xxxx-xx-xxxxx:xx:xx.xxx", 
    "online": true, 
    "onlineTime": "xxxx-xx-xxxxx:xx:xx.xxx", 
    "params": {
      "bindInfos": {
        "alexa": [
          "1f540545-94ba-4723-8971-7ea3db7f1871_26ca1996a20e8bd63617ab272d4eeede1d2d8e32"
        ]
      }, 
      "fwVersion": "2.0.2", 
      "lightBcolor": 0, 
      "lightGcolor": 165, 
      "lightRcolor": 255, 
      "lightbright": 100, 
      "lightmode": 1, 
      "lightswitch": 0, 
      "partnerApikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
      "rssi": -55, 
      "staMac": "xx:xx:xx:xx:xx:xx", 
      "state": 2, 
      "switch": "off", 
      "water": 0
    }, 
    "productModel": "1515-X", 
    "settings": {
      "alarmNotify": 1, 
      "opsHistory": 1, 
      "opsNotify": 0
    }, 
    "sharedTo": [], 
    "showBrand": true, 
    "type": "10", 
    "uiid": 25
  }
]
rwlove commented 5 years ago

Here's sonoff-debug dump, again, with it turned on this time. Thanks for your work on this.

[
  {
    "__v": 0, 
    "_id": "[hidden]", 
    "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
    "brandLogoUrl": "", 
    "brandName": "KOMEITO", 
    "createdAt": "xxxx-xx-xxxxx:xx:xx.xxx", 
    "deviceStatus": "", 
    "deviceUrl": "", 
    "deviceid": "[hidden]", 
    "devicekey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
    "extra": {
      "_id": "[hidden]", 
      "extra": {
        "apmac": "xx:xx:xx:xx:xx:xx", 
        "brandId": "5971b5ce48b2ec2c22a03b86", 
        "description": "20180509004", 
        "mac": "xx:xx:xx:xx:xx:xx", 
        "manufacturer": "\u6df1\u5733\u5e02\u5e1d\u62d3\u7535\u5b50\u6709\u9650\u516c\u53f8", 
        "model": "PSA-BTA-GL", 
        "modelInfo": "59e5d1f95c1af3a660cdea90", 
        "staMac": "xx:xx:xx:xx:xx:xx", 
        "ui": "\u9999\u85b0\u673a", 
        "uiid": 25
      }
    }, 
    "group": "", 
    "groups": [], 
    "ip": "[hidden]", 
    "location": "", 
    "name": "[hidden]",, 
    "offlineTime": "xxxx-xx-xxxxx:xx:xx.xxx", 
    "online": true, 
    "onlineTime": "xxxx-xx-xxxxx:xx:xx.xxx", 
    "params": {
      "fwVersion": "2.7.0", 
      "lightBcolor": 0, 
      "lightGcolor": 78, 
      "lightRcolor": 255, 
      "lightbright": 100, 
      "lightmode": 1, 
      "lightswitch": 0, 
      "rssi": -59, 
      "sledOnline": "on", 
      "staMac": "xx:xx:xx:xx:xx:xx", 
      "state": 2, 
      "switch": "off", 
      "timers": [
        {
          "at": "0 3 * * 1,2,3,4,5,6,0", 
          "coolkit_timer_type": "repeat", 
          "do": {
            "switch": "on"
          }, 
          "enabled": 1, 
          "mId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
          "type": "repeat"
        }, 
        {
          "at": "45 3 * * 1,2,3,4,5,6,0", 
          "coolkit_timer_type": "repeat", 
          "do": {
            "switch": "off"
          }, 
          "enabled": 1, 
          "mId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
          "type": "repeat"
        }
      ], 
      "water": 1
    }, 
    "productModel": "1515-X", 
    "settings": {
      "alarmNotify": 1, 
      "opsHistory": 1, 
      "opsNotify": 0
    }, 
    "sharedTo": [], 
    "showBrand": true, 
    "type": "10", 
    "uiid": 25
  }
]
sfgabe commented 5 years ago

...and here's the output with it on, which goes with the attached screenshot.

Screenshot_20190405-010157

[
  {
    "__v": 0, 
    "_id": "[hidden]", 
    "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
    "brandLogoUrl": "", 
    "brandName": "KOMEITO", 
    "createdAt": "xxxx-xx-xxxxx:xx:xx.xxx", 
    "deviceStatus": "", 
    "deviceUrl": "", 
    "deviceid": "[hidden]", 
    "devicekey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
    "extra": {
      "_id": "[hidden]", 
      "extra": {
        "apmac": "xx:xx:xx:xx:xx:xx", 
        "brandId": "5971b5ce48b2ec2c22a03b86", 
        "description": "20181128002", 
        "mac": "xx:xx:xx:xx:xx:xx", 
        "manufacturer": "\u6df1\u5733\u5e02\u5e1d\u62d3\u7535\u5b50\u6709\u9650\u516c\u53f8", 
        "model": "PSA-BTA-GL", 
        "modelInfo": "59e5d1f95c1af3a660cdea90", 
        "staMac": "xx:xx:xx:xx:xx:xx", 
        "ui": "\u9999\u85b0\u673a", 
        "uiid": 25
      }
    }, 
    "group": "", 
    "groups": [], 
    "ip": "[hidden]", 
    "location": "", 
    "name": "[hidden]",, 
    "offlineTime": "xxxx-xx-xxxxx:xx:xx.xxx", 
    "online": true, 
    "onlineTime": "xxxx-xx-xxxxx:xx:xx.xxx", 
    "params": {
      "bindInfos": {
        "alexa": [
          "1f540545-94ba-4723-8971-7ea3db7f1871_26ca1996a20e8bd63617ab272d4eeede1d2d8e32"
        ]
      }, 
      "fwVersion": "2.0.2", 
      "lightBcolor": 0, 
      "lightGcolor": 165, 
      "lightRcolor": 255, 
      "lightbright": 100, 
      "lightmode": 1, 
      "lightswitch": 1, 
      "partnerApikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
      "rssi": -52, 
      "staMac": "xx:xx:xx:xx:xx:xx", 
      "state": 2, 
      "switch": "on", 
      "water": 1
    }, 
    "productModel": "1515-X", 
    "settings": {
      "alarmNotify": 1, 
      "opsHistory": 1, 
      "opsNotify": 0
    }, 
    "sharedTo": [], 
    "showBrand": true, 
    "type": "10", 
    "uiid": 25
  }
]
sfgabe commented 5 years ago

I played around a bit with this to see what I could get going locally - it works as far as seeing the sensor data in HA. How to visualize RGB data when it comes as separate strings like that is beyond my knowledge, but the bare-bones data is there. Hopefully it can save someone some time on your side.

I havn't dug into switches but here are the additional sensors/sonoff.py additions for this device:

    'water'                 : { 'eid' : 'water',       'uom' : '%',            'icon' : 'mdi:water-percent' },
    'state'                 : { 'eid' : 'state',       'uom' : 'W',            'icon' : 'mdi:help' },
    'lightswitch'           : { 'eid' : 'lightswitch', 'uom' : 'W',            'icon' : 'mdi:lightbulb' },
    'lightBcolor'           : { 'eid' : 'lightBcolor', 'uom' : 'X',            'icon' : 'mdi:palette' },
    'lightGcolor'           : { 'eid' : 'lightGcolor', 'uom' : 'X',            'icon' : 'mdi:palette' },
    'lightRcolor'           : { 'eid' : 'lightRcolor', 'uom' : 'X',            'icon' : 'mdi:palette' },
    'lightbright'           : { 'eid' : 'lightbright', 'uom' : 'X',            'icon' : 'mdi:lightbulb-on' },
    'lightmode'             : { 'eid' : 'lightmode',   'uom' : 'W',            'icon' : 'mdi:theme-light-dark' },

...and in the main sonoff.py file:

        # Humidifier only:
        if 'water' in device['params']: 
            self._attributes['water'] = device['params']['water']
        if 'state' in device['params']: 
            self._attributes['state'] = device['params']['state']
        if 'lightswitch' in device['params']: 
            self._attributes['lightswitch'] = device['params']['lightswitch']
        if 'lightmode' in device['params']: 
            self._attributes['lightmode'] = device['params']['lightmode']
        if 'lightBcolor' in device['params']: 
            self._attributes['lightBcolor'] = device['params']['lightBcolor']
        if 'lightRcolor' in device['params']: 
            self._attributes['lightRcolor'] = device['params']['lightRcolor']
        if 'lightGcolor' in device['params']: 
            self._attributes['lightGcolor'] = device['params']['lightGcolor']
        if 'lightbright' in device['params']: 
            self._attributes['lightbright'] = device['params']['lightbright']

Here's what that produces in a HA card: Screen Shot 2019-04-05 at 4 25 25 PM

2016for commented 5 years ago

Great job @sfgabe!

Gives a starting point for a lot of people. This will help a lot of people trying to add devices and relieving some load on Peter. :)

peterbuga commented 5 years ago

@sfgabe it's a start 👍 but a bit more needs to be done.

also I took the time and I updated the component to have a more complex, richer & much easier way to output the debug information. please take a look at the latest master branch and make sure to read the new installation options + debug section if you're in the mood to generate a new log file. ps: backup your files ;)

sfgabe commented 5 years ago

Here's the new log file

[
  {
    "__v": 0,
    "_id": "[hidden]",
    "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "brandLogoUrl": "",
    "brandName": "KOMEITO",
    "createdAt": "xxxx-xx-xxxxx:xx:xx.xxx",
    "deviceStatus": "",
    "deviceUrl": "",
    "deviceid": "[hidden]",
    "devicekey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "extra": {
      "_id": "[hidden]",
      "extra": {
        "apmac": "xx:xx:xx:xx:xx:xx",
        "brandId": "5971b5ce48b2ec2c22a03b86",
        "description": "20181128002",
        "mac": "xx:xx:xx:xx:xx:xx",
        "manufacturer": "\u6df1\u5733\u5e02\u5e1d\u62d3\u7535\u5b50\u6709\u9650\u516c\u53f8",
        "model": "PSA-BTA-GL",
        "modelInfo": "59e5d1f95c1af3a660cdea90",
        "staMac": "xx:xx:xx:xx:xx:xx",
        "ui": "\u9999\u85b0\u673a",
        "uiid": 25
      }
    },
    "group": "",
    "groups": [],
    "ip": "[hidden]",
    "location": "",
    "name": "[hidden]",,
    "offlineTime": "xxxx-xx-xxxxx:xx:xx.xxx",
    "online": true,
    "onlineTime": "xxxx-xx-xxxxx:xx:xx.xxx",
    "params": {
      "bindInfos": {
        "alexa": [
          "1f540545-94ba-4723-8971-7ea3db7f1871_26ca1996a20e8bd63617ab272d4eeede1d2d8e32"
        ]
      },
      "fwVersion": "2.0.2",
      "lightBcolor": 0,
      "lightGcolor": 165,
      "lightRcolor": 255,
      "lightbright": 100,
      "lightmode": 1,
      "lightswitch": 0,
      "partnerApikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
      "rssi": -55,
      "staMac": "xx:xx:xx:xx:xx:xx",
      "state": 2,
      "switch": "off",
      "water": 1
    },
    "productModel": "1515-X",
    "settings": {
      "alarmNotify": 1,
      "opsHistory": 1,
      "opsNotify": 0
    },
    "sharedTo": [],
    "showBrand": true,
    "type": "10",
    "uiid": 25
  }
]
sfgabe commented 5 years ago

Hmmm, output looks the same. Did I miss something? I was using the debug script, is there a new way?

peterbuga commented 5 years ago

actually yes, my bad! i forgot to completely update the requests/bugs README section but as I mentioned above you have to download the latest master branch code and add debug: True in your sonoff configuration.yaml after that follow these steps:

debug if enabled this will give you the ability to generate a log of messages from ewelink that can be easily posted here to debug/implement new devices. it works by creating a pseudo switch switch.sonoff_debug (notice it won't show up automatically in frontend in lovelace you have to manually add it or toggle it manually from Developer tools > Services section). to generate a sonoff debug log toggle the pseudo-switch ON, the capture of messages starts in the background. now pick up the phone -> open eWeLink app and start changing settings of your Sonoff device but not faster than 10 seconds, when you finish, toggle the pseudo-switch OFF and a new (very long) persistent notification will show up, go to Developer tools > States section and look for a persistent_notification.notification entity (impossible to miss) and copy the message from there (to remove this notifications and others Dismiss them from main HA notifications area and you can restart the process if needed). INFORMATION: it'll be better if you share the device-to-debugged to a 2nd eWeLink account and use this in HA and main one in mobile app NOTICE: you should NOT leave debug-mode enabled for everyday use, please just please don't!

on top of steps above, it'll be nice if you could make a list of actions you've done in mobile app so that i can sync them with the log entries, for example ON/OFF, light to red, increase humidity etc... and try to make a pause of 10-15seconds between actions

ps: i got to work this weekend on the Sonoff B1 device witch is more or less the same regarding the rgb-color part of this frankenstein of device, most of the code is already done i would just need to patch the right information from debug log

peterbuga commented 5 years ago

@sfgabe based on some new information i gathered this weekend working on another device, i think the best way (so far) to integrate this device and making it compatible with HA is by splitting it in different entities:

due to limitations of HA (and also my limited knowledge about HA structure) at this moment i'm fairly confident that i cannot mix all device's parts in a single entity, but you could custom merge them as a 2nd step in some kind of custom card inside HA or something similar. if you find out please let me know too 😅 also i'm open to ideas or changes of the structure i mentioned above!

2016for commented 5 years ago

@peterbuga that sounds like the best option, @sfgabe you could use a group: to display it in a better way in HA. I have multiple sensors for my washer dryer which I have added to a group to display complete status.

On Tue, Apr 9, 2019 at 11:17 PM Peter Buga notifications@github.com wrote:

@sfgabe https://github.com/sfgabe based on some new information i gathered this weekend working on another device, i think the best way (so far) to integrate this device and making it compatible with HA is by splitting it in different entities:

  • the color light & night will be a light entity with options to change: on/off state, change between the type of light, brightness in both modes (i tend to believe that brightness is missing in color mode) (and optionally the ability to turn on in the same time the night-color lights if anyone thinks they need to go this far)
  • the diffuser part will be a fan entity with option to change: on/off state and low/high levels
  • the water level with be a (binary) sensor entity

due to limitations of HA (and also my limited knowledge about HA structure) at this moment i'm fairly confident that i cannot mix all device's parts in a single entity, but you could custom merge them as a 2nd step in some kind of custom card inside HA or something similar. if you find out please let me know too 😅 also i'm open to ideas or changes of the structure i mentioned above!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/peterbuga/HASS-sonoff-ewelink/issues/83#issuecomment-481360404, or mute the thread https://github.com/notifications/unsubscribe-auth/AqJgbIn3Vn7Gug65O9jw4I5ZNl4JNFc0ks5vfNIcgaJpZM4cZZNf .

sfgabe commented 5 years ago

@peterbuga thanks for the detailed description, I could see the new debug code in the update so I figured the docs hadn't been updated yet. I finally got a chance to test it.

It should be pretty self explanatory but I turned it on and off, switched from "night mode" to "color light", changed the light color, turned the light off and on, adjusted the brightness up and down, and switched from low to high.

Here's the log:

sonoff-debug-log.txt

sfgabe commented 5 years ago

@peterbuga that sounds like the best option, @sfgabe you could use a group: to display it in a better way in HA. I have multiple sensors for my washer dryer which I have added to a group to display complete status.

@2016for I'm not worried about the display, I can see details no problem. The trick is toggling the different options (it has more than on/off).

Swiftnesses commented 5 years ago

Devices can be grouped (at least via discovery) by implementing the same device information on all entities, so HA knows which entities should be grouped!

For example, I use discovery for my MQTT blind implementation and use:

{
  "name": "MOVE - Living Room - Front Left",
  "position_topic": "homeassistant/cover/living_room/front_left/position",
  "set_position_topic": "homeassistant/cover/living_room/front_left/set_position",
  "json_attributes_topic": "homeassistant/cover/living_room/front_left/attributes",
  "position_open": 100,
  "position_closed": 0,
  "device_class": "shade",
  "optimistic": false,
  "qos": 0,
  "unique_id": "move_living_room_front_left",
  "device": {
      "identifiers": "move_living_room_front_left",
      "manufacturer": "Teptron",
      "model": "Bluetooth Edition",
      "name": "Move Blind"
  }
}

AND

{
  "name": "MOVE - Living Room - Front Left - Status",
  "state_topic": "homeassistant/sensor/blinds_status/living_room_front_left/state",
  "json_attributes_topic": "homeassistant/sensor/blinds_status/living_room_front_left/attributes",
  "icon": "mdi:comment-text",
  "qos": 0,
  "unique_id": "move_living_room_front_left_status",
  "device": {
      "identifiers": "move_living_room_front_left",
      "manufacturer": "Teptron",
      "model": "Bluetooth Edition",
      "name": "Move Blind"
  }
}

These both appear together under discovery.

Swiftnesses commented 5 years ago

@sfgabe was this implemented? Considering picking up a unit!

orlandogil2007 commented 4 years ago

Hi I found the codes for this model, they are commands “AT + UPDATE =” serial codes similar to sonoff-L1

Diffuser and Light ON FAN LOW backlog serialsend4 AT+UPDATE=“sequence”:“1579752745631”,“switch”:“on”,“state”:1; serialsend5 1B

Diffuser and Light ON FAN HIGH backlog serialsend4 AT+UPDATE=“sequence”:“1579752745631”,“switch”:“on”,“state”:2; serialsend5 1B Diffuser and Light OFF FAN OFF(LOW) backlog serialsend4 AT+UPDATE=“sequence”:“1579752745631”,“switch”:“off”,“state”:1; serialsend5 1B

20200116_205558 Diffuser

Thrasher2020 commented 4 years ago

Did this progress any further? My sonoff diffuser simply gives me on/off

SvetZitrka commented 3 years ago

How did you find out that this diffuser would be controlled in front of eWeLink? I have a Unlike Vocolink at home and I would also integrate it into a Home Assistant https://www.vocolinc.cz/p/157/vocolinc-smart-aroma-flowerbud