Skip to content

Instantly share code, notes, and snippets.

@labmonkey
Last active May 13, 2026 23:18
Show Gist options
  • Select an option

  • Save labmonkey/daf865cbd2537846083fbd4afe780d9b to your computer and use it in GitHub Desktop.

Select an option

Save labmonkey/daf865cbd2537846083fbd4afe780d9b to your computer and use it in GitHub Desktop.
Sony Bravia Android TV -> Turn screen ON/OFF using ADB

Sony Bravia Android TV -> Turn screen ON/OFF using ADB

TLDR

By using this method https://gist.github.com/Ademking/e9141c8336de77c3ea1c390dc666bfaa I've recorded which button is the "PICTURE_OFF" on my remote that simply turns off the screen on Bravia TV and then triggered this from command line.

Story

I could not find any programmatic way to turn off the display of Sony Bravia TV that I could for example script in Home Assistant.

I was thinking that maybe somewhere there is an Android "Activity" which would trigger this via ssh but did not find any. In the end you can turn off Sony Bravia from the "Action Menu" that you can find in your remote (I think this menu is editable so maybe you have to add there this command but mine was there out of the box).

I've started looking further and then found out that if you have an Universal Remote (Such as Flirc Skip 1s which I do not recommend by the way) you can find in the list of all possible BRAVIA commands that it has that there is a "PICTURE OFF" button that turns off the display from the remote. The Standard Sony TV remote that I had did not have such a button at all so an Universal remote is neccessary to trigger this "button".

I found out that you can also record the button press events from the command line, store them in file and then manually send those files/events via adb so that you simulate the button being pressed via CLI. Here https://gist.github.com/Ademking/e9141c8336de77c3ea1c390dc666bfaa you can find how to do it.

Solution

  1. Record the PICTURE_OFF event into a file the way descibed above or download the one that I've provided. Please note that this is a binary file with some "random" content but your TV will understand it. I cannot guarantee that the file I provided will work because maybe its different between systems or TVs - I have no idea and you have to check that yourself.
  2. I've noticed that when TV is turned off the current window name reported is "com.sony.dtv.sonysystemservice". So now we know how to check the display state and how to turn it off.

Having those two I can execute below command that turns off the screen in case its not off.

dumpsys window windows | grep mCurrentFocus | grep com.sony.dtv.sonysystemservice && echo "Screen is OFF" || cat /mnt/sdcard/input_picture_off > /dev/input/event0

Note that this command is triggered via adb shell. Either with proper Home Assistant plugin or when you manually ssh into the TV yourself. The input_picture_off file was also recorded via adb shell and is located in the TV itself in any writable location you like.

@luiscamalmeida

Copy link
Copy Markdown

Hi @ogakul.
It's my last resort. The problem with that approach is that if anyone uses the quick settings (to change color mode or sound output for example) the script will execute random actions. So far I've tried to decompile sony's apk and search the code for a way to invoke this action. It's a shame the intent we need is protected and can only be called by a system apk.

@luiscamalmeida

Copy link
Copy Markdown

@ogakul using this method you can send the command "PictureOff" and it will solve the need to use the action menu.

@labmonkey

Copy link
Copy Markdown
Author

Honestly I have no idea why I could send commands to /dev/input/event0 and in your case it is not possible. This method definitely works because I use it with my automation. Sadly I cannot help here.

@ogakul

ogakul commented Mar 10, 2024

Copy link
Copy Markdown

@ogakul using this method you can send the command "PictureOff" and it will solve the need to use the action menu.

Thanks works great!

@dontwan

dontwan commented Nov 11, 2025

Copy link
Copy Markdown

I found a way to turn off the picture / screen by using the “REST API” feature. This will open additional doors for more opportunities.
Documentation can be found here: https://pro-bravia.sony.net/develop/integrate/rest-api/spec/index.html

  1. On your television, set Settings -> Network and Internet -> Home network setup -> Authentication -> Normal and PreShared Key and set your PSK key.

  2. In Home Assistant, add the following code to your configuration.yaml:

rest_command:
  sony_tv_picture_off:
    url: "http://192.168.1.5/sony/system" # change it to your television IP address
    method: POST
    headers:
      X-Auth-PSK: "secret" # change it to your PSK key
      Content-Type: "application/json"
    payload: >
      {
        "id": 1,
        "version": "1.0",
        "method": "setPowerSavingMode",
        "params": [{"mode": "pictureOff"}]
      }
  1. ⚠️Important step: completely restart your Home Assistant! (somehow there is an bug that doesn't apply the rest_command when only reloading the YAML files)

  2. In your automation use:

actions:
  - action: rest_command.sony_tv_picture_off

Bonus
I'm using the TP-Link router addon which has the device_tracker entity.
By using state_attr('device_tracker.sony_tv', 'ip') I can dynamically fetch the IP address of my television.
"http://{{ state_attr('device_tracker.sony_tv', 'ip') }}/sony/system

@electrocamuk

Copy link
Copy Markdown

Would love this to work on a Panasonic android TV but alas, it returns a "RemoteKeyCode has no value defined" error :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment