ESP8266 / NodeMCU / Arduino based TV Remote

alexa
arduino
project_av
project_remotes

(JZst) #1

Using the NodeMCU with the Arduino IDE we can have a simple infrared device in SmartThings. I am using TSAL6100 and TSAL6400 high quality LEDs. The NodeMCU can have either 2 or 3 IR LEDs connected to it in series.

If using 2 IR LEDs, feel free to use the IRremoteESP8266 code sample. In that folder, you will also find wiring pictures for reference. For longer distance like 11-12 feet, I had to remove even the lowest resistor I had which was 27ohms. So no resistor for this wiring technique otherwise the IR distance goes down to 9-10 feet.

For wiring 3 IR LEDs for higher output and using 5 volts. As of IRremoteESP8266 version 2.0 (around July 1st of 2017), the authors of the library granted my feature request and now the signal can be REVERSED and the ground signal will be sent to the pin rather than VCC as done if using 3.3v and as the original library 1.x did. The authors did a great job implementing my feature request. So now, simply change the sendGround variable at the top of the Arduino sketch to change what gets sent to the IR connected pin. That also means that you have to directly connect the positive side of the LEDs to the USB cable’s positive lead and the negative side to the ESP8266 pin so reversed from the wiring of the 2 LED example above. With this wiring technique, I successfully used a 27ohm resistor (or no resistor) and distance didn’t suffer. This was a really powerful signal that didn’t need 100% line-of-sight like the slightly weaker 2 LED layout.

Here is the SmartThings device code for a TVDevice. The only bug I have with it is the fact that Alexa/Echo does not like it when I say “Alexa set the TV Remote to 4” and it should switch to HDMI input #4. This for some reason does not work and I hope somebody smart can help me in fixing that. Dimmers work well with this Alexa/ST range ability but my device for some reason does not. On/off works very well via Alexa. UPDATE: Thanks to @lonelygadget and the recommendation to add the word Light. Now “Alexa set TV remote LIGHT to X%” works great but lately Amazon fixed that word light requirement and now my older Alexa attempts work as well. I have mine set to change TV inputs when setting to zero then you can say “Alexa set the TV remote UP” or “Alexa set the TV remote to 25,50,75 or 100” cycles through my external HDMI input box.

Thanks to my buddy @Casper for posting his IR capable device which got me started with ESP8266/NodeMCU and IR — I haven’t stopped since :slight_smile: This would have been totally foreign to me if he didn’t post his amazingly detailed write-up of his fan IR hack. Before he posted, I have never even used Arduino even as a pro computer nerd of 23 years. I like Linux and used my familiar Raspberry Pi for my GPIO triggering needs like in my other project for triggering relays/garage/gate. The wireless NodeMCU changes the game and comes at a lovely $5 price and no OS to maintain like in the RPi.

Library of many IR code sequences:
http://irdb.tk/find2
http://www.hifi-remote.com/johnsfine/DecodeIR.html





Make a "dumb" fan "smart" using cheapo ESP8266 board controllable via ST (universal IR remote)
Smartthings and RF blaster?
Raspberry Pi with PHP (or Arduino/ESP8266/NodeMCU) to GPIO to Relay to Gate/Garage Trigger
Samsung UN48J6200 television integration
Make a "dumb" fan "smart" using cheapo ESP8266 board controllable via ST (universal IR remote)
(Jason) #2

I think that Amazon recommends not using numbers in s device name


(JZst) #4

You’re right I really had a hard time with Echo accepting devices with numbers or letters like ESP8266 — but it really liked standard English titles like “TV Remote” or “Wireless board” that natural language can easily distinguish.

However, my question is very different. I am able to use Alexa and ask “Alexa set my hallway light to 60” and it will set it to 60. This is a slider/value on the dimmer device. My goal is to use slider/dimmer capability and say “Alexa set my TV Remote to 4” — in essence this should work but the slider in ST works great.

All the best!


(Casper) #5

Very nice, I really want to try it out but I don’t have those LEDs yet.

Saw the pics too, very neat and simple. I wonder if you need to point the LEDs to the TV or just leave them as-is (pointing up) anywhere in the room?


(JZst) #6

They seem to work sideways almost as well as pointed. However, pointed always gets greater range just by a bit. I look at real TV remotes and they always point the rounded top toward the devices as that seems to be most optimal.

You know my offer still stands: if ever in my neighborhood, I got 6 of those TSAL6100’s with your name on them :slight_smile: looks like TSAL6100 and TSAL6400 are very close in quality. As soon as we get out of the cheap consumer grade ones like the Amazon board, they become very powerful. To be fair, the Amazon one does have a resistor which probably stunts its abilities.


(Casper) #7

Thanks again for the offer :slight_smile: , I’m in OC and very lazy to drive to LA haha, maybe I’ll order online and wait for it.

For those Amazon boards you mentioned, I actually ordered a handful of them from a China Ebay store… the range still sucks.


(JZst) #8

Here are the ones I got below, and I definitely understand lazy… hence the HA solutions :slight_smile:

TSAL6400 http://www.ebay.com/itm/141976474171
TSAL6100 http://www.ebay.com/itm/262136736326

Honestly, I barely see a difference to warrant the more expensive ones. They may be a bit better in some respects especially if used w/o a resistor so withstand more current, etc.


(JZst) #10

Yep, that’s why some of the pictures don’t match… sorry about that :slight_smile: figured it out later…

Bottom line, avoid any of these two LED’s since they’re BUILT-IN on the NodeMCU and you don’t want that exact thing that you’re experiencing — blue staying on forever after the first command.

int redLED = LED_BUILTIN; //GPIO16 also D0 also LED_BUILTIN
int blueLED = D4; //GPIO2 also D4

I like using D1 and D2 just because of this. Change the Arduino code accordingly. I will hopefully update the code/drawings soon enough.


(JZst) #12

Updated Arduino code and pictures/wiring/schematics to reflect usage of D2 and avoid D4 & D0 as those are built-in LED’s and actually would steal a little power if used.


(JZst) #14

See this post from me where I do some math and explain along the way. The obvious reason is so that your IR LED doesn’t burn up. Having said that, these aren’t on all the time and if you got a nice TSAL LED then a resistor is not that important unless you truly have the LED on all the time. Also look at any Google hits on wiring IR LED to Arduino, you’ll see that a resistor is kinda expected to be in the circuit and dissipate some excess power.


(Bryce) #15

@JZst Try adding “light” to the end of your device name, “TV Remote Light”. Then test issuing the command “Set TV Remote Light to 4” to see if the dimmer level is appropriately set to 4%. I have found even with lights, if the device name does not inlcude “Light” then dimming commands are troublesome. Conversely, On/Off seems work either way. I have On/Off devices that are actually windows shades. “Turn off Windows” works in all situations except when accidentally saying “Shut” or “Open Windows”.


(JZst) #16

@lonelygadget you are our unicorn :slight_smile: where did you come from with this off the wall solution because it’s indeed the answer I was seeking for the past few months. So the key is not in the name itself — FYI, I renamed it back (made sure to forget device in Alexa app and re-discover for cleanliness on all changes made) and now just saying the word “light” after the TV Remote device name works every time. I had to tweak my ST Groovy code with a line of code as Alexa sends a 1.0 or 4.0 float rather than the integer that my Arduino code looks for. Thanks to you, now I can be even lazier :slight_smile: I hated pulling out the phone to switch to Chromecast to Fire Stick. Awesome feedback for all of us to benefit from and much appreciated!!! You officially earned the “smarter than me” badge from my orig post :slight_smile:

BTW, one minor issue is that Alexa doesn’t like value over 100. My range in the ST code is 1-4 but Alexa did accept 100 yet complained at anything higher quoting that it’s outside of the device’s range. What this limitation means is lack of ability to switch channels beyond 100. While that was never in the vision for this device code, it’s still pretty sad that the Echo is not smart enough to go past 100. Maybe I should look into other ST capabilities that Alexa is friendly with like Thermostat, etc.

All the best!


(JZst) #17

Code on GitHub updated to support Amazon Echo (Alexa) commands with numeric ranges. The HDMI slider is the control that finally started working after @lonelygadget clued us in on the keyword “light” in the command.


(Bryce) #19

Does not go beyond 100.0 because that is representing a dimmer percentage, which the normal range is 0.0-100.0. I am looking at writing an additional skill to augment what device types and functions are supported. Right now the SmartThings skill is rather limited. May even write a skill for direct support of TV/IR control using NodeMCU. This would require adding a discovery protocol to this code base.


(JZst) #20

Yep I was aware that I’m trying to leverage light capability which obviously goes from 0-100% — definitely a hack :slight_smile: having said that, there aren’t that many capabilities that work with Alexa that have other ranges. Only thermostat comes to mind and maybe some of the Logitech Harmony code.

I’m guessing you’re trying to augment Alexa skill code which would be sweet. Let me know if you want me to flip a few things to comply with your vision. Happy to do it and obviously enhance this IR device even further.


(JZst) #21

I just noticed something, I connected to an unsecured ESPxxxx SSID on my phone and found that it gave me a DHCP address of 192.168.4.2 — so naturally I went to 192.168.4.1 and guess what, it’s my TV Remote device — unprotected/open WIFI. How does one disable the built-in access point on these NodeMCU devices? Does anybody know?

EDIT: looking into this possible solution: http://www.esp8266.com/viewtopic.php?p=16816

EDIT2: using this line below seems to turn off wifi altogether…
WiFi.mode(WIFI_STA);


(JZst) #22

So check this out: https://github.com/esp8266/Arduino/issues/676

Looks like the ESP8266 library came with likely the most important wifi security flaw with the older 2.2.0 version… Wireless Access Point is ENABLED and accepting clients w/o a wireless security key. Then SERVING the little website on this NodeMCU board if you connect to that unsecured SSID and navigate to 192.168.4.1 — friggin awesome. If using this code below, it does indeed work as expected after updating to 2.3.0 and I no longer see my ESP8266 advertising it’s SSID for unsecured connections and neighbors being able to control my TV :slight_smile: Use the below on every sketch before WiFi.begin().
WiFi.mode(WIFI_STA);

I urge folks to update your ESP8266 library to 2.3.0 — it fixes this important wifi problem. It’s also a nice user experience when it shows percentage of completion in the log/output pane at the bottom.
Arduino IDE > Sketch > Include Libraries > Manage Libraries > search for ESP8266 and update to 2.3.0

If you don’t have the ESP8266 library then read the first post but this is now the correct board manager URL to provide under Arduino IDE > File > Preferences > Additional Board Manager URLs
http://arduino.esp8266.com/versions/2.3.0/package_esp8266com_index.json

I am updating all of my device code to reflect this, which unfortunately will break folks that are 2.2.0 or below. Given that security is the topic, it’s important in home automation especially for wifi-based devices so I’m willing to break some compatibility for it.

Thanks!


#23

@JZst I was looking at your 2 led sketch and I noticed you were sending the raw and hex codes for some of the actions. Is there a reason for that?


(JZst) #24

Two reasons for that:

  1. Just to show examples that the IRLib has ability to send different IR protocols.
  2. Likely more important than #1, the fact that the IR Receiver sketch sensed and spat out either NEC or just RAW so I just went with what I saw the receiver sketch display in the serial console.

#25

Thank you! I’m getting close… I only have one IR led so far but I did some rough online estimate and added a resistor to it. Crossing my fingers that I don’t burn it up before I get to test the other equipment I want to control. I have a few TSAL6400 on the way.