I took a look at my actual usage of the Harmony hub and realized that even if I could justify the price, multiple hubs may not play nice on the same network. It was also around this time that the Raspberry Pi Zero Wireless device became widely available. I had seen some absolutely ugly implementations of a smart IR blaster online, and decided that I could probably perform the same tasks with a better looking build. I decided against the full sized pi computer due to price, but the instructions should pretty much be the same if you decide to use one.
Since this is Aggregated Knowledge, I'll list the links that helped me create a rough draft, my version, and my recommendations for a better version. I will also include my own troubleshooting that should help explain how and where to customize the code to your own specifications with an explanation why certain things will or will not work. First up, the BOM and required tools.
1. Pi Zero W -- $10
2. Power supply for Pi -- $5
3. 40 pin GPIO add-on -- $3
4. Micro SD Card -- $6
5. Pi Case -- $3
6. IR Blaster module for Arduino -- $3
Prices are a rough estimate. Items 1-5 can be purchased as a kit on Amazon for ~$25.
Next up, tools. Everything goes together fairly easily without tools. But, to get that 40 pin GPIO on, you will need a soldering iron and solder (unless you buy the solderless pins, which are a bit pricey). My recommendation on soldering in the pins is to break away the 3 pins you will need and solder those on individually. The reasoning is that you may want to bend them at a 90 degree angle to hide the wires inside of the case if you are not cutting custom wires, or to prevent clutter inside the case. It makes the project look nicer. If you plan on soldering on the whole 40 pin module, this is an excellent example on how to perform the soldering quickly.
Aggregate 1:
I love this example because it's not using anything more than a flat surface and soldering tools. No custom stands or even a set of helping hands, because you don't need them. If you are completely new to soldering, YouTube user EEVblog is the equivalent of a motivational speaker combined with an engineering instructor.
Installing and configuring the OS. At the time of this writing, Stretch is the latest release and what I have used. This will lead to changes in scripts and code, since the packages available and their locations have changed a little as well. For example, we will be using node.js which was previously at a different location and defined as node rather than nodejs. Keep this in mind with the additional aggregates that I link, and with your own project. The typical method of writing the OS image to microSD should be followed, then add the wpa_supplicant file. Upon reboot, for security purposes, we will set up a wpa passphrase.
Aggregate 2:
Now it's time to make you open a half dozen tabs on your browser. The next aggregate is the primary building blocks for the web service portion of the project. There is some very good information in it, but it is also a little bit dated and written for controlling lights and fans. An important message here: If you need to capture your remote control codes, this aggregate has the instructions. I have a Samsung TV, which has the same IR codes for power/channel/sound on most of the newer remotes. I was able to download my lirc.conf file from the online database without issue. I would recommend reading through Aggregate 3 without executing anything until reading through the changes detailed in this blog.
Aggregate 3:
Aggregate 4:
From the example in Aggregate 3 (Agg3), Step number 3 becomes less convoluted if you have the lircd.conf file for your specific remote. If you plan on changing the name of your device across the config files, you will need to search for instances of "living_light" and replace them with the new name. Locally, this will be a requirement in /etc/lirc/lircd.conf and /opt/alexa_home_control/raspberrypi/iot_shadow.js. I did not change the living_light portion of the scripts, code, or config files. In order to properly execute the setup script, change /opt/alexa_home_control/raspberrypi/service/alexa_home.service file to properly execute nodejs. The /usr/bin/node entry should match the location of nodejs.
In Step 4, the IoT setup has changed a little, but not too much. It is relatively simple to setup a device and add the shadow file from Agg3. You may want to set up your Amazon IAM environment first, so you will have 2 factor authentication prior to building anything on AWS. Just make sure everything is in the same AWS region when you build it out. Make sure you have the certificates where they need to be according to Agg3, but modify the iot_shadow.js to include the new variable for shadow name and add the host endpoint. You can remove the lines for clientId and region. The additions will be as follows:
var shadowName = "Philbert"
host: "enter in your https endpoint here"
My IoT device name is Philbert, which will offer a lesson when we cover the Voice Service. The host endpoint is from the Interact page of your IoT device, under HTTPS. Once these changes are made, execute the setup script on the Pi.
A new role in IAM should help smooth out the Lambda configuration. I gave the role full permissions to IoT and Write permission to CloudWatch Logs. Permissions can be scaled back once you have a working device. I can not guarantee that the permissions listed in Agg3 are correct. The Lambda configuration is where things can go sideways fairly quickly. CloudWatch logs will help you in Troubleshooting. Using the linked Lambda in Agg3, I created my own file that after a considerable amount of learning and troubleshooting finally worked. This code should execute with minimal effort on a Python 2.7 Lambda.
Aggregate 5:
My Lambda
Line 7 will need a correct Voice Service ID, will be added in next step.
Line 9 requires that same HTTPS endpoint from the IoT management page.
Line 11 and 30 are just the parts (us-southcentral-2) from the endpoint that match Line 9.
Looking through the Lambda, you can see what can be added rather quickly. You have intents, a way to map them to a command, and the code that validates the intent. I got stuck for a few hours on the bottom of the script with lines 129 and 136, reviewing every line of every config file and script. The logs helped me figure it out, but it was frustrating since I have absolutely no training or education in Python or AWS. If you have changed anything, the intents and utterances should be changed in Voice Services. Collect your Lambda arn number and open the Alexa Developer Console in a new window.
Most of the ASK/Alexa/Voice Service configuration is pasting in existing information and modifying entries. As previously noted, the name of my project is Philbert. But voice to text reads it as Filbert. So, the Invocation Name of your skill should be equal to what you see in a text to speech app. There's a bug in my Intent Schema, when an Echo hears "turn up", "turn down", "turn volume up", or "turn volume down" it will change the volume on the Alexa device rather than issue the command to the IoT device. Changing the Intent and Lambda should correct this, I just don't want to have to say "Alexa, push it to the right" to get my television to turn the volume up.
Aggregate 6:
Intent Schema
Aggregate 7:
Utterances
Aggregate 5:
My Lambda
Line 7 will need a correct Voice Service ID, will be added in next step.
Line 9 requires that same HTTPS endpoint from the IoT management page.
Line 11 and 30 are just the parts (us-southcentral-2) from the endpoint that match Line 9.
Looking through the Lambda, you can see what can be added rather quickly. You have intents, a way to map them to a command, and the code that validates the intent. I got stuck for a few hours on the bottom of the script with lines 129 and 136, reviewing every line of every config file and script. The logs helped me figure it out, but it was frustrating since I have absolutely no training or education in Python or AWS. If you have changed anything, the intents and utterances should be changed in Voice Services. Collect your Lambda arn number and open the Alexa Developer Console in a new window.
Most of the ASK/Alexa/Voice Service configuration is pasting in existing information and modifying entries. As previously noted, the name of my project is Philbert. But voice to text reads it as Filbert. So, the Invocation Name of your skill should be equal to what you see in a text to speech app. There's a bug in my Intent Schema, when an Echo hears "turn up", "turn down", "turn volume up", or "turn volume down" it will change the volume on the Alexa device rather than issue the command to the IoT device. Changing the Intent and Lambda should correct this, I just don't want to have to say "Alexa, push it to the right" to get my television to turn the volume up.
Aggregate 6:
Intent Schema
Aggregate 7:
Utterances
The Configuration tab should allow you to enter in the Lambda ARN, and then you can test and save the skill. Once the ARN is entered, verify that the skill ID from the Skill Information tab has been entered into the Lambda. Perform a quick test on the Skill Test tab "alexa, ask filbert to turn on", and see if it goes through. If not, look at the Lambda Monitoring tab. If there were no errors on the Monitoring tab, test the connectivity to the AWS IoT device by watching the activity log while executing the test again. If the test executes properly, SSH into the pi and verify that the alexa_home service is running. If it is, attempt to restart it and see if it registers on the activity log for the AWS IoT device.
Once the device works, it is time to determine where you would like it. Some double sided tape can mount the pi behind a television while the IR blaster can be mounted under the IR receiver on the television bezel, with the bulb extending out enough to register. The other option is 3D printing a case, or using colorful tape and some screws to hide wire and stabilize the IR blaster. Once the blaster is stabilized and the device looks pretty, you can test the maximum working distance from the TV.
Thanks for reading through this, coming soon will be "Why Amazon Web Services for IoT" and "Pi Zero W Security Cameras to the Echo Show"
Honda Eu2000i Won't Start
ReplyDeleteHonda EU2000i Extended Range Fuel
Best Portable Inverter Generator
Disassemble Portable Generator
Dual System W/Tank Cap
Propane Conversion Generator
Basic Solar Setup Guide
Parkside Inverter Generator
Propane Powered Portable Generator
Remove Cosmoline Mineral Spirits