I was looking for a way to track how long I use Ring Fit Adventure. Unfortunately the Nintendo Switch doesn’t have any integrations.
So I used a piece of homebrew on my homebrew enabled Switch.
It is originally made for Discord Rich Presence but with a small script it is also available in Home-Assistant as a sensor.
This is beyond cool. I had been using the Discord Presence sysmodule with the intended PC client to update the Discord status, then the Discord Integration to pull the values into Home Assistant. Your way is so much more elegant, gonna update mine ASAP.
EDIT: It doesn’t seem to work too well for me. If I run the script manually, it works once (but also prints “off” after the game title), then subsequent attempts just result in “off”. After the initial attempt from the script, the presence client on the PC also stops working. If I go to the presence client manager on the Switch and toggle the module, it “resets” and allows the PC client and an initial script attempt to work. However, after the reset, it stops working after the first script attempt and the cycle continues.
I’m not really familiar with Python, but I tried removing the try/except statement to see what exception is occurring. The first attempt works, the second takes a few seconds to error out with:
Traceback (most recent call last):
File "switch-presence-noExcept.py", line 35, in <module>
main()
File "switch-presence-noExcept.py", line 26, in main
data = sock.recv(628)
socket.timeout: timed out
While every subsequent attempt after that produces:
Traceback (most recent call last):
File "switch-presence-noExcept.py", line 35, in <module>
main()
File "switch-presence-noExcept.py", line 26, in main
data = sock.recv(628)
ConnectionResetError: [Errno 104] Connection reset by peer
I’ll keep trying to mess around with this and see what else I can find out.
I have updated the script. Could you try again? Running the second time works for me. But only after waiting for a few seconds. This is no problem for me since the command_line sensor updates every 60 seconds.
I got it working, similar to your change I took the exit() method out of the try/except statements (although moved it outside instead of removing it completely). I also included the game ID so it can be used for a nice-looking media player:
For the images to work, you’ll need to launch SwitchPresence-Rewritten-Manager.nro and dump the images, then transfer the contents of your Switch SDMC://Images folder to a HomeAssistant /config/www/nintendo_switch_thumbnails/ directory.
Cheers mate, ditto I noticed today though that the code on my JSON couldn’t handle apostrophes in the game title and had to swap the replace ' with " function for json.dumps(). I updated the code in my previous post in case anyone is interested.
My Switch is modded, but I haven’t messed with it in a while. When does the homebrew send the data? Is it only while at the Switch dashboard, on startup and obviously not while in sleep mode?
Based on my novice understanding I believe the homebrew doesn’t “send” data, it runs constantly and responds to queries sent from the script or presence client at whatever interval it’s defined to.
Interestingly, it still responds when asleep, docked and using wired ethernet; if you put it to sleep while running a game, even if suspended and on the Home menu, it gives the same response as if you were actively playing the game. The only way I can get around this is letting it use wifi. Not a huge deal since I don’t wanna play online with my modded Switch.
I just came across this repo where someone was able to pull data from his switch account using the parental controls features…
THe code is 2yrs old, but Im going to see if i can get it working as-is… if I can, i may need some help turning it into an integration, as I have never done an integration before.