D-Link Motion Sensor DCH-S150

I too have got this sensor working! It certainly has been a useful learning excercise for me as I’m such a newbie to HA. Thanks @postlund et al.

Great to he hear! Happy hacking!

Howdy. What exactly am I to do with those two files you linked? I’m cluless. Thanks in advance.

Create a directory called custom_components in your configuration directory (where configuration.yaml is). Inside that directory, create another directory called binary_sensor. Place the two files in that directory and add the configuration mentioned above.

1 Like

Thanks for the response. What an I supposed to write for host? The IP of the detector?

Yep, IP of the detector.

Still not showing up. I take it the password is the one I made up in the app or is there a default one I should be using? Sorry for all the questions…been trying to figure this out for a couple of days alone, but it hasn’t worked out.

It’s the PIN code you used to setup the device.

Still not showing up. Guess I’ll have to use IFTTT for the time being. Thanks again for the help.

If you enable logging and provide some logs I can help you troubleshoot.

Thanks so much for the offer. I will read how to do that and get back to you soon.

I have one of these I bought by mistake (thought it was Z-Wave).

Could someone please explain how to include and use this in HASS? I don’t really understand what steps is needed.

I have the D-Link switch included and working according to the instructions in https://home-assistant.io/components/switch.dlink/.

What files do I need to download from https://github.com/postlund/hass-config/tree/master/homeassistant/custom_components/binary_sensor and where should I add them?

For some reasons, it was working fine and now I’m getting this error:

2017-10-08 23:43:20 ERROR (MainThread) [custom_components.binary_sensor.dlink_motion_sensor] failed to update motion sensor
File “/share/homes/admin/homeassistant/custom_components/binary_sensor/dlink_motion_sensor.py”, line 93, in async_update
File “/share/homes/admin/homeassistant/custom_components/binary_sensor/dlink_new.py”, line 142, in latest_trigger
File “/share/homes/admin/homeassistant/custom_components/binary_sensor/dlink_new.py”, line 169, in _cache_soap_actions
File “/share/homes/admin/homeassistant/custom_components/binary_sensor/dlink_new.py”, line 93, in soap_actions
File “/share/homes/admin/homeassistant/custom_components/binary_sensor/dlink_new.py”, line 100, in call
File “/share/homes/admin/homeassistant/custom_components/binary_sensor/dlink_new.py”, line 56, in login
File “/share/homes/admin/homeassistant/custom_components/binary_sensor/dlink_new.py”, line 104, in call
File “/share/homes/admin/homeassistant/custom_components/binary_sensor/dlink_new.py”, line 214, in call

Appreciate any help. Thanks!

I’m getting the same thing with the dlink w215 smart plugs.

Actually I fixed the issue by returning last detection time always in latest_trigger in dlink_new, the code now looks like the following:

         resp = yield from self.client.call(
             'GetLatestDetection', ModuleID=self.module_id)
         detect_time = resp['LatestDetectTime']
         return datetime.fromtimestamp(float(detect_time))
     else:
         resp = yield from self.client.call(
             'GetMotionDetectorLogs', ModuleID=self.module_id, MaxCount=1,
             PageOffset=1, StartTime=0, EndTime='All')
         if 'MotionDetectorLogList' not in resp:
             _LOGGER.error('log list: ' + str(resp))
         log_list = resp['MotionDetectorLogList']
         detect_time = log_list['MotionDetectorLog']['TimeStamp']
         _LOGGER.error('log list: ' + str(resp))
         return datetime.fromtimestamp(float(detect_time))```

Sorry for not answering to this earlier, but time… Anyways, this changes does not correlate to the stack trace you posted above. The crash happens during the SOAP action caching call, just above that code (yield from self._cache_soap_actions() at line 142, you can see the reference in the stack trace). I cannot see any difference in current code and your changes, as it’s only moving som return statements and duplicating code. So it looks more like a coincidence that it works (which is likely to be true as these devices function really poorly from what I have seen).

Anyways, since the POST call is the trouble make here (line 214), my guess is that the device does not respond within the four second timeout period. That’s what I’ve been seeing a lot of. I have no idea why that happens, but mostly it works fine and then for a period I get a lot of timeouts until it returns to “normal” again. Then repeat. I did some tests with the loop command while back and did not see these problems, but when I started using the component in HA again, I got a lot of timeouts.

I’ll see if I can make some changes later tonight. At least update to get a better indication of the actual exception as that is for some reason not included now. Are you sure that stack trace is complete?

Actually the stack trace was happening earlier but not anymore, I have no clue what changed since I posted the stack trace, but when I return the last detection time under the if condition it gets read in dlink motion sensor and set the state correctly.
I put logger.debug under else and seems it hit that break point but I couldn’t figure out the attributes under GetMotionDetectorLogs. I’m new to python scripts, so still fiddling around. But so far Im getting a detection and I was able to use it with HA.

You are also right, there is always a delay or timeout when ever there is a motion detection call.

@postlund
Im using hassbian 62.1 and ive added the two files to my custom_components directory. However when i try to run dlink.py from command line it get the following…

  File "./dlink.py", line 51
    resp = yield from self.call(
                    ^
SyntaxError: invalid syntax

any ideas?

You seem to be using an older version of python. Try using python3 instead of just python.

I’ll try that, I guess that would make sense considering I ran the command like "python ./dlink.py (IP address) (Pencode)”

Also when I did a hard reboot on my pi and I was still unable to see any sensors relating to dlink or binary. Is that normal ? How can I check to see if the script is running from the custom_componets @postlund