Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for New Widetech Dehumidifier (nwt.derh.312en) #1

Closed
gerliczky opened this issue Dec 25, 2020 · 23 comments
Closed

Support for New Widetech Dehumidifier (nwt.derh.312en) #1

gerliczky opened this issue Dec 25, 2020 · 23 comments
Labels

Comments

@gerliczky
Copy link

Dear @al-one ,
I have successfully added hass-xiaomi-miot addon in HACS as custom repository. I managed to add my New Widetech Dehumidifier (nwt.derh.312en) device on the integration page in Home Assistant.
My problem is that I do not see my device neither devices nor in entities.
I assume this device is not yet supported by the addon. Can I help you somehow to support this device?

@al-one
Copy link
Owner

al-one commented Dec 25, 2020

@gerliczky Can you find the miot-spec type for me.

This is one of the ways to get it:

@gerliczky
Copy link
Author

gerliczky commented Dec 25, 2020

@al-one I have followed your instructions.
The MiHome_5.9.19_63129_vevs.apk is installed
I logged in with my MiHome account where the Defumidifier is already added.
I can control my device, but in the txt file I found no spec_type.
There is the IP address, the device type, the token and the request response messages.

2020-12-25 20:49:00 -> {"params":[{"did":"123456789","siid":2,"piid":1},{"did":"123456789","siid":2,"piid":3},{"did":"123456789","siid":2,"piid":5},{"did":"123456789","siid":5,"piid":1},{"did":"123456789","siid":4,"piid":1},{"did":"123456789","siid":6,"piid":1},{"did":"123456789","siid":3,"piid":1},{"did":"123456789","siid":7,"piid":3},{"did":"123456789","siid":7,"piid":4},{"did":"123456789","siid":8,"piid":1},{"did":"123456789","siid":8,"piid":2}],"datasource":1} /miotspec/prop/get 2020-12-25 20:49:00 <- {"code":0,"message":"","result":[{"did":"123456789","siid":2,"piid":1,"value":true,"code":0,"updateTime":1608706605},{"did":"123456789","siid":2,"piid":3,"value":1,"code":0,"updateTime":1608706605},{"did":"123456789","siid":2,"piid":5,"value":50,"code":0,"updateTime":1608706605},{"did":"123456789","siid":5,"piid":1,"value":true,"code":0,"updateTime":1608706605},{"did":"123456789","siid":4,"piid":1,"value":true,"code":0,"updateTime":1608706605},{"did":"123456789","siid":6,"piid":1,"value":false,"code":0,"updateTime":1608706605},{"did":"123456789","siid":3,"piid":1,"value":44,"code":0,"updateTime":1608924278},{"did":"123456789","siid":7,"piid":3,"value":false,"code":0,"updateTime":1608706605},{"did":"123456789","siid":7,"piid":4,"value":false,"code":0,"updateTime":1608706605},{"did":"123456789","siid":8,"piid":1,"value":0,"code":0,"updateTime":1608706605},{"did":"123456789","siid":8,"piid":2,"value":0,"code":0,"updateTime":1608706605}]} 2020-12-25 20:49:05 -> {"params":[{"did":"123456789","siid":2,"piid":1},{"did":"123456789","siid":2,"piid":3},{"did":"123456789","siid":2,"piid":5},{"did":"123456789","siid":5,"piid":1},{"did":"123456789","siid":4,"piid":1},{"did":"123456789","siid":6,"piid":1},{"did":"123456789","siid":3,"piid":1},{"did":"123456789","siid":7,"piid":3},{"did":"123456789","siid":7,"piid":4},{"did":"123456789","siid":8,"piid":1},{"did":"123456789","siid":8,"piid":2}],"datasource":1} /miotspec/prop/get 2020-12-25 20:49:05 <- {"code":0,"message":"","result":[{"did":"123456789","siid":2,"piid":1,"value":true,"code":0,"updateTime":1608706605},{"did":"123456789","siid":2,"piid":3,"value":1,"code":0,"updateTime":1608706605},{"did":"123456789","siid":2,"piid":5,"value":50,"code":0,"updateTime":1608706605},{"did":"123456789","siid":5,"piid":1,"value":true,"code":0,"updateTime":1608706605},{"did":"123456789","siid":4,"piid":1,"value":true,"code":0,"updateTime":1608706605},{"did":"123456789","siid":6,"piid":1,"value":false,"code":0,"updateTime":1608706605},{"did":"123456789","siid":3,"piid":1,"value":44,"code":0,"updateTime":1608924278},{"did":"123456789","siid":7,"piid":3,"value":false,"code":0,"updateTime":1608706605},{"did":"123456789","siid":7,"piid":4,"value":false,"code":0,"updateTime":1608706605},{"did":"123456789","siid":8,"piid":1,"value":0,"code":0,"updateTime":1608706605},{"did":"123456789","siid":8,"piid":2,"value":0,"code":0,"updateTime":1608706605}]} 2020-12-25 20:49:06 -> {"params":[{"did":"123456789","siid":2,"piid":1,"value":false}]} /miotspec/prop/set 2020-12-25 20:49:06 <- {"code":0,"message":"","result":[{"did":"123456789","siid":2,"piid":1,"code":0}]} 2020-12-25 20:49:10 -> {"params":[{"did":"123456789","siid":2,"piid":1},{"did":"123456789","siid":2,"piid":3},{"did":"123456789","siid":2,"piid":5},{"did":"123456789","siid":5,"piid":1},{"did":"123456789","siid":4,"piid":1},{"did":"123456789","siid":6,"piid":1},{"did":"123456789","siid":3,"piid":1},{"did":"123456789","siid":7,"piid":3},{"did":"123456789","siid":7,"piid":4},{"did":"123456789","siid":8,"piid":1},{"did":"123456789","siid":8,"piid":2}],"datasource":1} /miotspec/prop/get

Did I miss something?

@al-one
Copy link
Owner

al-one commented Dec 26, 2020

@gerliczky I'm sorry. You can get spec_type from vevs/logs/devices/your-did.json

@al-one al-one added the enhancement New feature or request label Dec 26, 2020
@gerliczky
Copy link
Author

gerliczky commented Dec 26, 2020

Found it:
urn:miot-spec-v2:device:dehumidifier:0000A02D:nwt-312en:1
https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:dehumidifier:0000A02D:nwt-312en:1

@al-one
Copy link
Owner

al-one commented Dec 26, 2020

@gerliczky You can test it use add-dehumidifier branch.

@gerliczky
Copy link
Author

Thanks a lot.
The test result:
2020-12-26 17:06:08 ERROR (MainThread) [homeassistant.components.humidifier] Error while setting up xiaomi_miot platform for humidifier Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 199, in _async_setup_platform File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 199, in _async_setup_platform File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 199, in _async_setup_platform await asyncio.shield(task) File "/config/custom_components/xiaomi_miot/humidifier.py", line 29, in async_setup_entry await async_setup_platform(hass, config, async_add_entities) File "/config/custom_components/xiaomi_miot/humidifier.py", line 39, in async_setup_platform entity = MiotDehumidifierEntity(config) File "/config/custom_components/xiaomi_miot/humidifier.py", line 82, in __init__ await asyncio.shield(task) await asyncio.shield(task) File "/config/custom_components/xiaomi_miot/humidifier.py", line 29, in async_setup_entry await async_setup_platform(hass, config, async_add_entities) File "/config/custom_components/xiaomi_miot/humidifier.py", line 39, in async_setup_platform entity = MiotDehumidifierEntity(config) File "/config/custom_components/xiaomi_miot/humidifier.py", line 82, in __init__ super().__init__(name, self._device) File "/config/custom_components/xiaomi_miot/humidifier.py", line 29, in async_setup_entry await async_setup_platform(hass, config, async_add_entities) File "/config/custom_components/xiaomi_miot/humidifier.py", line 39, in async_setup_platform entity = MiotDehumidifierEntity(config) File "/config/custom_components/xiaomi_miot/humidifier.py", line 82, in __init__ super().__init__(name, self._device) File "/config/custom_components/xiaomi_miot/__init__.py", line 259, in __init__ super().__init__(name, device) File "/config/custom_components/xiaomi_miot/__init__.py", line 160, in __init__ self._miio_info = device.info() File "/usr/local/lib/python3.8/site-packages/miio/device.py", line 177, in info return DeviceInfo(self.send("miIO.info")) File "/usr/local/lib/python3.8/site-packages/miio/device.py", line 143, in send return self._protocol.send( File "/config/custom_components/xiaomi_miot/__init__.py", line 259, in __init__ super().__init__(name, device) super().__init__(name, self._device) File "/config/custom_components/xiaomi_miot/__init__.py", line 160, in __init__ self._miio_info = device.info() File "/usr/local/lib/python3.8/site-packages/miio/device.py", line 177, in info return DeviceInfo(self.send("miIO.info")) File "/usr/local/lib/python3.8/site-packages/miio/device.py", line 143, in send return self._protocol.send( File "/usr/local/lib/python3.8/site-packages/miio/miioprotocol.py", line 160, in send self.send_handshake() File "/usr/local/lib/python3.8/site-packages/miio/miioprotocol.py", line 64, in send_handshake m = MiIOProtocol.discover(self.ip) File "/usr/local/lib/python3.8/site-packages/miio/miioprotocol.py", line 116, in discover s.sendto(helobytes, (addr, 54321)) socket.gaierror: [Errno -3] Try again File "/usr/local/lib/python3.8/site-packages/miio/miioprotocol.py", line 160, in send self.send_handshake() File "/usr/local/lib/python3.8/site-packages/miio/miioprotocol.py", line 64, in send_handshake m = MiIOProtocol.discover(self.ip) File "/usr/local/lib/python3.8/site-packages/miio/miioprotocol.py", line 116, in discover s.sendto(helobytes, (addr, 54321)) socket.gaierror: [Errno -3] Try again File "/config/custom_components/xiaomi_miot/__init__.py", line 259, in __init__ super().__init__(name, device) File "/config/custom_components/xiaomi_miot/__init__.py", line 160, in __init__ self._miio_info = device.info() File "/usr/local/lib/python3.8/site-packages/miio/device.py", line 177, in info return DeviceInfo(self.send("miIO.info")) File "/usr/local/lib/python3.8/site-packages/miio/device.py", line 143, in send return self._protocol.send( File "/usr/local/lib/python3.8/site-packages/miio/miioprotocol.py", line 160, in send self.send_handshake() File "/usr/local/lib/python3.8/site-packages/miio/miioprotocol.py", line 64, in send_handshake m = MiIOProtocol.discover(self.ip) File "/usr/local/lib/python3.8/site-packages/miio/miioprotocol.py", line 116, in discover s.sendto(helobytes, (addr, 54321)) socket.gaierror: [Errno -3] Try again

@al-one
Copy link
Owner

al-one commented Dec 26, 2020

@gerliczky What's your python-miio and home-assistant version ?

@gerliczky
Copy link
Author

miiocli, version 0.5.4
hassio 2020.12.1

@al-one
Copy link
Owner

al-one commented Dec 27, 2020

miiocli device --ip <ip> --token <token> info

Try this command and check your lan network.

@gerliczky
Copy link
Author

The result:
Model: nwt.derh.312en
Hardware version: esp32
Firmware version: 2.1.3

@gerliczky
Copy link
Author

I am still using the humidifier branch. I chaged log level to debug. When I add the dehumidifier I see the followig entries on the log:

2021-01-17 06:53:16 DEBUG (MainThread) [custom_components.xiaomi_miot.config_flow] Xiaomi Miot async_step_user 
{
    'user_input': {
        'name': 'dehumi',
        'mode': [],
        'host': 'IP',
        'token': 'TOKEN',
        'miio_info': {
            'life': 239012,
            'uid': 1914369720,
            'model': 'nwt.derh.312en',
            'token': 'TOKEN',
            'ipflag': 1,
            'fw_ver': '2.1.3',
            'mcu_fw_ver': '0004',
            'miio_ver': '0.0.9',
            'hw_ver': 'esp32',
            'mmfree': 62716,
            'mac': MAC',
            'wifi_fw_ver': 'cef6c0945',
            'ap': {
                'ssid': 'SSID',
                'bssid': 'MAC',
                'rssi': -36,
                'primary': 4
            },
            'netif': {
                'localIp': 'IP',
                'mask': '255.255.255.0',
                'gw': 'GW_IP'
            }
        }
    },
    'info': nwt.derh.312en v2.1.3(MAC) @ IP - token: TOKEN,
    'errors': {}
}

2021-01-17 06:53:16 DEBUG (MainThread) [custom_components.xiaomi_miot] Xiaomi Miot async_setup_entry 
{
    'entry_id': '3b00f47ba7f77a94451cf1d1ebd9c440',
    'unique_id': '64:90:c1:85:c0:0a',
    'config': {
        'host': 'IP',
        'token': 'TOKEN',
        'name': 'dehumi',
        'model': 'nwt.derh.312en',
        'mode': []
    },
    'domains': [],
    'miio': {
        'life': 239012,
        'uid': 1914369720,
        'model': 'nwt.derh.312en',
        'token': 'TOKEN',
        'ipflag': 1,
        'fw_ver': '2.1.3',
        'mcu_fw_ver': '0004',
        'miio_ver': '0.0.9',
        'hw_ver': 'esp32',
        'mmfree': 62716,
        'mac': 'MAC',
        'wifi_fw_ver': 'cef6c0945',
        'ap': {
            'ssid': 'SSID',
            'bssid': 'MAC',
            'rssi': -36,
            'primary': 4
        },
        'netif': {
            'localIp': 'IP',
            'mask': '255.255.255.0',
            'gw': 'GW_IP'
        }
    }
}

So the device added without error, but no entity was created and no new device is added.

Could you help me to fix this?

@al-one
Copy link
Owner

al-one commented Jan 17, 2021

Try lasest commit of branch add-dehumidifier.

@gerliczky
Copy link
Author

Unfortunately there is no change. The same message on log and neither devices nor entities are created.

I noticed that on the integration UI, when I try to add the device, only climate and sensor can be selected, so I left it empty.

@al-one
Copy link
Owner

al-one commented Jan 18, 2021

Download lasest and try again.

@gerliczky
Copy link
Author

gerliczky commented Jan 19, 2021

Now I got the folllowing error:

2021-01-19 05:08:42 INFO (MainThread) [custom_components.xiaomi_miot.humidifier] Initializing with host IP (token TOKEN)
2021-01-19 05:08:47 ERROR (MainThread) [homeassistant.components.humidifier] Error while setting up xiaomi_miot platform for humidifier
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 199, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/xiaomi_miot/humidifier.py", line 27, in async_setup_entry
    await async_setup_platform(hass, config, async_add_entities)
  File "/config/custom_components/xiaomi_miot/humidifier.py", line 37, in async_setup_platform
    entity = MiotDehumidifierEntity(config)
  File "/config/custom_components/xiaomi_miot/humidifier.py", line 80, in __init__
    super().__init__(name, self._device)
  File "/config/custom_components/xiaomi_miot/__init__.py", line 289, in __init__
    super().__init__(name, device)
  File "/config/custom_components/xiaomi_miot/__init__.py", line 169, in __init__
    self._miio_info = device.info()
  File "/usr/local/lib/python3.8/site-packages/miio/device.py", line 177, in info
    return DeviceInfo(self.send("miIO.info"))
  File "/usr/local/lib/python3.8/site-packages/miio/device.py", line 143, in send
    return self._protocol.send(
  File "/usr/local/lib/python3.8/site-packages/miio/miioprotocol.py", line 160, in send
    self.send_handshake()
  File "/usr/local/lib/python3.8/site-packages/miio/miioprotocol.py", line 64, in send_handshake
    m = MiIOProtocol.discover(self.ip)
  File "/usr/local/lib/python3.8/site-packages/miio/miioprotocol.py", line 116, in discover
    s.sendto(helobytes, (addr, 54321))
socket.gaierror: [Errno -3] Try again

@gerliczky
Copy link
Author

Hi @al-one,
Do you have idea, what the problem is?

@gerliczky
Copy link
Author

Does it happened, because the device is currently not supported in python-miio?

@al-one
Copy link
Owner

al-one commented Jan 23, 2021

miiocli -d device --ip 192.168.lan.ip --token xxxxxx raw_command get_properties "[{'did': 'result', 'siid': 2, 'piid': 1}]"

Run this shell in HA host.
Do you have other miot devices? If you have, can they be integrated normally.

@gerliczky
Copy link
Author

My dehumidifier works correctly. I can contro and get information with miiocli command.
Unfortunately I do not have another miot device.
I have executed the command you suggested. The result:

INFO:miio.cli:Debug mode active
Running command raw_command
DEBUG:miio.protocol:Unable to decrypt, returning raw bytes: b''
DEBUG:miio.miioprotocol:Got a response: Container:
    data = Container:
        data = b'' (total 0)
        value = b'' (total 0)
        offset1 = 32
        offset2 = 32
        length = 0
    header = Container:
        data = b'!1\x00 \x00\x00\x00\x00\x13\xe3>7\x00\x0cA-' (total 16)
        value = Container:
            length = 32
            unknown = 0
            device_id = unhexlify('13e33e37')
            ts = 1970-01-10 07:05:17
        offset1 = 0
        offset2 = 16
        length = 16
    checksum = b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' (total 16)
DEBUG:miio.miioprotocol:Discovered 13e33e37 with ts: 1970-01-10 07:05:17, token: b'ffffffffffffffffffffffffffffffff'
DEBUG:miio.miioprotocol:IP:54321 >>: {'id': 1, 'method': 'get_properties', 'params': [{'did': 'result', 'siid': 2, 'piid': 1}]}
DEBUG:miio.miioprotocol:IP:54321 (ts: 1970-01-10 07:05:18, id: 1) << {'id': 1, 'result': [{'did': 'result', 'siid': 2, 'piid': 1, 'code': 0, 'value': True}], 'exe_time': 270}
[{'did': 'result', 'siid': 2, 'piid': 1, 'code': 0, 'value': True}]

I still receive the error above when I try to add my device in HA on the Integration page.
Do you have any idea, what to do?

@al-one
Copy link
Owner

al-one commented Jan 24, 2021

Sorry. I have no idea.

@gerliczky
Copy link
Author

I just updated to the most recent version, and just recognised, that the device and a new sensor entity is created. :)
Are you going to implement the control entities also? (switch and services)
Could you share me an example, how to use the xiaomi_miot.send_command and xiaomi_miot.get_properties, xiaomi_miot.get_properties, and xiaomi_miot.call_action services?

@al-one
Copy link
Owner

al-one commented Jan 31, 2021

You can try last commit of master.
If there is still only sensor entity, You can call new service set_miot_property to sensor entity.

# turn on/off
service: xiaomi_miot.set_miot_property
data:
  entity_id: sensor.dehumidifier_entity_id
  siid: 2
  piid: 1
  value: true # false

# switch mode
service: xiaomi_miot.set_miot_property
data:
  entity_id: sensor.dehumidifier_entity_id
  siid: 2
  piid: 3
  value: 1 # 1 - Tagget-humid 2 - Dry-cloth

# target humidity
service: xiaomi_miot.set_miot_property
data:
  entity_id: sensor.dehumidifier_entity_id
  siid: 2
  piid: 5
  value: 30 # 30-70

@gerliczky
Copy link
Author

It works perfectly. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants