Basic Sony TV switch on or Off using HDMI-CEC

Install needed package:

1sudo apt install cec-utils

Check connected devices

 1pi@raspberrypi:~ $ echo 'scan' | cec-client -s -d 1
 2opening a connection to the CEC adapter...
 3requesting CEC bus information ...
 4CEC bus information
 5===================
 6device #0: TV
 7address:       0.0.0.0
 8active source: no
 9vendor:        Sony
10osd string:    TV
11CEC version:   1.4
12power status:  on
13language:      eng
14
15
16device #1: Recorder 1
17address:       3.0.0.0
18active source: no
19vendor:        Pulse Eight
20osd string:    CECTester
21CEC version:   1.4
22power status:  on
23language:      eng
...

From the above, the Sony TV has address 0.0.0.0.

Turn-on:

1echo 'on 0.0.0.0' | cec-client -s d 1

Turn-off:

1echo 'standby 0.0.0.0' | cec-client -s d 1

Get status:

1echo 'pow 0.0.0.0' | cec-client -s d 1

Explore:

1echo 'h' | cec-client -s -d 1

See details in https://pimylifeup.com/raspberrypi-hdmi-cec/