Alexa, When’s the Bus?

I got an Amazon Echo for my birthday (from my husband, who took romantic to a new level when he liked my present so much he bought me an Amazon dot a week later so he could use the echo elsewhere in the house!), which is a new gadget for us. Of course I started asking her questions that she couldn’t answer … and you can write your own “skills” so of course I sat down to browse the documentation and ended up creating a working skill for her :) It was a fun process but there were lots of unfamiliar parts to it so I thought I’d blog what I did in case anyone else wants to try out creating skills as well, and in case I ever want to remember some of the stuff I know now!

Create the Skill

Once your Alexa echo/dot is working, visit the developer portal and create a new skill. I hadn’t used Amazon Lambda before but if you choose this option for your skill, it integrates well with Alexa and the security side is pretty much done for you so I picked this option for my first skill. Lambda is a serverless technology, and I wrote my skill in Javascript. When you’re developing a skill, it’s available on your account only (so all the devices in the house are attached to my amazon account) until you publish it – which I probably won’t until I’ve removed the hardcoded URL for the bus stop nearest to my house!

Write Some Code

With the skill created, it’s time to write some code! I started with this detailed introduction post from Brian Donohue which includes sample code and instructions that got me to the point of being able to shout “Tell Lorna ping” at Alexa (my skill is called “Lorna”) and have her reply “ping ack”. At this point I have both the lambda function and the Skill itself in place, and I needed to make it do something useful.

What I wanted to do: get a list of the imminent buses from the stop near my house. It’s really helpful to know if you should run or if there’s no bus for 10 minutes and you have time to also put the towels in the washing machine or talk to the cat or whatever. I know that 10 minutes waiting for a bus seems reasonable in many situations but I live near a main route into a European city so my standards are different :)

By watching what happens when I request the bus stop information on my phone, I was able to get a URL to a specific webpage with the current departures on it. This is a pretty fragile setup; I scrape data from a web page that wasn’t intended for this purpose and which might vanish at any moment, using a regex that really relies on no formatting changes in the page. However it does work and I’m comfortable with this for a hobby/personal project.

If you’re looking for info on Leeds buses, try this: http://yorkshire.acisconnect.com/Text/WebDisplay.aspx?stopRef=[the bus stop number that also works with the SMS system]. It also has info on which buses have low floors, plus any extra announcements.

Update The Skill

Once I was able to make the web request and parse the results using my local node toolchain, I then added that functionality into my lambda script. I found that publishing the skill was a painful process (check for further posts on Amazon lambda because I’m changing my workflow and may have better advice sooncheck out my followup post on a better workflow for this) because I had to:

  1. Put the code into a web-based text editor (you can upload zip files to s3 and do something but I don’t have this sorted out yet)
  2. Go Actions -> “Publish a new version”
  3. Go Triggers and set up a new trigger linking the Alexa Skills Kit to my function
  4. Go back to the Alexa Developer Console, click Configuration and update the version number at the end of the Lambda URN field

I’m also not particularly expert with Javascript yet so that didn’t help at all! To debug problems with your Alexa skill, click the monitoring tab and then over on the right hand side there is a “View Logs in Cloudwatch” link which I found extremely helpful!

Creating Alexa Skills

I hadn’t really intended to hack with the echo; it’s a fairly complete product in itself and I normally prefer much more open source or at least less proprietary systems. However, there’s one in my office and I had a itch to scratch! You can ask her “Alexa, how’s my commute?” but that seems to give road traffic information rather than the public transport I was looking for. I found this was a very approachable project despite being a bit of a beginner with Javascript, so if you’re considering creating a skill yourself, I say go for it! It took less time and fewer tears than I expected!

Tips, tricks, showing off your own skills: all welcome in the comments box.

Edit: A few people asked me about my actual skill code, so it’s available on GitHub if you want it (you need to find a bus stop URL if you want to actually use the skill), as I say based heavily on the sample code from Brian.

4 thoughts on “Alexa, When’s the Bus?

  1. Pingback: Slight tangent, voice skills! - Level 13 Studios

  2. Pingback: Amazon Lambda Deployment Workflow For Alexa Skill | LornaJane

  3. Hi Lorna,

    I’ve been toying with the idea of actually buying an Echo but I’ve yet to be convinced as to whether or not they are worth it quite simply because there are many positive and negative reviews around the web.

    My question to you is, does the convenience it provides outweigh the initial cost of it as they are relatively expensive for what is essentially a basic assistant.

    Many thanks in advance!

    • I find it handy and we do use them around the house – bus times skill gets a lot of use, also the lifx bulbs can be turned on and off which is handy when you’ve got your hands full as we usually use an app for those. Also we have a regularly-visiting 3-year-old who learned to say “Alexa, tell me a joke please” which made it a good investment by itself :)

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.