Control Your TV Via Google Home or Alexa Via Openhab and MQTT, ESP8266, Web Interface

by Wim3d in Circuits > Wireless

12491 Views, 23 Favorites, 0 Comments

Control Your TV Via Google Home or Alexa Via Openhab and MQTT, ESP8266, Web Interface

TV wifi controller.png

My Google Home Mini can stream Youtube etc on my TV, but was not able to switch on my TV. I solved this by this small device which receives commands via MQTT and sends IR signals to my TV.

The principle scheme is shown in the picture.

I attached a 18B20 temperature sensor for my home automation, it is not mandatory.

Hardware

IMG_20190204_220107.jpg
Schematic_TV-controller_Sheet-1_20190210130331.png
IMG_20190204_215352.jpg
IMG_20190204_215300.jpg
IMG_20190204_215242.jpg
IMG_20190204_215343.jpg
IMG_20190204_202453.jpg
IMG_20190204_205655.jpg

In this section I decribe the hardware. The module is powered by a 5V phone charger.

Components:

- ESP8266 (I used ESP-01 for its small size)

- IR LED

- Resistors (1K and 10K, 4.7K for the 18B20)

- Transistor to control the IR led (I used 2N2222)

- Voltage regulator (5V to 3.3V, I used XC6206)

- Capacitors for the voltage regulator (0.1 and 10 UF)

The electric scheme is attached. I made a compact module to fit in a small box.

The 18B20 was finally sealed in a heat shrink tube

The Software and Openhab

Website.png

The program is on my Github.

The Google Home Openhab integration is described here.

The module publishes a website via which you can control the module and read the temperature see the picture.

I use 3 MQTT topics for the communication:

power_topic = "SonyTV/power" 
volumeup_topic = "SonyTV/volup"
volumedown_topic = "SonyTV/voldown"

You can find the IR codes online for your brand. I found the Sony TV codes here.

My Openhab items file:

Switch powerSony "Sony TV Power"  [ "Switchable" ] {mqtt=">[mosquitto:SonyTV/power:command:*:default],<[mosquitto:SonyTV/power:state:default]"}
Switch powerSony2 "Sony TV Power2" [ "Switchable" ] {mqtt=">[mosquitto:SonyTV/power:command:*:default],<[mosquitto:SonyTV/power:state:default]"} Switch powerSony3 "Sony TV Power3" [ "Switchable" ] {mqtt=">[mosquitto:SonyTV/power:command:*:default],<[mosquitto:SonyTV/power:state:default]"} Switch volumeupSony"Sony TV Volume Up" [ "Switchable" ] {mqtt=">[mosquitto:SonyTV/volup:command:*:default],<[mosquitto:SonyTV/volup:state:default]"} Switch volumedownSony "Sony TV Volume Down" [ "Switchable" ] {mqtt=">[mosquitto:SonyTV/voldown:command:*:default],<[mosquitto:SonyTV/voldown:state:default]"}

Note: I use 3 different switches for the power, this is not mandatory of course. In Google Home they have aliases: "Sony TV", "My television" and "television".

My Sony TV only has a power toggle code, so 'power on' and 'power off' are the same. Therefore 'Google Home' does not know whether the TV is on or off. Anyone has a solution for this?