syssi / xiaomi_fan

Xiaomi Mi Smart Fan integration for Home Assistant
Apache License 2.0
431 stars 118 forks source link

dmaker.fan.p5 unavailable. #238

Closed keshabit closed 1 year ago

keshabit commented 1 year ago

the dmaker.fan.p5 fan is pingable but unavailable in home assistant, this is happening because the fan is in the different network segment than the ha node. However, the Xiao Mi mobile application can operate without any issues, this is happening only when integrating with the home assistant module. please help

syssi commented 1 year ago

If the Android app is unable to establish a local network connection a cloud connection is used. I'm pretty sure the Android App want be able to talk to your device locally too.

keshabit commented 1 year ago

Thank you for the prompt response. Thats right! Xiaomi Mi Android app can operate from different segments but the home assistant can't establish the communication link. I can ping the fan from the home assistant segment. This is not happening with any smart devices other than this fan in the network. Xiaomi fan is in Segment A and HA is in Segment B, if I bring the fan to Segment B it works, this is separated keeping network security in mind. I hope this explains.

syssi commented 1 year ago

Do you know these docs?

https://python-miio.readthedocs.io/en/latest/troubleshooting.html#discover-devices-across-subnets

keshabit commented 1 year ago

Thank you for the very generous feedback!

This solution used for the similar issue:

"Masquerading If you've multiple VLAN's/subnets and you're in control over the router in between, then I'd setup masquerading for the outgoing routing interface of the VLAN/subnet where the Xiaomi devices reside. This basically means changing the source address in the UDP packet headers to the IP address of routing interface. If you want to know more about this, just inform yourself about packet masquerading and/or SNAT."

Somehow it doesn't convince me, why is it that my phone in Segment B can work just right with the Android app but the HA Server in Segment B can't work with the Xiaomi fan in Segment A in both cases? I am just curious shouldn't we have a similar approach in both cases? Besides, no other smart devices like Tuya, Welink, etc enabled have any issues.

syssi commented 1 year ago

As far as I know it's a limitation of the device firmware.

keshabit commented 1 year ago

Thank you @syssi, let me work on this as guided by the suggested solution.

keshabit commented 1 year ago

Just to add, so that it can help folks with pfSense to make Xiaomi devices work with multi-VLAN (trusted) configuration: a. Change the Outbound NAT of pfSense to Hybrid mode. b. Create an outbound NAT rule. i. Add the interface where Xiaomi VLAN is configured. ii. Source Subnet from which vLAN you wanted to access the Xiaomi Devices. iii. You can put UDP if specific for Xiaomi or include TCP and UDP both. iv. Destination Subnet where Xiaomi Device is located. v. Translation put the Xiaomi Subnet addresses. That's it! It worked in my case. A big thanks to @syssi for the prompt response and help. Keep up the good work.