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.
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.
- 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.
- 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.
@labmonkey can you share the recorded keys? My remote doesn't have a pic off key for me to record.