Sunday, April 02, 2017

Alexa Turn On / Off TV


I have a Samsung LED smart TV. The "smart" TV let's you turn off the TV, but it doesn't let you turn it on as the IP address is not available when it's off.

That sort of makes sense.

While it is possible to then download a command to turn off the TV. you will need to go through the TV settings to enable HDMI-CEC. This means that turning on the apple TV for example will in turn turn on the TV and set the channel to Apple TV.


What you need.

1. Domoticz
2. iSamsung command (https://www.domoticz.com/wiki/Samsung_TV)
3. atvremote command (i took this from homeassistant)


Use Domoticz to create a dummy device and add a virtual selector device.




There are 4 buttons I programmed and here are the corresponding commands.

if your TV has the IP address 192.168.1.x (Replace x with the actual IP address of the TV)

To turn the TV off
script:///usr/local/bin/iSamsungTV 192.168.1.x -KEY KEY_POWEROFF

To use Apple TV to turn on the TV to Apple TV channel
script:///srv/homeassistant/bin/atvremote -a menu

To change the channel another HDMI input
script:///usr/local/bin/iSamsungTV 192.168.1.x -KEY KEY_HDMI

To change the channel to COMPONENT input
script:///usr/local/bin/iSamsungTV 192.168.1.x -KEY KEY_COMPONENT1


Now that we have Domoticz working, we need to add the buttons to ha-bridge for Alexa commands

For Domotics IP 192.168.1.y (Replace y) and switch ID is NN (Replace NN with the actual switch ID

To turn on the TV
http://192.168.1.y:8080/json.htm?type=command&param=switchlight&idx=NN&switchcmd=Set%20Level&level=10


to turn off the TV
http://192.168.1.y:8080/json.htm?type=command&param=switchlight&idx=NN&switchcmd=Set%20Level&level=0


To change the channel, we can create another ha-bridge device and just leave the turn on button for HDMI and Cable TV, respectively

http://192.168.1.y:8080/json.htm?type=command&param=switchlight&idx=NN&switchcmd=Set%20Level&level=20
http://192.168.1.y:8080/json.htm?type=command&param=switchlight&idx=NN&switchcmd=Set%20Level&level=30



To Use these command with Alexa, you can say this.

Alexa, Turn On TV (Defaults to Apple TV)
Alexa, Turn Off TV
Alexa, Turn On HDMI (does a round robin approach to HDMI surfing
Alexa, Turn On Cable TV (changes the channel to component which is my cable box)




No comments:

Splitting the home network

Who wouldn't want to separate the traffic at home for security reasons. The more common ones include wireless guest and wireless users. ...