home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.88k stars 30.11k forks source link

Issue with PS4 discovery on firewalled HA (and runnning in docker) #41688

Closed KiwiLostInMelb closed 3 years ago

KiwiLostInMelb commented 3 years ago

The problem

When running with a firewall which blocks dynamic UDP ports the PS4 component does not work - devices not discovered.

Environment

Problem-relevant configuration.yaml

Traceback/Error logs

There were no errors detected when logging in debug mode - just no devices found. Fix is required for pyps4_2ndscreen

Additional information

Ok, so I have found the issue and submitted a fix to pyps4_2ndscreen. Link is: https://github.com/ktnrg45/pyps4-2ndscreen/issues/40

Basically, the pyps4_2ndscreen code uses a dynamic port for discovery. This will of course fail in a firewalled/locked down environment regardless of if I was running docker as HOST or on a bridge adapter. When I got the cli version of pyps4 working there was still an issue with HA. All fixed now but may have implications if and when the change is rolled out for pyps4_2ndscreen as it adds another port to be mapped.

Change was to ddp.py in discovery.init code.....

def init(self):
  """Init."""
  self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  if SEARCH_UDP_PORT is None:
    SEARCH_UDP_PORT = 997
  self.sock.bind((UDP_IP, SEARCH_UDP_PORT))
  _LOGGER.debug(
    "Binding discovery IP: %s Port: %d",
    UDP_IP, SEARCH_UDP_PORT)
  self.sock.settimeout(6.0)
....

See added port definition for the responding port - 997 UDP.

So I dont really know if you are interested in this at all but thought I would share as it was the only way I could get the PS4 integration working on my HA installation. This MUST have been seen by others with firewalled HA installations???

Over to you guys.

probot-home-assistant[bot] commented 3 years ago

Hey there @ktnrg45, mind taking a look at this issue as its been labeled with an integration (ps4) you are listed as a codeowner for? Thanks! (message by CodeOwnersMention)

realjax commented 3 years ago

I am not exactly sure what the definition of a fiewalled HA instance is, but the fact is that on my raspberry pi running HassOS 4.13 the PS4 discovery no longer works either.

ktnrg45 commented 3 years ago

I am not exactly sure what the definition of a fiewalled HA instance is, but the fact is that on my raspberry pi running HassOS 4.13 the PS4 discovery no longer works either.

@realjax Are your PS4's configured in HA already? If they are, the integration ignores them to avoid double configuration. BTW I should add that the discovery part is only used in configuration.

KiwiLostInMelb commented 3 years ago

Firewalled/locked down - means that my server does not allow any TCP/UDP ports through EXCEPT those that I specifically allow. I run on HA in docker on linux and not raspi which I think is open - hence no problem for a lot of users. RaspPi is just too slow for my install and I have a full time server available.

I had to use the new version of the second screen code (overwrite python site package) AND allow the extra UDP port through the firewall to the HA docker instance to get HA to discover the PS4.

I tested that the command line version of 2nd screen worked first (via docker container exec) before getting HA up and running. CLI and HA dont share config files.

Hope this makes sense.

Good luck!

All working in HA now.

On Tue, 20 Oct 2020 at 12:10, ktnrg45 notifications@github.com wrote:

I am not exactly sure what the definition of a fiewalled HA instance is, but the fact is that on my raspberry pi running HassOS 4.13 the PS4 discovery no longer works either.

@realjax https://github.com/realjax Are your PS4's configured in HA already? If they are, the integration ignores them to avoid double configuration.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/issues/41688#issuecomment-712526528, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGJZGMNDUZQE4VPDJCMWR3SLTPRTANCNFSM4SMELG7A .

realjax commented 3 years ago

I am not exactly sure what the definition of a fiewalled HA instance is, but the fact is that on my raspberry pi running HassOS 4.13 the PS4 discovery no longer works either.

@realjax Are your PS4's configured in HA already? If they are, the integration ignores them to avoid double configuration. BTW I should add that the discovery part is only used in configuration.

I removed the integration and added it again, restarting HA in the process and tried this several times. I assume that should do the trick right? Anyway, it didn't :) It still cant find my ps4.. I can see the home assistant 'ps4' in the second screen app, but it never finds it from HA automatically nor by using its ip address

realjax commented 3 years ago

Firewalled/locked down - means that my server does not allow any TCP/UDP ports through EXCEPT those that I specifically allow. I run on HA in docker on linux and not raspi which I think is open - hence no problem for a lot of users.

Thanks @KiwiLostInMelb , I guess my setup needs no futher tinkering with ports then.

ktnrg45 commented 3 years ago

I am not exactly sure what the definition of a fiewalled HA instance is, but the fact is that on my raspberry pi running HassOS 4.13 the PS4 discovery no longer works either.

@realjax Are your PS4's configured in HA already? If they are, the integration ignores them to avoid double configuration. BTW I should add that the discovery part is only used in configuration.

I removed the integration and added it again, restarting HA in the process and tried this several times. I assume that should do the trick right? Anyway, it didn't :) It still cant find my ps4.. I can see the home assistant 'ps4' in the second screen app, but it never finds it from HA automatically nor by using its ip address

Ok. Just making sure this is not the same issue. Discovery uses broadcasts which will not work if your HA host and ps4 are not on the same vlan/subnet, which is why there is an option to enter the ip address manually during config.

realjax commented 3 years ago

They're on the same subnet 🙂

ktnrg45 commented 3 years ago

Hmm may be something else then. Discovery still works for me on HassOS 4.14 + Core 0.115.2.

Can your ps4 second screen app find the ps4?

realjax commented 3 years ago

Yes, the second screen app finds both the ps4 and Home assistant, but then (after selecting home ass. in the app) when I select auto discovery, te integration says 'No PlayStation 4 devices found on the network.'

realjax commented 3 years ago

PS. I ran HassOS at 4.13, updated to 4.14 but it made no difference.