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

About: I like to combine electronics like Arduino's, ESP8266 etc with 3D designing and 3D printing.

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.

Step 1: Hardware

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


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


- 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

Step 2: The Software and Openhab

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?