dlink_hnap icon indicating copy to clipboard operation
dlink_hnap copied to clipboard

Battery Attribute

Open daconrad0 opened this issue 3 years ago • 22 comments

Is it possible to get the battery state so I can change the batteries as needed. I currently only see the following: FF1159EE-6692-4181-8CF3-807D222A352F

daconrad0 avatar Oct 17 '20 16:10 daconrad0

Maybe, I don't know. Don't have any battery powered devices myself.

postlund avatar Nov 01 '20 18:11 postlund

@daconrad0 hi, is your unit the s161? the s160 doesn't have a battery?

kintaroju avatar Nov 02 '20 22:11 kintaroju

Yes

Dennis Conrad

On Nov 2, 2020, at 5:45 PM, kintaroju [email protected] wrote:

 @daconrad0 hi, is your unit the s161? the s160 doesn't have a battery?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

daconrad0 avatar Nov 03 '20 00:11 daconrad0

@daconrad0 question for you, does your s161 report the change in state from dry to wet at all? I've configured my device correctly in the configuration.yaml under binary_sensor and it sees the device, but when I get a cup of water and let it beep for 20-30 seconds, I don't see a change in state in the UI entity, does yours show a change in state in the UI entity?

kintaroju avatar Nov 03 '20 03:11 kintaroju

@postlund since @daconrad0 indicated that the s161 works with your integration, what would it take for us to help you get the data to poll battery states from the s161?

kintaroju avatar Nov 03 '20 03:11 kintaroju

@kintaroju We need to find the action used to extract that information. Start by running this command and pasting the result:

python custom_components/dlink_hnap/dlink.py <ip> <pin> actions

Replace and with the information for your device.

postlund avatar Nov 03 '20 06:11 postlund

@postlund, i am using hassos to run home assistant, and took me a while to get into the docker session, below is the error I got, when i installed python3:

image

when i tried to install python i had an error installing it.

kintaroju avatar Nov 03 '20 16:11 kintaroju

@kintaroju Try:

pip install xmltodict

And run again, should work.

postlund avatar Nov 03 '20 16:11 postlund

@postlund I get the following error messages below. I know that I can ping the device in question:

image

kintaroju avatar Nov 03 '20 17:11 kintaroju

@kintaroju Verify that the IP address is correct. I would expect not since you get a timeout.

postlund avatar Nov 03 '20 17:11 postlund

@postlund I've validated the IP, and I've check the AP to ensure that the MAC matches the IP, and I've did a test ping from HassOS to the device and it's all correct. I've even double checked the PIN on the back of the device and what I inputted is correct.

I've even reassigned the IP and that didn't help either. Do you have any other ideas to help troubleshoot the issue?

BTW i am testing this first on my s160 first before attempting this on the s161 to make sure I have the process down pat.

kintaroju avatar Nov 03 '20 17:11 kintaroju

Humm, that's strange. Maybe you can try to find an MDNS/zeroconf client and look for the HNAP service? I think it's called _dhnap._tcp.local or so. I suspect that they might use a different port number and we can see that in the service.

postlund avatar Nov 03 '20 18:11 postlund

@postlund thanks for that tidbit about mdns being the culprit. i managed to get the s160 on the same vlan/subnet as the home assistant server and it managed to query the device. I will test the s161 shortly after i move the device.

I believe there is something up with opnsense and the mdns-repeater service as it's just a simple option to select 2 interfaces and mdns is "supposed" to work, which doesn't seem to be the case. If you can provide some tips on what I could be missing here that would be appreciated. For the moment for my workaround I've had to create a new SSID to allow the devices to connect to the main network because the silly devices don't support "fast roaming" 802.11r on my ubiquiti APs.

kintaroju avatar Nov 03 '20 19:11 kintaroju

@postlund I've placed the s161 on the main network at home, and now i get the following error message:

image

kintaroju avatar Nov 03 '20 19:11 kintaroju

@kintaroju MDNS isn't really needed as I haven't implemented support for discovery. What I'm interested in is what port is announced for the HNAP service. HNAP is just SOAP over HTTP and normally served over port 80 (unencrypted). The MDNS could reveal if it's another port. So have a look at the service and let me know what it says.

postlund avatar Nov 03 '20 20:11 postlund

@postlund for the s161 how abouts would I look for the required port to look for the required data, as this is getting into territory that I haven't done lol. If you have docs or tips I'm all ears.

kintaroju avatar Nov 03 '20 21:11 kintaroju

@kintaroju TBH I'm not sure what the best tools are, but it will depend on the platform you run on. I usually use iNet Pro on iOS, works pretty well. So I guess we should start by determine which OSes you have at hand?

postlund avatar Nov 03 '20 21:11 postlund

@postlund I can spin up whatever OS as I have an ESXi host. For your iNet tool I managed to scan the device and managed to get the bonjour service is based on "device control protocol". When i used Windows, and used the "advanced port scanner" it didn't see any opened ports.

kintaroju avatar Nov 03 '20 22:11 kintaroju

@postlund i think you'll have a laugh, but I figured out why communication between my vlans and the s160 could never talk, my opnsense router had a IPS rule to block dlink dhnap due to it's nature of being fairly insecure lol. so essentially all port 80 traffic from the IoT device and HA was being blocked.

One other thing just have to say, thanks for all your help narrowing down communication issue as it was an eye opener.

kintaroju avatar Nov 04 '20 17:11 kintaroju

@postlund for the s161 let me know when you want to try to debug the issue, as the unit is not pingable and also goes into power saving mode which causes the unit to disconnect from the network.

kintaroju avatar Nov 08 '20 04:11 kintaroju

@daconrad0 question for you, does your s161 report the change in state from dry to wet at all? I've configured my device correctly in the configuration.yaml under binary_sensor and it sees the device, but when I get a cup of water and let it beep for 20-30 seconds, I don't see a change in state in the UI entity, does yours show a change in state in the UI entity?

@daconrad0 just checking if you checked your s161 if it does report any change in state to home assistant at all?

kintaroju avatar Nov 08 '20 04:11 kintaroju

@postlund

...Start by running this command and pasting the result:

python custom_components/dlink_hnap/dlink.py <ip> <pin> actions

Replace and with the information for your device.

I'm not into Home Assistant, but am very interested in monitoring my D-Link DCH-S160 Water Sensors via a Raspberry Pi. Eventually, I'd like to replace all of the functionality provided by D-Link's apps (i.e., send e-mail and push notifications), as they'll eventually stop supporting these devices entirely, as they do with all of their products. As a result, I've tried executing your dlink.py script on its own as follows:

python3 dlink.py <ip_address> <pin> water_detected

As you can see from the output below, it does generate a response from the Water Sensor, but also produces several errors:

Water detected: False
dlink.py:296: RuntimeWarning: coroutine 'ClientSession.close' was never awaited session.close()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x75b21290>
ERROR:asyncio:Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x75b17b90>, 91742.126952004)]']
connector: <aiohttp.connector.TCPConnector object at 0x75b212b0>

I've found that adding "await" to the second to last line of your script, solves the problem. The line should read as follows:

await session.close()

I'm very new to python and am running your script in a very different environment than intended, so I get that this may not be appropriate to your application. Just wanted to share, in case someone else was trying to get it to run on its own.

And, thanks for doing the heavy lifting on the HNAP/SOAP portion. I've been trying for weeks to get it to work in a bash script.

lwbeam avatar Aug 11 '21 22:08 lwbeam