Sony Bravia TV component with Pre-Shared Key

Works fine here with 76.2!

1 Like

This was working for me perfectly before .77.2 and now I can’t get my configuration to validate.

Running fine here on 0.77.2. What is your config and which errors are shown when validating?

its the same as before, I have had to rebuild my system but I went through the same steps as you outlined them, no errors when I put the component, but as soon as I put the YAML entry for a tv I get these errors

ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/config_entries.py”, line 359, in async_forward_entry_setup
self.hass, component, self._hass_config)
File “/usr/local/lib/python3.6/site-packages/homeassistant/setup.py”, line 45, in async_setup_component
return await setup_tasks[domain] # type: ignore
File “/usr/local/lib/python3.6/site-packages/homeassistant/setup.py”, line 56, in async_setup_component
return await task # type: ignore
File “/usr/local/lib/python3.6/site-packages/homeassistant/setup.py”, line 118, in _async_setup_component
conf_util.async_process_component_config(hass, config, domain)
File “/usr/local/lib/python3.6/site-packages/homeassistant/config.py”, line 757, in async_process_component_config
platform = get_platform(hass, domain, p_name)
File “/usr/local/lib/python3.6/site-packages/homeassistant/loader.py”, line 62, in get_platform
return get_component(hass, PLATFORM_FORMAT.format(domain, platform))
File “/usr/local/lib/python3.6/site-packages/homeassistant/loader.py”, line 94, in get_component
module = importlib.import_module(path)
File “/usr/local/lib/python3.6/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 955, in _find_and_load_unlocked
File “”, line 665, in _load_unlocked
File “”, line 674, in exec_module
File “”, line 781, in get_code
File “”, line 741, in source_to_code
File “”, line 219, in _call_with_frames_removed
File “/config/custom_components/media_player/braviatv_psk.py”, line 7

^
SyntaxError: invalid syntax
2018-09-03 18:25:23 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/config_entries.py”, line 359, in async_forward_entry_setup
self.hass, component, self._hass_config)
File “/usr/local/lib/python3.6/site-packages/homeassistant/setup.py”, line 45, in async_setup_component
return await setup_tasks[domain] # type: ignore
File “/usr/local/lib/python3.6/site-packages/homeassistant/setup.py”, line 56, in async_setup_component
return await task # type: ignore
File “/usr/local/lib/python3.6/site-packages/homeassistant/setup.py”, line 118, in _async_setup_component
conf_util.async_process_component_config(hass, config, domain)
File “/usr/local/lib/python3.6/site-packages/homeassistant/config.py”, line 757, in async_process_component_config
platform = get_platform(hass, domain, p_name)
File “/usr/local/lib/python3.6/site-packages/homeassistant/loader.py”, line 62, in get_platform
return get_component(hass, PLATFORM_FORMAT.format(domain, platform))
File “/usr/local/lib/python3.6/site-packages/homeassistant/loader.py”, line 94, in get_component
module = importlib.import_module(path)
File “/usr/local/lib/python3.6/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 955, in _find_and_load_unlocked
File “”, line 665, in _load_unlocked
File “”, line 674, in exec_module
File “”, line 781, in get_code
File “”, line 741, in source_to_code
File “”, line 219, in _call_with_frames_removed
File “/config/custom_components/media_player/braviatv_psk.py”, line 7

^
SyntaxError: invalid syntax
2018-09-03 18:25:27 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting

Can you check if you copied the braviatv_psk.py file correctly? The error indicates something went wrong there.
Latest version is here https://github.com/custom-components/media_player.braviatv_psk?files=1 and supports the Lovelace tracker card so you are informed that there is a new version of the supported custom components.

thank you very much that did the trick

Hello,

Great work there. Would it be possible to be able to launch apps using braviarc.start_app(“AppName”) ?

Cheers

@fredericpfisterer I have added api for that in my fork:


Exposes media_player.bravia_open_app command that needs to be called with an uri identifier of the app.

List of available apps can be retrieved from the TV but I haven’t exposed API for that.

Example IDs (at least on my TV) are:
Netflix: com.sony.dtv.com.netflix.ninja.com.netflix.ninja.MainActivity
Youtube: com.sony.dtv.com.google.android.youtube.tv.com.google.android.apps.youtube.tv.activity.ShellActivity

I have such script defined in HA for example:

tv_open_youtube:
  alias: Youtube
  sequence:
    - service: media_player.bravia_open_app
      data:
        entity_id: media_player.mybraviatv
        uri: com.sony.dtv.com.google.android.youtube.tv.com.google.android.apps.youtube.tv.activity.ShellActivity
1 Like

Hi

I have KDL-42W653A (2013, not in the docs list tho) and it is working via PIN perfectly. No psk option either.

Are you sure is “uri: …” and not “url: …” ?

From your link

Don’t be misled by that name :wink:
I have made an addition to the braviatv_psk component so it will also support the older PIN method. So the settings of the screenshot are definitely okay.

That version is still in development with the goal to upgrade the current Bravia component in HA, but I don’t have enough time to give that the attention it needs.

@Nikiya_Osborn I heared the podcast for the HA 0.80 release. Were you reffering to this custom component for your Bravia TVs at 37:00?

Hey @gerard33,
Thanks for the hard work. I’m new to HA and have been trying (unsuccessfully) to get this to work with my Sony Bravia.
I’ve done everything you said. I don’t get any particular error afterwards…
Just this:

It doesn’t work at all. I’ve rebooted several times, to no avail
What am I missing?

I guess your screenshot is made when the TV is actually on? Otherwise there is no issue :wink:

Can you share your config? And do you have an Android TV?

Is there anything we can do to help? It would be great to upgrade the official openhab version to the PSK one. I’d also love to get @rchl new services added so we can send remote commands.

Also I’ve got some streaming channels and on the TV remote I can type “202” (CBeebies for those in the UK!) and the streaming channel comes up. I’d love to figure out how to do that via the TV api. Sending the commands Num2, Num0, Num2 doesn’t seem to work.

I’ve made some changes to the stock bravia component to support PSK and similar features…anyways, I’ve added support to add Android apps to Sources list (can be filtered). This allows for launching apps too. I’ve hooked in a Harmony Elite remote which HomeAssistant reacts on by launching Netflix, Kodi, Plex, or YouTube.

Code changes involve python braviarc and python homeassistant::media_player::braviatv.


1 Like

DOes it work with sony bluray home theather with wifi?

Here are some commands that were being sent in CURL form. They work without authentication. Maybe they are useful to you. If I ever dig into python like I’ve wanted to I’ll see what I can do. I’ve just moved to home assistant and had this and a few other resources I gathered while playing around with lua to automate things in Vera. There’s lots of data that you can get I’ve just never had the time to really sit down and get it all sorted out.

The formatting on this isn’t correct because I just had it in a text file so beware copy paste might not work without removing spaces and things.

curl -v -XPOST http://192.168.178.27/sony/system -d ‘{“method”:“getMethodTypes”,“params”:[""],“id”:1,“version”:“1.0”}’

curl -v -XPOST http://192.168.178.27/sony/system -d ‘{“method”:“getInterfaceInformation”,“params”:[],“id”:2,“version”:“1.0”}’

curl -v http://192.168.178.27:52323/dmr.xml

curl -v http://192.168.178.27:52323/RenderingControlSCPD.xml

curl -v http://192.168.178.27:52323/ConnectionManagerSCPD.xml

curl -v http://192.168.178.27:52323/AVTransportSCPD.xml

curl -v http://192.168.178.27:52323/DIALSCPD.xml

curl -v http://192.168.178.27:52323/IRCCSCPD.xml

curl -v http://192.168.178.27:52323/ScalarWebApiSCPD.xml

curl -v -XPOST http://192.168.178.27:52323/upnp/control/ConnectionManager --header ‘SOAPACTION: “urn:schemas-upnp-org:service:ConnectionManager:1#GetProtocolInfo”’ --header ‘Content-Type: text/xml; charset=“utf-8”’ -d ‘<?xml version="1.0"?><s:Envelope xmlns:s=“http://schemas.xmlsoap.org/soap/envelope/” s:encodingStyle=“http://schemas.xmlsoap.org/soap/encoding/”><s:Body><u:GetProtocolInfo xmlns:u=“urn:schemas-upnp-org:service:ConnectionManager:1”></u:GetProtocolInfo></s:Body></s:Envelope>’

curl -v -XPOST http://192.168.178.27/sony/accessControl -d ‘{“method”:“getMethodTypes”,“params”:[""],“id”:2,“version”:“1.0”}’

curl -v -XPOST http://192.168.178.27/sony/encryption -d ‘{“method”:“getMethodTyp
es”,“params”:[""],“id”:3,“version”:“1.0”}’

curl -v -XPOST http://192.168.178.27/sony/recording -d ‘{“method”:“getMethodTypes”,“params”:[""],“id”:7,“version”:“1.0”}’

curl -v -XPOST http://192.168.178.27/sony/browser -d ‘{“method”:“getMethodTypes”,“params”:[""],“id”:6,“version”:“1.0”}’

curl -v -XPOST http://192.168.178.27/sony/appControl -d ‘{“method”:“getMethodTypes”,“params”:[""],“id”:4,“version”:“1.0”}’

curl -v -XPOST http://192.168.178.27/sony/accessControl -d ‘{“method”:“actRegister”,“params”:[{“clientid”:“TVSideView:4e6b4a7a-aa52-416e-bfad-6aac6f560f9d”,“nickname”:“Nexus 5 (TV SideView)”,“level”:“private”},[{“value”:“yes”,“function”:“WOL”}]],“id”:8,“version”:“1.0”}’

Here’s a link to the sony protocol documentation if you haven’t seen it. https://shop.kindermann.de/erp/KCO/avs/3/3005/3005000168/01_Anleitungen+Doku/Steuerungsprotokoll_1.pdf

I have a slightly older Sony Bravia so the integration does not work.
However, I’ve been looking at what is being sent and I think it could be made to (largely) work with prior generation like mine.
I think that there are 2 key elements to it …

  1. The initial authentication (to authorise a MAC address for remote control) does not use a PIN or PSK. There is a dialogue on the TV but it just requires a confirmation using the regular TV remote control
  2. The remote control emulation appears to be the same but the starting point is /IRCC not /sony/IRCC. I think that the code could handle this automatically because the UPnP discovery returns /dmr.xml which has a section
<service>
<serviceType>urn:schemas-sony-com:service:IRCC:1</serviceType>
<serviceId>urn:schemas-sony-com:serviceId:IRCC</serviceId>
<SCPDURL>http://192.168.0.2:80/IRCC/IRCCSCPD.xml</SCPDURL>
<controlURL>http://192.168.0.2:80/IRCC</controlURL>
<eventSubURL/>
</service>

and I think newer TV would return …

<controlURL>http://192.168.0.2:80/sony/IRCC</controlURL>

So rather than hard-coding the URL start point it could be dynamically generated from the data returned by the TV or moved into the config file with the default being /sony/IRCC

I do not know if other things would go wrong later … so I plan to edit the existing code to handle those two things and see what happens.

Note - there is an open source library in C# that supports Sony TVs going back even further.
A mot suggesting importing it but it could give some ideas about how to handle different versions of the Sony equipment.