GithubHelp home page GithubHelp logo

seydx / homebridge-sonybravia-platform Goto Github PK

View Code? Open in Web Editor NEW
20.0 8.0 0.0 9 MB

Sony Android TV Platform for Homebridge

License: MIT License

JavaScript 100.00%
homebridge homebridge-plugin cec sony-android-tv apple-tv hdmi sony sony-bravia-tv

homebridge-sonybravia-platform's Introduction

homebridge-sonybravia-platform v2.5

npm npm GitHub last commit

Homebridge Platform Plugin for Sony Bravia Android TV

This is a Plugin for Homebridge to control your Sony Android TV.

Note: If you are looking for the dynamic version, install the new version! homebridge-bravia-tv v3

Following functions can be exposed to HomeKit:

  • Switch for TV Power (on/off)
  • Switch for the inputs like HDMI, Scart, CEC Devices, AV, WIFI mirroring
  • Switch for Apps with custom characteristics (see below)
  • Switch for Channels with custom characteristics (see below)
  • Bulb for controlling the volume
  • Remote Controll with commands like toggle mute, toggle tv power, channel up, channel down, enter, return etc

Why do we need this plugin?

With this plugin you can create scenes for apps (i.e. starting Amazon Prime), controll your CEC devices like Apple TV or PlayStation, track the state of the TV (on/off), Source Inputs and Volume

See Images for more details.

Installation instructions

After Homebridge has been installed:

  • sudo npm install -g homebridge-sonybravia-platform
  • sudo apt-get install jq

Preparing the TV

  • Set "Remote start" to ON in your Android TV Settings -> Network -> Remote Start
  • Change "Authentication" to "Normal and Pre-Shared Key" in your Android Settings -> Network -> IP Control -> Authentication
  • Enter a "Pre-Shared Key" in your Android TV Settings -> Network -> IP control -> Pre-Shared Key

Basic config.json:

{
"bridge": {
  ...
},
"accessories": [
  ...
],
"platforms": [
{
 "platform":"SonyBravia", 
 "name":"Sony",
 "ipadress":"192.168.1.1",
 "psk":"YourPSK",
}
]
}

Advanced config.json:

{
"bridge": {
  ...
},
"accessories": [
  ...
],
"platforms": [
{
 "platform":"SonyBravia", 
 "name":"Sony Bravia",
 "ipadress":"192.168.1.1",
 "port":80
 "psk":"YourPSK",
 "interval": 5,
 "maxVolume":35,
 "extraInputs":false,
 "volumeEnabled": true,
 "appsEnabled": true,
 "channelsEnabled":false,
 "channelSource:"tv:dvbt",
 "inputsEnabled":true,
 "detectCEC":true,
 "offState": "HOME",
 "remoteControl":true,
 "controlMode":"BASIC",
 "homeapp":"com.sony.dtv.eu.siptv.video.eu.siptv.atv.MainActivity",
 "favChannel":"tv:dvbt?trip=1.1051.10304&srvName=SWR RP HD"
}
]
}

Multiple TVs

If you want to control multiple TVs , just add a second platform (see above), change the IP, PSK and set a new unique NAME.

APPS

Exposed as a Switch to HomeKit, that detects automatically all apps from the TV. It also has new characteristics, that allows to control and set the Home App withing the EVE App AND change between ALL installed apps on the TV. You will be able to create own scenes. You can dim the light if you start YouTube and many more.. Note: Apple Home App doesnt support Accessory with own characteristics. So you need to use apps like Elgato EVE or other to create own scenes.

See Images for more details.

*Home APP

Home App is an on the TV installed app that can be defined in the config.json file (in v2.3 you are also able to set the Home App within the app!).

With the following command for terminal you will get a list of apps that are installed on your TV (Change TVIPHERE, YOURPSKERE with your data, be sure that jq is installed, see above)

  • curl -XPOST http://TVIPHERE/sony/appControl -d '{"id":2,"method":"getApplicationList","version":"1.0","params":["1.0"]}' -H 'X-Auth-PSK: YOURPSKERE' | jq -r '.result[]'

Just search your app and copy the adress of the coosen app. This is an example adress of my IPTV: com.sony.dtv.eu.siptv.video.eu.siptv.atv.MainActivity

If you dont set this in your config.json, the plugin will look for any cached home apps, if there is nothing, it will take the uri of the app in the first place (in most cases it is Play Store)

Channels

Exposed as a Switch to HomeKit, that detects automatically all channels from the TV. It also has new characteristics, that allows to control and set the favourite channel withing the EVE App AND change between ALL channels on the TV. You will be able to create own scenes. Note: Apple Home App doesnt support Accessory with own characteristics. So you need to use apps like Elgato EVE or other to create own scenes.

See Images for more details.

*Favourite Channel (favChannel)

With the following command for terminal you will get your favourite channel (Change TVIPHERE, YOURPSKERE with your data, be sure that jq is installed, see above! NOTE: "stIx" is your channel number on the TV, BUT you need to substract with 1! i.e. Channel Numb on tv is 30, then "stIx" is 29!) (in v2.3 you are able to set the favourite channel within the EVE app!)

  • curl -XPOST http://TVIPHERE/sony/avContent -d '{"id":2,"method":"getContentList","version":"1.2","params":[{"source":"tv:dvbt","stIx":0}]}' -H 'X-Auth-PSK: YOURPSKERE' | jq -r '.result[][0]'

For your config.json you need the "uri" from output. i.e: tv:dvbt?trip=1.1051.10304&srvName=SWR RP HD

If you dont set this in your config.json, the plugin will look for any cached favourite channels, if there is nothing, it will take the first channel

OFFSTATE

Due to the reason that its not possible to deactivate / shut down a HDMI input, CEC device etc., this option give you the possibility to set your own off command. There are 3 Modes: "HOME" for starting the home app, "CHANNEL" for switching to youor favourite channel and "OFF" for turning off the TV.

CEC Device

In v2.3 it's not necessary to do complicated steps to get a list of your cec devices. If you want to expose your CEC devices like Apple TV or PlayStation 4 just put "detectCEC":true in your config.json and follow the instructions in the log. Thats it.

NOTE: If you have issues with the state of your CEC Device (due to different tv models) you can set "cecDevices" in your config.json to set manually the HDMI port. The title must be the same as from the cec device. Example:

"cecDevices":[
    {
      "title":"Apple TV",
      "hdmiport":4
    }
]

Remote Control

In v2.5 you have the possibility to expose a remote control (if "remoteControl" is true in config.json) to HomeKit. With the remote control, you can send commands like channel up, channel down, volume up, volume down, enter, home, toggle mute, toggle power etc. You have also the possibility to choose between "BASIC" or "ADVANCED" mode ("controlMode" in config.json). "BASIC" will only expose basic switches to HomeKit. "ADVANCED" will expose some more stuff. All these "commands" will be available within the "Remote Control" service. Therefore, this service is not compatible with the Apple Home app! You can use this with apps like Elgato EVE, Home etc.

Options

Attributes Required Usage
name Yes Unique Name for the Platform.
ipadress Yes IP adress from your Sony Bravia TV
port No If you have problems with connecting to the TV, try a different port (Default: 80)
psk Yes Your Pre Shared Key
interval No Polling Interval in seconds (Default: 2s)
inputsEnabled No Exposes HDMI inputs to HomeKit (Default: true)
extraInputs No Exposes extra sources like AV, display mirroring etc. (Default: true)
detectCEC No Exposes CEC devices instead of HDMI inputs to HomeKit (Default: true)
cecDevices No ONLY if you have issues with the state of your cec devices, you can add this to manually define the hdmi port of the device
volumeEnabled No Exposes a bulb to HomeKit to control TV volume (Default: true)
maxVolume No Max adjustable volume (Default: 35)
appsEnabled No Exposes App Service to HomeKit (Default: true, not compatible with Apple Home app)
homeapp No URI of an installed app on the TV
channelsEnabled No Exposes Channel Service to HomeKit (Default: false, not compatible with Apple Home app)
channelSource No Source type (tv:dvbt , tv:dvbc) (Default: tv:dvbt)
favChannel No URI from the favourite channel
remoteControl No Exposes remote control to HomeKit (Default: false, not compatible with Apple Home app)
controlMode No choose between "BASIC" or "ADVANCED" or "OFF" to create your own remote control (Default: "BASIC")
offState No choose between "HOME", "CHANNEL" or "OFF" to create your own off state command (Default: "HOME")

Supported clients

This platform and the switches it creates have been verified to work with the following apps on iOS 11.2.5:

  • Apple Home (no App/Channel controlling)
  • Elgato Eve

Known issues | TODO

  • ISSUE: At the moment it is not possible to deactivate a CEC device or shutting it down, this plugin activates the option setted in config.json instead (offState > "HOME" for Home App, "CHANNEL" for Channels and "OFF" for turning TV off)

  • TODO: create option to expose other Inputs like Scart, Composite, Screen mirroring

  • TODO: Bulb for volume up/down

  • TODO: Service to switch between apps

  • TODO: Better error handling

  • TODO: Service to switch between Channels

  • TODO: Better, faster and easier

  • TODO: Adding cache function

  • TODO: New option: offState

  • TODO: New function: Remote Control

Contributing

You can contribute to this homebridge plugin in following ways:

  • Report issues and help verify fixes as they are checked in.
  • Review the source code changes.
  • Contribute bug fixes.
  • Contribute changes to extend the capabilities

Pull requests are accepted.

homebridge-sonybravia-platform's People

Contributors

seydx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

homebridge-sonybravia-platform's Issues

Plugin doesn't allow homebridge to launch while TV is off

It seems that getting the app list on my Sony requires it to be awake. I've set the always-on IP mode on the TV, and the plugin is able to turn the TV on while it's off. In spite of that, if I launch homebridge while the TV is off, it gets stuck looking for apps. I have Sony model KDL40W600B.

It just prints this in a loop:
[2018-3-23 04:31:48] [Sony] Sony: TypeError: Cannot read property '0' of undefined - Trying again
[2018-3-23 04:31:58] [Sony] Getting apps...
[2018-3-23 04:31:58] [Sony] Sony: TypeError: Cannot read property '0' of undefined - Trying again

ATV has port, but no logical address, doesn't work with current implementation

I'm not sure how to enter this, whenever I choose a random port number I see the app runaway wildly turning it on in a loop.

Command output:
{
"connection": true,
"icon": "meta:playbackdevice",
"label": "Apple TV",
"title": "Player 1",
"uri": "extInput:cec?type=player&port=1"
},

My config:
"cecs": [{
"label": "Apple TV",
"logaddr": 0,
"port": 1
}]

The result:
[2018-3-23 03:28:06] [Sony] Turning on the TV...
[2018-3-23 03:28:07] [Sony] Turning on the TV...
[2018-3-23 03:28:07] [Sony] Turning on the TV...
[2018-3-23 03:28:07] [Sony] Turning on the TV...
[2018-3-23 03:28:08] [Sony] Turning on the TV...
[2018-3-23 03:28:08] [Sony] Turning on the TV...
[2018-3-23 03:28:09] [Sony] Turning on the TV...
[2018-3-23 03:28:09] [Sony] Turning on the TV...
[2018-3-23 03:28:09] [Sony] Turning on the TV...
[2018-3-23 03:28:10] [Sony] Turning on the TV...
[2018-3-23 03:28:10] [Sony] Turning on the TV...
[2018-3-23 03:28:10] [Sony] Turning on the TV...
[2018-3-23 03:28:10] [Sony] Turning on the TV...
[2018-3-23 03:28:10] [Sony] Turning on the TV...
[2018-3-23 03:28:10] [Sony] Turning on the TV...
[2018-3-23 03:28:11] [Sony] Turning on the TV...
[2018-3-23 03:28:11] [Sony] Turning on the TV...
[2018-3-23 03:28:11] [Sony] Turning on the TV...
[2018-3-23 03:28:11] [Sony] Turning on the TV...
[2018-3-23 03:28:11] [Sony] Turning on the TV...
[2018-3-23 03:28:12] [Sony] Turning on the TV...
[2018-3-23 03:28:12] [Sony] Turning on the TV...
[2018-3-23 03:28:12] [Sony] Turning on the TV...
[2018-3-23 03:28:12] [Sony] Turning on the TV...
[2018-3-23 03:28:12] [Sony] Turning on the TV...
[2018-3-23 03:28:13] [Sony] Turning on the TV...
[2018-3-23 03:28:13] [Sony] Turning on the TV...
[2018-3-23 03:28:13] [Sony] Turning on the TV...
[2018-3-23 03:28:13] [Sony] Turning on the TV...

With the television completely turned off, Homebridge does not work well

With the television completely turned off, Homebridge does not work well, that is, if for whatever reason I decide to turn it off completely from the power socket then Hombridge appears not working, all the Home App buttons do not work. Why is this happening? If I go on a trip and I want to turn off the TV, I can't since then I don't have access to anything
CopyQ RVcWnz

Controlling volume with soundbar

On most recent version of plugin. Everything had been working just fine including volume control. Recently added a Sony soundbar to the TV and now when I try to change the volume in HomeKit I see the volume pop up on tv displaying the current volume but no changes occur. Homebridge terminal shows volume request with correct requested volume.

HomeKit support

Now that HomeBridge has been updated to support tv services, can this be added to this Plugin?

Siri understands power commands only a couple of times after restarting homebridge

I have a strange issue, related only to this plugin so far. I have named the platform "TV". Powering on and off via Siri voice commands works only 1 or 2 times, after that Siri's response is "Hmm.. I can't do that with Homekit because I'm not sure what you mean by TV".

I have tried other names: Sony, Sony Bravia, etc. Always the same result, the voice command work only the first one or two times, after that they don't. From Home app (or Elgato Eve) everything works, only the voice commands do not work. The problem is both with this and the dynamic version of plugin.

I tried also other Bravia plugin (https://www.npmjs.com/package/homebridge-bravia), and with that there's no issue: Power on and off command works fine.

Funny thing is that voice commands for volume do work permanently, telling "Hey Siri, TV Volume 15" sets it every time to whichever value you want. Only the power commands fail.

Help

Im having this problem when running homebridge.

Any help would be appreciated

[2/13/2018, 8:47:13 PM] [Sony Bravia] Initializing SonyBravia platform...
/usr/local/lib/node_modules/homebridge-sonybravia-platform/index.js:756
this.tvSwitch = self.tvSwitch;
^

ReferenceError: self is not defined
at new TVSwitchAccessory (/usr/local/lib/node_modules/homebridge-sonybravia-platform/index.js:756:21)
at async.waterfall.reqApps.token (/usr/local/lib/node_modules/homebridge-sonybravia-platform/index.js:131:36)
at nextTask (/usr/local/lib/node_modules/homebridge-sonybravia-platform/node_modules/async/dist/async.js:5310:14)
at Object.waterfall (/usr/local/lib/node_modules/homebridge-sonybravia-platform/node_modules/async/dist/async.js:5320:5)
at Object.accessories (/usr/local/lib/node_modules/homebridge-sonybravia-platform/index.js:117:12)
at Server._loadPlatformAccessories (/usr/local/lib/node_modules/homebridge/lib/server.js:364:20)
at Server._loadPlatforms (/usr/local/lib/node_modules/homebridge/lib/server.js:308:16)
at Server.run (/usr/local/lib/node_modules/homebridge/lib/server.js:85:36)
at module.exports (/usr/local/lib/node_modules/homebridge/lib/cli.js:40:10)
at Object. (/usr/local/lib/node_modules/homebridge/bin/homebridge:17:22)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:393:7)
at startup (bootstrap_node.js:150:9)
at bootstrap_node.js:508:3

Cannot control volume

Everything works great except the volume controller, the volume bar just appear when I adjust the bulb in home app, but it does not actually control the volume. I have no idea how to fix it..help..
Great plugin, thanks!

Remote says "this accessory is not currently supported by the home app"

Hello,
Thanks for this plugin. Very useful!
All of it works great in iOS 13.3 except the remote.
In Home App I currently get an error message:
"this accessory is not currently supported by the home app"
Is this a known issue? Is there a fix or workaround?

I have no other remotes than Apple TV working in Home App but I have one more remote working in Control center via the JSON config in Homebridge.
Grateful for any comment? Many thanks.

Volume slider should show proper % when maxVolume is set

The lightbulb brightness in the app is 100% always, regardless of what maxVolume is set to in config.json. You should override the max brightness to the maxVolume value so that you get both a smaller range / more control in the slider, and an accurate number displayed in the app.

Volume controller

Hello,
Just installed the latest version and updated the config.json, volume controller still does not work.
the config.json:

{
    "bridge": {
        "name": "Homebridge",
        "username": "02:42:81:B2:65:96",
        "port": 51826,
        "pin": "031-45-154"
    },

    "description": "This is an example configuration file. You can use this as a template for creating your own configuration file containing devices you actually own.",

    "accessories": [],

    "platforms": [
        {
        "platform": "HomeAssistant",
        "name": "HomeAssistant",
        "host": "http://127.0.0.1:8123",
        "password": "",
        "supported_types": ["automation", "binary_sensor", "climate", "cover", "device_tracker", "fan", "group", "input_boolean", "light", "lock", "media_player", "remote", "scene", "script", "sensor", "switch", "vacuum"],
        "default_visibility": "hidden",
        "logging": true,
        "verify_ssl": false
        },
        {
            "platform": "config",
            "name": "Config",
            "port": 8080,
            "sudo": false
        },
        {
        "platform":"SonyBravia", 
        "name":"Sony",
        "ipadress":"192.168.2.180",
        "psk":"1234",
        "interval": 5,
        "maxVolume":60,
        "extraInputs":false,
        "volumeEnabled": true,
        "appsEnabled": false,
        "channelsEnabled":false,
        "homeapp":"com.sony.dtv.com.wasu.wasutvcs.com.wasu.wasutvcs.activity.AuthActivity",
        "cecs":
        [
            {
                "label":"PlayStation 4",
                "logaddr":8,
                "port":1
            }
        ]
        }
    ]
}

When adjust the volume in homekit log shows:

[2018-3-23 14:03:12] [Sony] Volume: 27
[2018-3-23 14:03:12] [Sony] Volume: 19
[2018-3-23 14:03:20] [HomeAssistant] Received event: ping
[2018-3-23 14:03:23] [Sony] Volume: 31

but TV volume does not change.

Can turning off an input/CEC turn off the TV?

I like how I can turn on both the TV and Apple TV with one switch now (The Apple TV CEC). It'd then be great to also turn off the whole setup with the same switch.

For this to be possible, we'd need to pick between launching a home app on close, or sending the off command. Perhaps there could be a setting in the config to control it?

HDMI arc

Volume control don’t work when sound bar is selectioned.

v2.3 can get stuck on launch

In v2.3 I started seeing this, it's happened twice so far and I have to wait, or remove my cachedAccessories to resolve it.

It hit it after trying to use the new CEC feature, then launching homebridge while the TV was off. I'm attempting to turn to the CEC while the TV is off, and it crashes. After that, sometimes, on subsequent launches of homebridge I'll hit this issue.

[2018-3-25 22:07:24] [Sony] { Error: connect ECONNREFUSED 192.168.0.18:80
    at Object.exports._errnoException (util.js:1024:11)
    at exports._exceptionWithHostPort (util.js:1047:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1150:14)
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '192.168.0.18',
  port: 80 }
[2018-3-25 22:07:34] [Sony] Getting apps...
[2018-3-25 22:07:34] [Sony] Error: Failed to load data, status code: 404
    at ClientRequest.<anonymous> (/Users/elp/.nvm/versions/node/v7.6.0/lib/node_modules/homebridge-sonybravia-platform/index.js:104:28)
    at Object.onceWrapper (events.js:316:30)
    at emitOne (events.js:115:13)
    at ClientRequest.emit (events.js:210:7)
    at HTTPParser.parserOnIncomingClient (_http_client.js:565:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:116:23)
    at Socket.socketOnData (_http_client.js:454:20)
    at emitOne (events.js:115:13)
    at Socket.emit (events.js:210:7)
    at addChunk (_stream_readable.js:252:12)
[2018-3-25 22:07:44] [Sony] Getting apps...
[2018-3-25 22:07:44] [Sony] Error: Failed to load data, status code: 404
    at ClientRequest.<anonymous> (/Users/elp/.nvm/versions/node/v7.6.0/lib/node_modules/homebridge-sonybravia-platform/index.js:104:28)
    at Object.onceWrapper (events.js:316:30)
    at emitOne (events.js:115:13)
    at ClientRequest.emit (events.js:210:7)
    at HTTPParser.parserOnIncomingClient (_http_client.js:565:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:116:23)
    at Socket.socketOnData (_http_client.js:454:20)
    at emitOne (events.js:115:13)
    at Socket.emit (events.js:210:7)
    at addChunk (_stream_readable.js:252:12)
[2018-3-25 22:07:54] [Sony] Getting apps...

Plug-in not working: Port issue?

I installed the Bravia plugin, and configured the config file. I started off slowly only activating the Power and Volume, but neither are working. I changed the port to be 194 and even set up port forwarding on my router to point to the TV ip address. Any thoughts why it's not working?

{
"platform": "BraviaTV",
"name": "TV",
"ipadress": "192.168.7.98",
"port": 194,
"psk": "XXXX",
"tvEnabled": true,
"volumeEnabled": false,
"inputsEnabled": false,
"detectCEC": false,
"extraInputs": false,
"appsEnabled": false,
"channelsEnabled": false,
"remoteControl": false
}

Switching to TV

Hello, I have installed the plugin 1 week ago, however after switching to adifferent channel like AppleTV i can switch back to TV... what do I wrong

Enhancement: Allow setting of Home App with Apps service

The app service is a nice way to open apps, and it displays both the current and home app, but it'd be cool if it also allowed setting of the home app. All it would need is one more toggle, I suppose this would mandate that it's not set it the config file as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.