Since I have been fiddling with Alexa I was able to get a light working with Wemo emulation. Both on the Raspberry Pi and on the ESP itself. I am mostly using the ESP with Fauxmo to act as physical devices. The Wemo emulation being done on the Pi is for running a bunch of scripts with MQTT or (hopefully in the future) gettin’ data from sensors and such. Still trying to find a way to get Alexa to read whatever I give her from MQTT, that would be righteous. But for now I have an automated keyboard light with Alexa.
(TLDR; Made a keyboard light on an ESP with a relay that emulates a Wemo plug and is voice activated by Alexa. Skip to the bottom for the code I used.
Any who, I replaced my old keyboard light switch made out of an old telephone biscuit jack with a toggle switch. I upgraded. I can now voice activate my keyboard light with Alexa. Man I’m lazy, and man that is cool. Not the lazy part the keyboard light. I do have to admit this was not my first attempt at this build. I tried two times before I finally got it right. The first two times I was trying to use 2N2222 and 2N3904 transistors and neither would work right for me. I was able to get it all working on the breadboard just fine but as soon as I transferred it to a PCB it failed. I think the problem is with the transistor. From my measurements it keeps leaking 12v back through the base and I don’t know enough about electronics to be able to figure it out yet, obviously, I tried twice.
So the third time I used the pre-made modules I have; 5v relay module. I put together a small PCB for the ESP and a DC-DC converter and added some pins to use jumper wires to attach to the relay. Soldered the power to a barrel jack and hooked up a toggle switch and connected it to the relay. So if I flip the switch it bypasses the relay and I get light manually. Always good to have a backup. The switch will work with or without the ESP plugged in. I plugged it in and bam! It worked. I gave Alexa a few commands and on and off the relay clicked. Beautiful.
Then……it failed, it started flickering the relay. It took me a minute to figure it out. I forgot the current limiting resistor on GPIO2 for the relay. Oops. That’s an easy fix luckily. The green jumper wire in the pictures goes to the pin header from GPIO2, so all I had to do was remove the jumper wire and replace it with a 1K ohm resistor. Easy. It was getting late so I turned it off and removed the ESP. The next day I go over to my computer and I can smell the lovely aroma of burnt electronics. Fuck. I look down and I can see the DC-DC converter sparking on the underside of the PCB. Turned out to be a bad solder job on my part. Since my liver transplant I have to take a shit load of pills, and some of these pills cause my hands to shake. Sometimes it’s not so bad and other times it’s ridiculous. I guess they were shaking more than I thought that night.
So I had to rebuild the whole thing. Again. Live and learn. This time I was sure to leave extra space in my solder routing just in case. The Mark IV has been up and running with zero problems for two days now. I think I worked out the kinks. And it is awesome to be able to sit down and tell Alexa to turn on my computer room and keyboard lights. Hell with Node-Red I could even WOL my computer!
Now behold, pictures…