Alexa IoT TV-Controller ESP8266

by idIoT3D in Circuits > Wireless

3847 Views, 33 Favorites, 0 Comments

Alexa IoT TV-Controller ESP8266

IMG_3023.JPG
IMG_3034.JPEG
IMG_3035.jpeg

Recently I bought an Amazon Echo Dot during the Amazon Prime day for ~20€.

These small voice assistants are cheap and great for DIY Home Automation if you know what is possible and how to build smart devices.

I have an Samsung Smart TV but I wanted to make it even smarter. In this Instructable I will show you how to build a Controller for your TV to control it wirelessly using your voice. Some possible and useful commands could be:

  • Turn On/Off the TV
  • Volume Settings (Up/Down/Mute)
  • Switch to another source (HDMI Port, TV, etc...)
  • Turn on Netflix/Amazon Prime/YouTube...

In case your TV has an USB-Port that is always-on you have the jackpot! If not, you can use a a loong USB-cable or a small Power Regulator Board that steps down any voltage between 12.5 and 16V down to 5V. I used this because I already had a 12V power supply directly beneath at my bed for some LED-Strips :)

Another way and thats why I participate in the Battery-Challenge, is that my designed 3D-printed housing has the space for a 150mAh LiPo Battery and Charger Board. So you can keep it completely wirelessly!

Unfortunately though I have no pictures of it because my iPhone died during an iOs-Update and the photos were not uploaded to my iCloud :(

So the provided pictures are only without the battery inside, which I connected after the final assembly...

However, if you want to build your own Controller, here is what you need:

Supplies

  • Further:

To build this project you need an system running the freeware "ioBroker". This is a free MQTT-Broker that allows the ESP8266 to connect to it and share it's data. ioBroker also has an Alexa-Adapter, which we can use to make our ESP wirelessly communicate to Alexa.

I run ioBroker on an old Laptop-Motherboard - but for small automations, a Raspberry-Pi would be enough to run it. You can download ioBroker on its official website here:https://www.iobroker.net/

You also need the Tasmota-Firmware! You can download it here: https://github.com/arendst/Tasmota/releases

-->Choose your language!

If you want to use it with Alexa, you need to know what a physical Alexa device is needed! The Alexa-App doesn't work! Alexa-Connectivity is only optional - you also can switch your TV on by pressing a small MQTT-button like this one: https://www.youtube.com/watch?v=ImVK5cGVrpQ

Program the ESP8266

IMG_3037.JPG

Because we are going to solder the ESP8266 to the PCB later, we have to program it first. To do this, I recommend you to use a cheap Programmer board - The one I used is not recommended! I had do modify it to make it work so check out the link on the top (see: Supplies).

At first plug the ESP into the programmer. Then start the Flash-Tool on your Computer. Now plug in the Programmer via USB and press the FLASH-Button on the PCB during plugging it in. Release it after a few seconds. Now there should be shown a COM-Port in the Program-Tool. Select it and continue by selecting the Tasmota-Firmware. Baud-Rate should be at 115.000 and Mode QIO selected.
When done, click on the Flash-Button on the Tool. Now the programmer starts.

When done, it will say DONE.

Now you can remove the Programmer from your PC and put it back in after you switched the programmer to UART-Mode (the switch on the PCB).

Setup Your ESP - WiFi

Step 3 1 Wifi Settings.png

Now that the ESP is programmed and plugged into your computer in UART-Mode, go to the wifi-settings of your device and search for a network which contains "tasmota" in the SSID (e.g. "Tasmota-31278D"). Connect to it, go to your browser and go to 192.168.4.1.

In the following I explain what you have to do in the setup:

Wifi Settings:

  • WLAN1:
    • SSID of your Wifi-Router
    • Password of your Wifi-Router
  • WLAN2:
    • SSID of your (second) Router (optional)
    • Password of your (second) Router (optional)
  • Hostname: The name which is shown in the network - I recommend "TV-Remote"

Confirm your settings by clicking "Save" (green Button). Now the ESP tries to connect to your WiFi network.

If this process fails, the ESP will open it's own Tasmota-Wifi-Network again.

Setup Your ESP - Module Config

Step 3 2 Module.png

When your ESP connected to your home network succesfully, you have to search for it's IP-Address in your Router-Menu.

Type in the Adress into your browser. The tasmota page of the ESP will be shown. Now navigate to Settings --> Configure Module and select "Generic (18)".

When done, search in the Drop-Down-Menu of GPIO-2 for IRsend (8) and select it.

Press Save!

Setup Your ESP - MQTT

Step 3 3 MQTT.png

The ESP needs to connect to our MQTT-Broker (ioBroker). We can configure the MQTT-settings on the tab Settings-->Configure MQTT. There you have to enter your Broker-IP, the Broker-Port, MQTT-User (if you dont know it you can find it at your MQTT-Adapter settings on ioBroker!). Furthermore you need to type in the MQTT-Password, the Client-Name (how the device is shown in ioBroker) and a topic. The topic is the name of the folder in iobroker. If you want to use more MQTT-devices, I recommend to declare full topics like livingroom/%topic% or kitchen/%topic%. But you dont need to do that but it will help you later when you have a lot devices connected to your Broker!

Dont forget to save everything afterwards! :)

And thats it! The ESP is ready to use now!

Setup Your IoBroker

Step 4 ioBroker MQTT.png

Now that the ESP is ready to use, we have to setup the MQTT-Broker- and optional the Alexa-Adapter.

Go to your ioBroker-webpage (ip-adress + port (8081) like 192.168.178.188:8081 in my case).

Navigate to "Adapters" and search for "MQTT Broker/Client" and "Alexa2".

The MQTT-Adapter is needed, Alexa is optional.

I recommend to start with the MQTT-Adapter. After installation a window will open where you have to setup your Broker.

Select the options as shown in the picture.

You can choose MQTT-User and password as you like!

As always, don't forget to save your settings (left bottom corner).

Testing MQTT-Connection

Step 4 MQTT.png

To test the connection from the ESP to broker, you need to remove the ESP from your PC and plug it back in with selected normal Startup-Mode again.

Wait a few seconds and check the status of your iobroker page "instances" and look at the "light"-symbol of the MQTT-Adapter. If your ESP is listed there, it connected succesfully!

The MQTT-folders will automatically appear on the "Objects" page!

Create MQTT-variable

Step 5 Create Variable.png
Screenshot (20).png

Navigate to the "Objects"-Tab of ioBroker.

Open the folder mqtt.0/YourTopic/cmnd.

Inside of this cmnd (command) folder, you have to create a new datapoint. You can do this by clicking on the + (plus)-Symbol on the top.

Name: IRsend

type: Datapoint

datapointtype: string

Btw sorry that the shown image content is in german, but I don't know how to switch to english for this instructable :/

Soldering and Printing

Unbenannt.png
IMG_3022.JPG
IMG_3021.JPG
IMG_3023.JPG
IMG_3031.JPEG

Software is done - soldering next!

The PCB should be in a circular shape with a 50mm diameter.

Solder everything together like shown in the included schematic. Make sure you dont connect the IR-Emitter reversed! Maybe the LED wont survive that.

I used small 2-pin-connectors for the IR-LED, Switch and the Micro-USB-Power-Board. If you want to do that too, make sure you mark your + and - connections on the side of the connector. The switch orientation doesnt matter!

If you have a 3d-Printer at hand, you can use my provided files - It is a basic 3cm thick case which fits all the components nicely!

Even a small battery and charging board fit inside!

I printed it with my Anycubic I3-Mega and Black Anycubic Filament :)

I glued the PCB, IR-LED, Switch and USB-Port inside using hotglue. Furthermore I sticked the case behind my TV with some double-sided tape. Works good!

To start the device now, you need to push the Button during plugging it in for a few seconds. The switch disconnects the IR-LED from GPIO-2 when pressed that the ESP can start up. Tasmota only supports GPIO-2 and GPIO-0 on the ESP-01 for the IRSender so I needed to do it this way. Release the button after ca. 5 seconds...

Automation Time :)

Step 6 Scripts.png

Now everything hardware-based is finished.

Automation-Software now :)

To make some cool automations, we need to download the Adapter "Scripts" in ioBroker. After you installed it, there will pop up a new field on the left side, called "Scripts". Open it and create a new Blockly-Script - this is a way for very simple programming using functional Blocks.

In order to control your TV, you need to know it's IR-Codes. You can easily find them on the internet - search for your Model + IR Codes. I found the codes for my TV online too. But you can easily decode them with an IR-Receiver and an Arduino! If you dont know how to do it, search on Instructables ;)

In my case, the signal to turn the TV on/off is "0xE0E040BF". The variable IRsend which we created earlier is now needed. The provided example program writes the Code into the variable. But before and after IRsend gets set to 0 with some delays. This is very important because the TV otherwise wont do anything.

You need to use this Format for IRsend: {"Protocol":"NEC","Bits":32,"Data":YourIRCode}

The trigger for the TV to turn on could be any variable in your ioBroker. If you want to do it with Alexa, basically create a new Routine in the Alexa-App on your smartphone and call it e.g. "Turn TV on".

You can find this variable in your Alexa-adapter folder on the "Objects"-tab of your ioBroker. This variable needs to be selected as the trigger event on the top of my example script (if-condition).

If you have an smart-TV you can also start for example Netflix, Amazon Prime, YouTube etc.

You have to navigate the TV step by step as you would do it using the remote. Dont forget to set IRsend to 0 between the commands with a small delay. Delays should work with values between 500 and 1000ms. Simply try it out :)

Any Questions? :)

I hope you can understand all the steps it takes to build my Smart-IR-Controller.

If you have any questions, feel free to ask me in the comments :)
Hope you like my project :D

Btw. sorry for my bad english, I'm from germany :p