D-Link Motion Sensor DCH-S150

Hi! Good morning from Spain!

I follow this big project from make long time, and i have a some systems with home assistant installed, my question now or if some people help my, is that recently acquisition two sensor of D-Link motion sensor in concrete the model DCH-S150, i am try write one conector with home assistant based in the @LinuxChristian project for D-Link Switch DSP-W215, but not it is possible and send me some errors, if some have some idea of how connect this module ( DCH-S150 motion sensor) with home assistant or help me with make the code


This is a product:
www.dlink.com/uk/en/home-solutions/mydlink-home/home-monitors/dch-s150-motion-sensor

Thanks you guys!

@kronostime I hope you have some success with this as I’d also like to see these motion sensors working in Home Assistant. If you need anyone to do any testing for you I’d be happy to help.

Same here. Would be really interested in seeing these motion sensors in HA!

Me too!

http://w.x.y.z/HNAP1/ returns the sort of information I think is needed to proceed with this. I would paste it in but it contains too many links for a new member apparently.

Note the url begins http NOT https which I believe is more usual.

1 Like

If there are any Australian developers who might be interested in working on a solution for this request I have received a commitment from D-Link Australia to supply free hardware for development and testing of this device within HASS.

Let me know if you are interested and capable.

I have reverse engineered and written a library and custom component for this sensor. It’s available here:
https://github.com/postlund/hass-config/tree/master/homeassistant/custom_components/binary_sensor
Example configuration is here:
https://github.com/postlund/hass-config/blob/master/homeassistant/packages/motion_sensors.yaml
Currently, I have no plans on merging this with the official release branch. But maybe sometime in the future when I have more time. So, you will have to add it as a custom component. Hope it works for you!

2 Likes

@postlund this is great news that you’ve progressed the development of this custom component.

I have installed the two files and I am finding the following in the log, the sensor otherwise does not show in my HASS installation at this time.

File "/home/michael/.homeassistant/custom_components/binary_sensor/dlink_motion_sensor.py", line 84, in async_update last_trigger = yield from self._motion_sensor.latest_trigger()
File "/home/michael/.homeassistant/custom_components/binary_sensor/dlink.py", line 160, in latest_trigger log_list = resp.MotionDetectorLogList

Any ideas?

I assume the answer is empty. Chances are that my library is not compatible with the latest firmware. I will try to upgrade to a later version if I can figure out how to do that. One thing you can try however is to run dlink.py manually with IP and PIN code:

./dlink.py 10.0.0.4 123456

It should give more information.

When running from command prompt I got:

Traceback (most recent call last):
  File "H:\custom_components\binary_sensor\dlink.py", line 12, in <module>
    from pysimplesoap.client import SoapClient
ImportError: No module named 'pysimplesoap'

I originally thought it was unrelated but here is more info from the HASS log that now seems relevant:

During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
        result = coro.send(None)
      File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity_component.py", line 361, in async_process_entity
        new_entity, self, update_before_add=update_before_add
      File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity_component.py", line 189, in async_add_entity
        yield from entity.async_update()
      File "/home/michael/.homeassistant/custom_components/binary_sensor/dlink_motion_sensor.py", line 84, in async_update
        last_trigger = yield from self._motion_sensor.latest_trigger()
      File "/home/michael/.homeassistant/custom_components/binary_sensor/dlink.py", line 160, in latest_trigger
        log_list = resp.MotionDetectorLogList
      File "/home/michael/.homeassistant/deps/pysimplesoap/simplexml.py", line 251, in __getattr__
        return self.__call__(tag)
      File "/home/michael/.homeassistant/deps/pysimplesoap/simplexml.py", line 247, in __call__
        raise AttributeError("Tag not found: %s (%s)" % (tag, e))
    AttributeError: Tag not found: MotionDetectorLogList (No elements found)

FYI - my /deps folder contains ‘pysimplesoap’ and ‘PySimpleSOAP-1.16-py3.5.egg-info’

It’s easiest to just install it in your venv too, so:

pip install PySimpleSOAP==1.16

My firmware upgrade didn’t work, so I had to roll-back. So I pushed an updated dlink.py that can list supported actions. So, I would like you to try this instead:

./dlink.py 10.0.0.4 123456 actions

Hi postlund, great work with this component!

Indeed the new firmware seems to break it, if i list the actions I get these:

Reboot
SetFactoryDefault
IsDeviceReady
GetDeviceSettings
SetDeviceSettings
GetDeviceSettings2
SetDeviceSettings2
GetGroupSettings
SetGroupSettings
GetSystemLogs
CleanSystemLogs
GetModuleSchedule
SetModuleSchedule
GetModuleEnabled
SetModuleEnabled
GetModuleProfile
SetModuleProfile
GetModuleSOAPActions
GetTimeSettings
SetTimeSettings
GetModuleGroup
SetModuleGroup
GetScheduleSettings
SetScheduleSettings
GetRecursiveSchedule
SetRecursiveSchedule
GetFirmwareStatus
GetFirmwareValidation
StartFirmwareDownload
PollingFirmwareDownload
CheckNewFirmware
SettriggerADIC
GetInternetSettings
GetCurrentInternetStatus
GetWLanRadios
SetTriggerWirelessSiteSurvey
GetSiteSurvey
SetAPClientSettings
GetAPClientSettings

I tried calling GetModuleSOAPActions for ModuleID=1 and got this:

<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetModuleSOAPActionsResponse xmlns="http://purenetworks.com/HNAP1/"><GetModuleSOAPActionsResult>OK</GetModuleSOAPActionsResult><ModuleSOAPList><SOAPActions><ModuleID>1</ModuleID><Action>GetMotionDetectorSettings</Action><Action>SetMotionDetectorSettings</Action><Action>GetMotionDetectorLogs</Action><Action>CleanMotionDetectorLogs</Action><Action>GetLatestDetection</Action></SOAPActions></ModuleSOAPList></GetModuleSOAPActionsResponse></soap:Body></soap:Envelope>'

But then, if I run the latest_motion command:

<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetMotionDetectorLogsResponse xmlns="http://purenetworks.com/HNAP1/"><GetMotionDetectorLogsResult>ERROR</GetMotionDetectorLogsResult></GetMotionDetectorLogsResponse></soap:Body></soap:Envelope>

My next step will be to see exactly which packets arrive from the cloud to the motion sensor when controlling it via the app. Any other ideas?

Cool, then we know for a fact that it is a firmware thing. Since there is a GetLatestDetection action now, I believe that should be used instead (not sure why GetMotionDetectorLogs doesn’t work though, would have to investigate that). So, I have made an attempt to implement support for that action but still be backwards compatible. Please try latest_motion with the updated version in my repo.

1 Like

Worked like a charm! Thanks a lot!

I spent a couple of hours trying to find the right parameters, for that call (had tried using GetLatestDetection before and only got errors). How did you managed it so fast?!

That’s great! You will likely notice some “connection errors” and that calls takes too long to execute some times. Not sure if the device can handle the update rate. My goal is to re-write the SOAP-code to use aiohttp instead and keep the connection alive at all time. Now pysimplesoap wll close it between each call, which is a bit excessive. Hopefully that re-write will make it more stable.

I’m a wizard :wink: No, I actually cheated this time. After writing the initial implementation I discovered open PR for this sensor in the OpenHAB project. But since it used GetLatestDetection it wasn’t interesting to me. Now, in your case, however I could benefit a bit from their work.

3 Likes

Hi Guys,

Do you know if there is any progress in developing the code for this sensor?
I’m using DCH-S150 in conjunction with IFTTT, it works ok, however, there is a delay in a few seconds that I would like to avoid.
I could be a tester of the code if needed.

Watching this topic with interest as I also have one of these sensors. I want to use this sensor without relying on outside servers.

I will tinker with component build (Thanks @postlund) but my inexperience with HA is likely to be an issue.

I cannot find anything about DCH-D150 on the net, did you mean S and not D? Or is it some special version? My custom component should work OK for DCH-S150, just drop it in custom_components. What you need to know is that there is no “push” functionality from the device (at least that I have found). That’s only available for their cloud solution. So polling is the available solution to get a reading locally. I poll with 5 seconds intervals which seems to work fine when using one device. When I add my second, I get timeouts sometimes. Not sure if this is due to my Home Assistant being overloaded or not, so you might not see it. But That’s an issue I see.

@postlund yes you are right, I have a DCH-S150. I misread @Molodax’s post.

Sorry for confusion, I meant DCH-S150 (it was typo).
And thank you for the answer, I also saw that you mentioned before that

my library is not compatible with the latest firmware

So I just wanted to check if that issue has been solved since I am using the latest firmware as well as I’m planing to add a second device.

Yep, it works with the latest firmware now!

2 Likes