Integration: emulated_roku - Sofabaton compatibility

With the end of life for Harmony remotes, it would be great for emulated_roku to support Sofabaton remotes.
Currently, the version of roku is too old for Sofabaton to recognize it. The app will not detect the emulated_roku as a valid roku device.

Ref: https://www.reddit.com/r/homeassistant/comments/wdppb7/having_difficulties_getting_the_emulated_roku_to/

I’ve discovered a work around. Turn off Home Assistant and turn on a real Roku device with the same IP address. Add the Roku to the SofaBaton. Turn off the Roku and startup Home Assistant with the Roku emulator running. You can now use the SoftBaton with the Emulated Roku interface.

I get it working with Sofabaton X1 by modifying the multicast response in the _init_.py file of the library before running the advertise script on my computer.
Specifically, I added the following lines in the response :

Ext:
Server: Roku UPnP/1.0 MiniUPnPd/1.4

The repsonse of the advertise script must look like:

DEBUG:emulated_roku:multicast:reply ('192.168.1.124', 1900)
HTTP/1.1 200 OK
Cache-Control: max-age = 300
ST: roku:ecp
Ext:
Server: Roku UPnP/1.0 MiniUPnPd/1.4
Location: http://192.168.1.29:8060/
USN: uuid:roku:ecp:Home Assistant

So the code in the library must be changed from :

MULTICAST_RESPONSE = "HTTP/1.1 200 OK\r\n" \
                     "Cache-Control: max-age = {ttl}\r\n" \
                     "ST: roku:ecp\r\n" \
                     "Location: http://{advertise_ip}:{advertise_port}/\r\n" \
                     "USN: uuid:roku:ecp:{usn}\r\n" \
                     "\r\n"

to :

MULTICAST_RESPONSE = "HTTP/1.1 200 OK\r\n" \
                     "Cache-Control: max-age = {ttl}\r\n" \
                     "ST: roku:ecp\r\n" \
                     "Ext: \r\n" \
                     "Server: Roku UPnP/1.0 MiniUPnPd/1.4\r\n" \
                     "Location: http://{advertise_ip}:{advertise_port}/\r\n" \
                     "USN: uuid:roku:ecp:{usn}\r\n" \
                     "\r\n"

After making this change, I ran the advertise.py script with my Home Assistant IP address. The Sofabaton App immediately discovered the Fake Roku.
However, there was a minor issue: the Roku device created in the Sofabaton app was assigned the IP address of the computer running the advertise.py script, 192.168.1.124 in my case, not the IP of my Home Assistant instance.
Fortunately, it’s possible to manually change the IP address of the Roku device in the Sofabaton App to correct this.

I tried with your solution, but its not working :confused:
maybe can you help me check why?
thank you in advance

Also tried with your solution but sadly the app does’nt find the emulated device (also not on another computer with the advertise.py).

Any hint’s?

thx

I’ve used an old android phone and installed an old version of sofabaton.
I’ve added the roku emulator from HA with success and now it works with the new app too

1 Like

thx, ok, so now i know why it was not working for me on the newer apps.
Any hints which app version of sofabaton did you use?

thx

Your nickname is the name of one of my cats :grin:
And because of that I’m even more happy to help you.

The version I used is the 3.1.5, first version compatible with X1 remote, didn’t tried other versions, as this one worked very well.

1 Like

I like your cat :wink:
Thanks for your help and the info regarding the version.

Will try that when i found time :slight_smile:

thx a lot

Tried it with the old app but cant get it to work.
Anyway, thx for your help.

Found a solution which also works for the newest (current) SofaBaton App version 3.3.5 :slight_smile:

I have used the current master from: GitHub - martonperei/emulated_roku
Which has an commit 3 months ago about sofabaton support.

I have just executed “advertise.py” (with correct paramerters) as stated in every post i found. the request from the app was visible in the cmd output but it did not show up for setup.

After decompilation of the current apk, i found out that the app is requesting the “apps” from the roku device after the multicast answer on port 8060. I proved that by looking at wireshark, where short after the multicast answer from the emulated roku, an request to IP:8060 was made, and sure unanswered from my PC.

And now the solution: You have to run “example.py” instead of “advertise.py” to get also the webserver running on 8060 port and FINALLY the sofabaton app is finding the emulated roku device.
After that you can set it up and change the IP to HA emulated roku and the events are received by HA :slight_smile:

So my conlusion is that in old versions no apps where discovered by the sofabaton app and just answering the multicast by “advertise.py” was enough to get it recognized.

As a bonus, in “init.py” you can add/change the custom apps template “APPS_TEMPLATE” so you can have more keys like “Scene living room”, … (as apps).

I hope this helps
pOpY

3 Likes

Thank you very much for sharing your findings. Greatly appreciated and finally got my integration working.

Have you found a way to force refreshing the apps from init. Was hoping that by starting it on my laptop and switching the IP back to it I could force the apps to update, but without success. That would be Ideal to add new scenes without having to redo all the activities.

Thanks again.

1 Like

Nice that it worked for you!

Sadly i found no way of “updating” the apps.
I think that’s an issue of the sofabaton app which just stores what it sees first.

Yeah… I wonder how good the integration is with a real Roku device then.

So… Not 100% working, but Creating a new Device with the updated apps, then removing the old one. You can now update the activity and re-add the new device. Only need to re-configure your actions on the activity.

Better than nothing I would guess.

As you said, better than nothing :slight_smile:

Hey Poppy,

I received a new SX1(x1 remote is almost dead because of the scrool wheel) and the method with the old app doesn’t work anymore.

As I don’t have experience with python and so, can you explain a little bit in more detail how can I achieve this?

Thank you in advance

just setup python on your machine (google for guides), clone or download latest master (GitHub - martonperei/emulated_roku) and run in an cmd line (where you have downloaded it):

python3 example.py
go to sofabaton app and add an wifi device and select roku,
When you want custom apps just edit the “init.py” as descibed above.

Hope this helps

Ps.: maybe you have to turn off your firewall on your machine during this :slight_smile:

I tried this on 2 differents linux machines and it dons’t work.
I can go to the ip:port:

in the app can’t see it :confused:

I have done it on windows with disabled firewall, but doesn’t see any reason why it should not work on Linux.

When you run the “python3 example.py” what’s the output?

now I’m running on linux and windows.
I can access th ip and port for both.
the output:

DEBUG:asyncio:Using proactor: IocpProactor
DEBUG:emulated_roku:roku_api:starting server 10.0.1.68:8060
DEBUG:emulated_roku:multicast:started for 239.255.255.250/10.0.1.68:8060/usn:test_roku
DEBUG:emulated_roku:multicast:broadcast
NOTIFY * HTTP/1.1
HOST: 239.255.255.250:1900
Cache-Control: max-age = 300
NT: upnp:rootdevice
NTS: ssdp:alive
Location: http://10.0.1.68:8060/
USN: uuid:roku:ecp:test_roku

same output on both, different IP’s