D-Link Motion Sensor DCH-S150

\config\custom_components\dlink_motion_sensor

1 Like

finally it works! thanks

Is this just working with sensors on my network?

Is there any way to control a sensor that I have in another house different than my HA?

Thanks!

This component is accessing directly the device not the dlink cloud service. So if your sensor has no public IP address, which would be a security risk, then NO.

Since they are going to stop IFTTT support for the Dlink motion sensor DCH-S150, this might become important. I just put my (corrected) summary here and a link to my files on dropbox, since the github files seem to no longer be available.
So: Put the files in the config folder “custom_components/dlink_motion_sensor” (make the folders). Then add an empty file called “init.py” to the same folder, otherwise it won’t work. Then add this to the configuration.yaml:

binary_sensor:
  platform: dlink_motion_sensor
  name: Some sensor
   host: dlink_motion_sensor_ip_address
   password: !secret motion_sensor_password

The password should be the pin code that comes with the sensor. Lastly, do a system reboot (not just the home assistant server).

Files:
Files D-link sensor

edit
I’ve changed the code to solve the “BinarySensorDevice is deprecated” warning

3 Likes

In light of the upcoming termination of IFTTT support maybe someone could convert it in an “official” component with a support of motion sensor DCH-S150 and water sensor DCH-S160?

that would be ideal, I’m also getting warnings with the code (BinarySensorDevice is deprecated, modify DlinkMotionSensor to extend BinarySensorEntity). It still works for now, however I’m getting some errors which might be related as well.

Hi, I just swapped the BinarySensorDevice with BinarySensorEntity and I don’t seem to get the error anymore. Not sure if that solves it correctly or not but seems fine.

@s.niesler08 please share the code

That will solve it. I believe this was mentioned in the release notes for 0.110.

MIne stopped working after latests update with these errors. Any idead?

2020-06-10 15:21:33 WARNING (MainThread) [homeassistant.components.binary_sensor] Setup of binary_sensor platform dlink_motion_sensor is taking over 10 seconds.
2020-06-10 15:21:35 ERROR (MainThread) [custom_components.dlink_motion_sensor.dlink] Got an error, resetting private key
2020-06-10 15:21:35 ERROR (MainThread) [custom_components.dlink_motion_sensor.binary_sensor] failed to update motion sensor
Traceback (most recent call last):
  File "/var/opt/homeassistant/custom_components/dlink_motion_sensor/dlink.py", line 105, in call
    result = yield from self.soap().call(method, **kwargs)
  File "/var/opt/homeassistant/custom_components/dlink_motion_sensor/dlink.py", line 225, in call
    self.address, data=xml, headers=headers, timeout=10)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 504, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client_reqrep.py", line 860, in start
    self._continue = None
  File "/usr/local/lib/python3.7/site-packages/aiohttp/helpers.py", line 586, in __exit__
    raise asyncio.TimeoutError from None
concurrent.futures._base.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/opt/homeassistant/custom_components/dlink_motion_sensor/binary_sensor.py", line 93, in async_update
    last_trigger = yield from self._motion_sensor.latest_trigger()
  File "/var/opt/homeassistant/custom_components/dlink_motion_sensor/dlink.py", line 153, in latest_trigger
    yield from self._cache_soap_actions()
  File "/var/opt/homeassistant/custom_components/dlink_motion_sensor/dlink.py", line 180, in _cache_soap_actions
    resp = yield from self.client.soap_actions(self.module_id)
  File "/var/opt/homeassistant/custom_components/dlink_motion_sensor/dlink.py", line 94, in soap_actions
    'GetModuleSOAPActions', ModuleID=module_id))
  File "/var/opt/homeassistant/custom_components/dlink_motion_sensor/dlink.py", line 101, in call
    yield from self.login()
  File "/var/opt/homeassistant/custom_components/dlink_motion_sensor/dlink.py", line 57, in login
    LoginPassword='', Captcha='')
  File "/var/opt/homeassistant/custom_components/dlink_motion_sensor/dlink.py", line 109, in call
    self._bad_response()
  File "/var/opt/homeassistant/custom_components/dlink_motion_sensor/dlink.py", line 115, in _bad_response
    raise Exception('got error response from device')
Exception: got error response from device

I solved my issue by uninstalling homeassistant, manually removing the entire homeassistant folder in python dist-packages folder, rebooting, reinstalling homeassistant and et voilla. it magically works.

Hey I’m very new to home assistant. As a Matter is fact I’m trying to get started with with only because I purchased the dlink sensor DCH-S150
I was using it with ifttt so far to trigger ewelink switches but they made it paid recently so trying to do it in home assistant. I bought 6 of those devices for my home so can’t upgrade to different device. If someone can write a quite sum of now to set up the sensor in home assistant it’ll be really helpful

It seems like there is a new error with 0.113 and the component doesn’t work anymore:

2020-07-22 21:39:42 ERROR (MainThread) [custom_components.dlink_motion_sensor.binary_sensor] failed to update motion sensor
Traceback (most recent call last):
  File "/config/custom_components/dlink_motion_sensor/binary_sensor.py", line 93, in async_update
    last_trigger = yield from self._motion_sensor.latest_trigger()
  File "/config/custom_components/dlink_motion_sensor/dlink.py", line 153, in latest_trigger
    yield from self._cache_soap_actions()
  File "/config/custom_components/dlink_motion_sensor/dlink.py", line 180, in _cache_soap_actions
    resp = yield from self.client.soap_actions(self.module_id)
  File "/config/custom_components/dlink_motion_sensor/dlink.py", line 93, in soap_actions
    return (yield from self.call(
  File "/config/custom_components/dlink_motion_sensor/dlink.py", line 101, in call
    yield from self.login()
  File "/config/custom_components/dlink_motion_sensor/dlink.py", line 65, in login
    self._private_key = _hmac(public_key + str(self.password), challenge)
  File "/config/custom_components/dlink_motion_sensor/dlink.py", line 24, in _hmac
    return hmac.new(key.encode('utf-8'),
  File "/usr/local/lib/python3.8/hmac.py", line 153, in new
    return HMAC(key, msg, digestmod)
  File "/usr/local/lib/python3.8/hmac.py", line 51, in __init__
    raise TypeError("Missing required parameter 'digestmod'.")
TypeError: Missing required parameter 'digestmod'.

Same problem here with 0.113

It is due to Python 3.8 where digestmod is required to provide. Would someone be able to adapt the code for 3.8?

Line 25 of config/custom_components/dlink_motion_sensor/dlink.py should be changed to message.encode(‘utf-8’),“MD5”).hexdigest().upper()
This worked for me. From what I worked out it previously defaulted to MD5 if not defined but now it has to be stipulated.

2 Likes

I created a PR:

Please verify and let me know if it works!

Right, so
 I have gotten a lot of questions regarding my custom component. Currently, I do not use my DCH-S150, but I left the code for the component for others to use. Now I decided to extract it into its own repository, which is compatible with HACS. So you can basically install it with HACS, but you do need to add it as a custom repository.

The code is available here:

It’s the same one as in my hass-config repo with some minor differences:

  • Code is formatted with black
  • Changed to async/await syntax
  • Added manifest
  • It has been renamed to dlink_hnap to open up for future device types

Other than that it should be the same. As I haven’t tested it, I need your help with that. If you try it out, please report back in https://github.com/postlund/dlink_hnap/issues/1.

If you find bugs, please write an issue on GitHub. Do not report it here! Once I have gotten some feedback and it seems to work good enough, I will send a PR to have it included in HACS natively. So you don’t have to add it as a custom repo.

5 Likes

Works perfect. Kudos :+1:

1 Like