Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling when PS5 is completely turned off #42

Open
CooperCGN opened this issue Jan 17, 2022 · 8 comments
Open

Error handling when PS5 is completely turned off #42

CooperCGN opened this issue Jan 17, 2022 · 8 comments

Comments

@CooperCGN
Copy link

CooperCGN commented Jan 17, 2022

Hi, first thanks for the awesome work.

Is there a way to get a proper error in return when the PlayStations is completely turned off. Right now I am using Playactor together with a homebridge plugin which polls the PS5 every 15 seconds, works good as long as the PS is in standby. When completely turned off my log gets spammed with this:

Error: Unable to locate device: device named PS5-XXX
at PendingDevice. (/usr/local/lib/node_modules/playactor/dist/device/pending.js:82:19)
at Generator.next ()
at fulfilled (/usr/local/lib/node_modules/playactor/dist/device/pending.js:5:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5)

I hope you get what I mean, any ideas?

@dhleong
Copy link
Owner

dhleong commented Jan 17, 2022

How are you invoking playactor and what are you hoping for? That error message describes the situation as clearly as it can; if the Playstation is completely off then it won't respond to pings so there's no way for it to know whether or not it exists.

@CooperCGN
Copy link
Author

The plugin invokes playactor on a set interval (in my case 5 seconds) by calling playactor check --host-name PS5-XXX | grep -i '200 Ok'. As I am not a coder I was thinking that maybe it would be possible to have some kind of option to override the error message and just let playactor assume that the PS5 is turned off, in standby.

@dhleong
Copy link
Owner

dhleong commented Jan 24, 2022

Can you just use the exit codes instead of grep? Per the help docs:

playactor check -h

  Detect a device and its state on the network. If found, information
  about it will be printed to the console.

  In addition, the status of the device can be determined by the exit code
  of this process:

      0 - The device was found and is awake
      1 - The device was found and it is in standby
      2 - The device was not found

@CooperCGN
Copy link
Author

But how do I get the exit code in return? Even when I remove the grep part and execute the playactor check command I just get the error output mentioned in my OP when the PS5 is turned off

@dhleong
Copy link
Owner

dhleong commented Jan 25, 2022

I'm not sure how you're integrating playactor into what you're doing, but exit codes are just a part of executing a program. In bash if you echo $?, I think, it will print out the exit code from the last thing you ran. In this case, an exit code of 0 (which generally means success) means the console is awake. A non-zero exit code generally means "error" so in this case means it's either asleep or not found.

@keremerkan
Copy link

keremerkan commented Feb 13, 2022

Here is how I tackled this problem:

  1. My Homebridge system is on Linux. This solution will work on Linux or Mac systems.
  2. My PS5 has a fixed IP address. That's why the scripts I'll add below uses a slightly different format from the wiki for playactor while calling it. You can change them to your liking.
  3. My Homebridge setup works from /var/lib/homebridge. You'll need to change the paths according to your Homebridge setup.

Steps:

  1. Create a directory called scripts under /var/lib/homebridge
  2. Create a file called playactor-wake.sh under /var/lib/homebridge/scripts and add the following to it (Don't forget to change the wake command according to your system:
#!/bin/bash

/usr/bin/playactor wake --ip 192.168.0.10 >> /dev/null 2>&1

if test "$?" != "0"; then
  >&2 echo "Could not wake PS5. Check if it is completely turned off."
  exit 1
fi

exit 0
  1. Create a file called playactor-standby.sh under /var/lib/homebridge/scripts and add the following to it (Don't forget to change the standby command according to your system:
#!/bin/bash

/usr/bin/playactor standby --ip 192.168.0.10 >> /dev/null 2>&1

if test "$?" != "0"; then
  >&2 echo "Could not standby PS5. Check if it is completely turned off."
  exit 1
fi

exit 0
  1. Create a file called playactor-check.sh under /var/lib/homebridge/scripts and add the following to it (Don't forget to change the check command according to your system:
#!/bin/bash

/usr/bin/playactor check --ip 192.168.0.10 --timeout 5000 >> /dev/null 2>&1

if test "$?" != "0"; then
  exit 1
fi

exit 0
  1. Make the files executable using chmod 755 and change their owner to the Homebridge user.
  2. Replace the on, off and state commands in the CMD plugin with these files.
  3. Profit!!! These files will replace the flooding errors with simple one line error explanations for wake and standby commands when the device is turned off and it will remove the errors for check command completely.

@CooperCGN
Copy link
Author

@keremerkan thank you so much, that’s exactly what I am trying to achieve. Will try it as soon as I am back home from work.

@keremerkan
Copy link

@CooperCGN no problem. Hope it works for you. Let me know if you need anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants