If you want to switch off and on a ( in my case Samsung) tv via home automation, chances are that you run into several issues. It's not an straightforward task, also since WOL is not supported by Samsung (2015 tv).
Please find below a step by step guide to, which enables you to switch off and on the tv via a Domoticz virtual switch. In addition, the switch follows closely the state of the tv, so the button is off when the tv is off, even when you have used the rc to switch off the tv.
There are several solution that could or will work;
a. Use a Logitech Harmony Hub. I didn't want to go this way, given that you need to place a infrared sensor somewhere in the neighborhood of the tv. In addition my samsung remote control uses RF, and I read somewhere that the HH can't send and receive RF at the same time. So the HH solution is a no go for me.
b. I use a raspberry 3 with OSMC (based on Kodi) as a mediaplayer. And since the pi supports CEC you could via CEC, by issuing "echo "standby 0" | cec-client -s -d 1 and echo "on 0" | cec-client -s -d 1" switch off and on a tv that also supports CEC. The problem with this solution is that by issuing the before mentioned command the CEC connection between the OSMC and the tv is disconnected, which results that you can no longer use the tv remote control to use the OSMC media player. Therefore using the Pi OSMC CEC solution is a no go.
c. then the logical solution is to connect a separate pi (in my case an old Pi 2) to the tv, just for CEC support. This is the solution that I prefer, and the step by step guide is available below;
# Setup the pi (Based on Strech version April 2019)
1. Update the Pi to the latest and reboot (new firmware and dbus daemon)
Code: Select all
sudo apt-get update
sudo apt-get upgrade
sudo reboot
Code: Select all
sudo curl -L install.domoticz.com | bash
error while loading shared libraries: libssl.so.1.0.0: cannot open shared object file: No such file or directory problem
https://www.domoticz.com/forum/viewtopi ... 2&start=40
b. Install some required components
Code: Select all
sudo apt-get install cmake libudev-dev libxrandr-dev python-dev swig
Following is copied from https://github.com/home-assistant/hassb ... /issues/38 (@john-ruddy)
Code: Select all
cd
git clone https://github.com/Pulse-Eight/platform.git
mkdir platform/build
cd platform/build
cmake ..
make
sudo make install
Code: Select all
cd
git clone https://github.com/Pulse-Eight/libcec.git
mkdir libcec/build
cd libcec/build
cmake -DRPI_INCLUDE_DIR=/opt/vc/include -DRPI_LIB_DIR=/opt/vc/lib ..
make -j4
sudo make install
sudo ldconfig
Code: Select all
cec-client -l
Code: Select all
libCEC version: 4.0.4, git revision: libcec-4.0.4+1-ba9b538, compiled on Thu 11 Apr 22:35:24 UTC 2019 by pi@cec-pi on Linux 4.14.98-v7+ (armv7l), features: P8_USB, DRM, P8_detect, randr, RPi
Found devices: 1
device: 1
com port: RPI
vendor id: 2708
product id: 1001
firmware version: 1
type: Raspberry Pi
2. Setup the Domoticz config on the CEC pi
a. Create a dummy switch on the CEC pi.
b. create 2 python scripts and install those in the scripts/python directory. Also make both scripts executable, with sudo chmod +x filename.py
File 1 tv on
-------
#!/usr/bin/python3
import os
os.system("date")
os.system('echo "on 0" | cec-client -s -d 1')
--------------------
File 2 tv off
-------
#!/usr/bin/python3
import os
os.system("date")
os.system('echo "standby 0" | cec-client -s -d 1')
--------------------
c. Link the scripts with the switch via:
On action: script:///home/pi/domoticz/scripts/python/tv_woonkamer_on.py
Off action: script:///home/pi/domoticz/scripts/python/tv_woonkamer_off.py
d. the cec pi is now done. Also write down the idx number of the dummy switch, mine is 1.
3. Create a system alive check checker (add via hardware in Domoticz: System Alive Checker) on the main Domoticz installation (production environment in my case)
The ping should be directed to the ip address of the tv, with a timeout of 30 sec. To check if the tv is on or off.
4. Create a dummy switch e.g TV Woonkamer.
5. Create a dummy switch e.g TV Woonkamer.tv.script attached
6. Link the on and off actions ( via JSON), of the TV woonkamer switch to the TV Woonkamer.tv.script attached
switch
http://ip 1:8080/json.htm?type=command¶m=switchlight&idx=95&switchcmd=On
http://ip 1:8080/json.htm?type=command¶m=switchlight&idx=95&switchcmd=Off
7. Make the system alive checker device slave (wk.tv.local system alive) of the TV Woonkamer switch.
8. Link the on and off actions ( via JSON) of the TV Woonkamer.tv.script attached switch to the switch on the CEC pi
http://ip 2:8080/json.htm?type=command¶m=switchlight&idx=1&switchcmd=On
http://ip 2:8080/json.htm?type=command¶m=switchlight&idx=1&switchcmd=Off
That's it. I have it working now for a few weeks and it's rock stable.