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

@labmonkey can you share the recorded keys? My remote doesn't have a pic off key for me to record.

@labmonkey

Copy link
Copy Markdown
Author

@luiscamalmeida Its a bit more complicated to be honest. I've updated this readme and added literally the file. Please note that input_picture_off is literally some kind of binary file containing the input event so don't try to make sense of the contents :-)

@luiscamalmeida

Copy link
Copy Markdown

Thans for the file.
Sadly my TV doesn't let me write to /dev/input/event0 so I'll need to figure another way to turn the screen off.

@labmonkey

Copy link
Copy Markdown
Author

Just a note that maybe that "event" endpoint is different for you.

My output for adb shell getevent -pl command contains these lines:

  input props:
    <none>
add device 5: /dev/input/event0
  name:     "mtkinp_ir_events"
  events:
    KEY (0001): KEY_ESC               KEY_1                 KEY_2                 KEY_3
                KEY_4                 KEY_5                 KEY_6                 KEY_7
                KEY_8                 KEY_9                 KEY_0                 KEY_MINUS
                KEY_EQUAL             KEY_BACKSPACE         KEY_TAB               KEY_Q
                KEY_W                 KEY_E                 KEY_R                 KEY_T
                KEY_Y                 KEY_U                 KEY_I                 KEY_O
                KEY_P                 KEY_LEFTBRACE         KEY_RIGHTBRACE        KEY_ENTER
                KEY_LEFTCTRL          KEY_A                 KEY_S                 KEY_D
                KEY_F                 KEY_G                 KEY_H                 KEY_J
                KEY_K                 KEY_L                 KEY_SEMICOLON         KEY_APOSTROPHE
                KEY_GRAVE             KEY_LEFTSHIFT         KEY_BACKSLASH         KEY_Z
                KEY_X                 KEY_C                 KEY_V                 KEY_B
                KEY_N                 KEY_M                 KEY_COMMA             KEY_DOT
                KEY_SLASH             KEY_RIGHTSHIFT        KEY_KPASTERISK        KEY_LEFTALT
                KEY_SPACE             KEY_CAPSLOCK          KEY_F1                KEY_F2
                KEY_F3                KEY_F4                KEY_F5                KEY_F6
                KEY_F7                KEY_F8                KEY_F9                KEY_F10
                KEY_NUMLOCK           KEY_SCROLLLOCK        KEY_KP7               KEY_KP8
                KEY_KP9               KEY_KPMINUS           KEY_KP4               KEY_KP5
                KEY_KP6               KEY_KPPLUS            KEY_KP1               KEY_KP2
                KEY_KP3               KEY_KP0               KEY_KPDOT             0054
                KEY_ZENKAKUHANKAKU    KEY_102ND             KEY_F11               KEY_F12
                KEY_RO                KEY_KATAKANA          KEY_HIRAGANA          KEY_HENKAN
                KEY_KATAKANAHIRAGANA  KEY_MUHENKAN          KEY_KPJPCOMMA         KEY_KPENTER
                KEY_RIGHTCTRL         KEY_KPSLASH           KEY_SYSRQ             KEY_RIGHTALT
                KEY_LINEFEED          KEY_HOME              KEY_UP                KEY_PAGEUP
                KEY_LEFT              KEY_RIGHT             KEY_END               KEY_DOWN
                KEY_PAGEDOWN          KEY_INSERT            KEY_DELETE            KEY_MACRO
... and countless other keys

This is the endpoint you need to send data to. Maybe you have something similar but with different device id.

@ogakul

ogakul commented Mar 8, 2024

Copy link
Copy Markdown

@luiscamalmeida

I tried this method but in my case, it gave me also an "Access denied" when trying to sendcommand to dev/input/event

I solved it by using the remote function in the BraviaTV integration https://www.home-assistant.io/integrations/braviatv/#remote

My TV has a "Screen off" option in the Quick / Action Menu (wrench icon on remote). I placed it in the first position in the Action Menu, then created a HomeAssistant script which does the following:

  1. Call Service: remote.send_command
  • Target: Sony
  • Command: ActionMenu
  1. Delay for 500 milliseconds

  2. Call Service: remote.send_command

  • Target: Sony
  • Command: Confirm

Update: As suggested by @luiscamalmeida this can be done even simpler by just using "PictureOff":

Call Service: remote.send_command
Target: Sony
Command: PictureOff

@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