postlund / dlink_hnap

Experimental integration to Home Assistant supporting D-Link devices
MIT License
41 stars 5 forks source link

Battery Attribute #11

Open daconrad0 opened 3 years ago

daconrad0 commented 3 years ago

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

postlund commented 3 years ago

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

kintaroju commented 3 years ago

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

daconrad0 commented 3 years ago

Yes

Dennis Conrad

On Nov 2, 2020, at 5:45 PM, kintaroju notifications@github.com 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.

kintaroju commented 3 years ago

@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 commented 3 years ago

@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?

postlund commented 3 years ago

@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.

kintaroju commented 3 years ago

@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.

postlund commented 3 years ago

@kintaroju Try:

pip install xmltodict

And run again, should work.

kintaroju commented 3 years ago

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

image

postlund commented 3 years ago

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

kintaroju commented 3 years ago

@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.

postlund commented 3 years ago

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.

kintaroju commented 3 years ago

@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 commented 3 years ago

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

image

postlund commented 3 years ago

@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.

kintaroju commented 3 years ago

@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.

postlund commented 3 years ago

@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?

kintaroju commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

@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?

lwbeam commented 3 years ago

@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.