Mike MacDonagh's Blog

Somewhere in the overlap between software development, process improvement and psychology

Forward commands from PHP to LightwaveRF

I write this little forwarder recently so that other bits of software in our house/network could send commands to our LightwaveRF kit without needing to be registered on the hub, effectively giving local speed access to all software integrations.

I’ve got a little web server running on a Pi, that machine is registered with the lightwaverf hub (it runs my Logitech Harmony integrations). That server can then be used to forward commands like this:


<html>
<head>
<title>MMD PI Lightwave Control</title>
</head>

<body>
<h2>RPI Lightwave Command forwarder</h2>
<?php

$lw_command = $_GET['command'];
$server_ip ='192.168.0.10';
$server_port = '9760';
$message = '666,!'.$lw_command;

$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_sendto($socket, $message, strlen($message), 0, $server_ip, $server_port);

?>

<strong>Sent command: </strong> <?= $message ?>

</body>

</html>

Now other bits of software on web pages or native clients can simply call urls such as

http://myserver/lwrf.php?command=R3D3F1

(room 3 device 3 turn on)

My Alexa skill is now live in the UK

Every month at my kung fu club, Chi Wai Kung Fu in Cheltenham UK, there’s a series of strikes of the month that are on rotation for extra attention. Also there’s a rotating black belt syllabus. It’s not the easiest thing in the world to remember all of these details, and whether or not you need to take a bo staff or set of escrima sticks to the club. So, I thought I’d write an Alexa skill to remind me 🙂

chiwai_alexa_out.png

If you’re into Alexa in the UK, then join my UK Facebook group, it’s got over 4,500 members:

echo_group_welcome

The basic skill is pretty simple, interrogating an array and returning the requested information. Getting it certified was a bit more fiddly because I wanted to use a single word invocation name “chiwai” which is against the rules normally, and because it’s a trademark infringement if it’s not official. Of course, in this case it was official as I developed it on behalf of the club. The Amazon skill dev support team were very helpful so now it’s live 🙂

Here’s a video of it in action:

To get it, if you’re in the UK, just say “Alexa, enable Chi Wai“.

You can also search for “ChiWai” in the Alexa app, or install direct from Amazon.co.uk.

You can then ask it questions like “what are the strikes of the month” or go a step further and say “what are the strikes of the month for October” or “what’s the black belt element in February”. Because of the way Alexa works, voice recognition on those second questions is greatly improved if you first start the skill by saying “Alexa, talk to Chi Wai” and then ask them. You can directly ask by saying “Alexa, ask Chi Wai for the …” but it’s not quite so accurate.

Also, try “Alexa, tell Chi Wai, Zoon Ching” 🙂

The code is on github here: https://github.com/macmike/chiwai-alexa-strikes

Chi Wai Kung Fu @ Cheltenham now with extra tech!

kung_fu_cats.pngFor over 6 years now I’ve been going to Chi Wai Kung Fu! A few years ago I achieved a lifelong ambition to become a Black Belt in Kung Fu. Now I’m a second Dan and a brown belt in Dacayana Eskrima as a bonus!

Chi Wai is great, my whole family go there 🙂
My two boys started when they were little and now are both black belts. It’s done them a huge amount of good, it’s far more than just self-defense (and that’s important by enough to justify it). They’ve learned respect, discipline, control, confidence and a positive attitude founded in the fact that they’ve worked hard at something to achieve their goals. me_sifu.jpgNot always achieving first time, but through persistence and hard work they’ve got there in the end! There’s a saying that a “Black belt is just a white belt that never gave up”, that’s something they’ve learned from Chi Wai.

My wife even does Kung Fu, and is heading towards her black belt this year. As a result I’m running out of wall space to hold all of our certificates. I’m also finding home practice sessions hurt a lot more!

The Chi Wai system mixes traditional kung fu with practical self-defence including weapons and group
attacks. Because the club has a full time dojo there’s lessons for separate age groups every day (except for Sunday, even ninjas need a rest).

It’s a great family run club with a genuine family atmosphere. It’s friendly and welcoming and manages to keep that positive environment consistently. A lot of that is down to the excellent instructors but it’s also down to the people and families that train there.

chiwai_family.jpgIt’s fantastic to have a family activity where we can all be at different levels, but all encourage each other and train together as the kids get older. As my eldest son’s gone from little kid to adult sized teenager he’s now fighting with the adults and enjoys putting me in arm locks in Black Belt lessons 🙂

If you’re in the Cheltenham, UK area then get yourself, your kids and your auntie to Chi Wai Kung Fu! You can even ask Amazon Alexa about it:

Or learn how to do the intro bow from my buddy the modelling guy:

 

 

How to remove duplicates in Amazon Music playlists

I’ve recently migrated to Amazon Music from Spotify and local media servers. It’s actually pretty good although getting my playlists migrated was a pain.

Uploading seemed to cause a lot of duplicates, so then creating playlists from the recently imported or added files caused a lot of duplicates in the playlists. I listen to playlists on shuffle so this annoyed me because it means the probability of duplicated tracks is higher and you miss out on the other files. I found a way around it though!

  1. Create your playlists however you want.
  2. On Windows, install the local Amazon Music app.
  3. In the Amazon Music Windows App you can select all of the files in a playlist, right click and add to a new playlist
  4. The app will popup and tell you how many duplicates there are and ask if you’d like them to be filtered out.
  5. Delete the original playlist
  6. Rename the new playlist.
  7. Rejoice in a lack of duplicates.

For Spotify playlists I used STAMP from FreeYourMusic – ok but expensive.

It managed most of the files on my wife’s spotify playlists fine, and produced a file of songs it couldn’t match. Some made sense because they were misnamed, or not part of Amazon Music so needed manual uploading from our local collection. However, across several thousand tracks it failed to match about 60 it should have.

Also, the CSV to Amazon Music doesn’t appear to work in STAMP on Android. STAMP support upgraded me to a multi-platform license and it worked on windows. Still, it saved me hours despite being over-priced and not perfect.

Send messages to another room using Amazon #Alexa #dirtyhack

Here’s a fun trick to get Amazon Alexa to send messages to the kids in another room or whatever…
This is a bit of a hacky workaround but it’ll do the job until Alexa can do push notifications.
1) Record some custom mp3s (or go to http://www.readthewords.com and generate some)
2) Save them with good names and upload them to Amazon Music in a “Messages” playlist, I recommend calling them “MSG_something”
3) From the Alexa app you can then choose a message to send to an Echo/Dot from the “Music and Books” area (the playlist and MSG_ prefix makes them easy to find)
For example, “Please come downstairs, dinner is ready”.
alexa_msg_screenshot
I use “z. msg” as a prefix so when my songs are sorted by names they’re all at the bottom. The msg_ bit is useful for searching by song to find them quickly 🙂

How to call a webservice api from Amazon Alexa using Javascript in a Lambda function

This wasn’t trivial and I’ve seen a lot of questions about it online so I thought I’d share how I did this to get Alexa to respond to questions about my kids pocket money 🙂

You can call a URL like this:
(note I’m assuming a JSON response, you’d need to modify for non-JSON)

var http = require('http');

function getWebRequest(url,doWebRequestCallBack) {
    http.get(url, function (res) {
        var webResponseString = '';
        //console.log('Status Code: ' + res.statusCode);

        if (res.statusCode != 200) {
            doWebRequestCallBack(new Error("Non 200 Response"));
        }

        res.on('data', function (data) {
            webResponseString += data;
        });

        res.on('end', function () {
            //console.log('Got some data: '+ webResponseString);            
            var webResponseObject = JSON.parse(webResponseString);            
            if (webResponseObject.error) {
                //console.log("Web error: " + webResponseObject.error.message);
                doWebRequestCallBack(new Error(webResponseObject.error.message));
            } else {
                //console.log("web success");
                doWebRequestCallBack(null, webResponseObject);
            }
        });
    }).on('error', function (e) {
        //console.log("Communications error: " + e.message);
        doWebRequestCallBack(new Error(e.message));
    });
}

You can then use it like this from inside an intent handler:

function getPocketMoney(intent, session, callback) {

    let shouldEndSession = false;
    let repromptText = null;
    let speechOutput = '';
    let cardTitle = '';

    let url = "http://mypocketmoneyservice/getpocketmoney?person=mike";

    getWebRequest(url, function webResonseCallback(err, data) {
        if (err) {
            speechOutput = "Sorry I couldn't connect to the server: " + err;
        } else {
            //something like this
            const balance = data.pocketmoney.person.balance;
            speechOutput = `${person} has £${balance} pocket money.`;            
            callback({}, buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));                   
        }
    });
}

Amazon Alexa – what it needs to do next

I’m a big fan of Amazon Alexa. I bought a dot to experiment with and it’s so useful I have it in several rooms now. Alexa can control my smart lighting (courtesy of lightwaverf kit), play music, order food, order some amazon stuff, manage my shopping and to-do lists amongst other things, but she’s got a few drawbacks.

Here’s what I’d like to see Alexa tackle next:

  1. Conversation flow – the ability to add contextual follow up questions, without every command being “Alexa, do a thing…” It sounds trivial but when you’re having entire conversations with Alexa it’s a bit weird to have to use the wake word for every sentence.
  2. Multiple commands in one e.g. “Alexa, turn on the kitchen lights and start playing the cooking playlist” rather than “Alexa, turn on the kitchen lights” and “Alexa, start playing the cooking playlist”
  3. Unstructured search – Alexa’s great at facts but Amazon have decided not to make her opinionated.  She’s great at “what is a hoover?” and “what is 12 miles in kilometres?”.
    1. She can answer: “Who played harry potter in harry potter and the philosopher’s stone?”
    2. But can’t do things like “who played Harry Potter in the movies”. In contrast google can answer that question with a quick snippet about the cast. I read a blog that said they didn’t want to make a decision for users about simply returning the first search hit rather than making an informed choice – but if I’m making a voice search that’s exactly what I want. If I want to get a range of views and select my search result I’ll use a text interface. Returning “cards” with links to Bing isn’t good enough – just read me the top hit from <insert search engine here>
  4. Intercom – I want to be able to send a voice message from one Alexa device to another to create an intercom system in my house (e.g. “Alexa, send a message to the living room telling the kids to turn the TV volume down”)
  5. Delayed reminders – Alexa’s good at setting alarms but I want her to remind me with a message not just beeping (e.g. “Alexa, at 6pm remind me it’s time to order a taxi”). At the moment, that sentence will result in “Time to order a taxi” on the to do list. Or I can set an alarm for 6pm which beeps. I want a voice message at a specific time.
  6. Alarms – play music not just beeps. (e.g. “Alexa, wake me up at 7am with my Spotify Wake Up playlist”)
  7. Local DLNA integration. Alexa’s great at streaming music from the internet but doesn’t currently see home DLNA music as a streaming source. Which is odd, I can see how to program a skill to do discovery (similar to the current smart home discovery, or just built into that) and the rest is the same. Amazon, if you read this I’ll do it for you at a reasonable price.
  8. Chromecast e.g. Alexa, play Netflix: Game of Thrones”
  9. Order a Dominos. Yep, I know it can do this in the US so why not in the UK? Dominos allow ordering via chatbot in Facebook Messenger so this is easy to do from a coding point of view. Dominos, if you’re listening…
  10. IFTTT integration. C’mon Amazon, IFTTT say they’re waiting for you do to something. This unlocks millions of possibilities.
  11. Add things to my Amazon Wish List e.g. “Alexa, add a Raspberry Pi to my Amazon wish list” only adds it to my (local) shopping list.
  12. Remove things from todo or shopping lists by voice. Also, email me my lists.
  13. Custom volume schedules. In the morning I want Alexa to be nice and quiet, in the evening I want her volume to be a lot higher. Perhaps what I really need is her to automatically adjust her volume based on the ambient noise. After all she’s listening all the time anyway.
  14. Proactive notification. I realise it would be annoying if any skill could push notifications to my Alexa (I don’t want random ads being spoken in my house) but I’d like to be able to whitelist some apps so I can get alerts at certain times of day from specific apps (e.g. order status on ordered food, package tracking, breaking news, birthday reminders).
  15. I want a big Echo with a screen for my kitchen too.

I realise many of these are about integrating outside of the Amazon ecosystem which is perhaps why they’ve been reluctant to do so. But with Google Home, an MS and Apple assistants turning up soon the winner is likely to be the most useful all round. At the moment that’s Alexa, but by being more open to integrations it’ll be hard to beat.

What do you want Alexa to be able to do?

Holistic Software Development – the book

The HSD book is currently in it’s final editing phase. If you’d like to purchase the book then please bookmark this page and come back soon.

What’s inside?HSD Book

The book covers a detailed introduction to Holistic Software Development and it’s principles. Covering the H-Model and how it us used to map levels of decomposition to recomposition and integration the book then follows a structured path through HSD material.

We discuss Strategy and Holistic Portfolio Management to help guide organisations in adopting post-agile flexibility at the top level. We cover the HSD requirements model and how it supports strategic intent without falling into the Big Up Front Requirements trap.

A detailed chapter on architecture follows covering enterprise, solution and system architecture and its representation through over sketches and architectural mechanisms.

We cover Planning and how to balance the needs of business planning with agile just in time planning. We deconflict project management and agile ways of working showing how they can work together in a holistic organisaiton.

Releases and Integration is the heart of the H-Model and so is where the focus of HSD comes together. We discuss the dual nature of releases, and how they are best set up across teams of teams in both a technical configuration management context and a planning context.

We cover the HSD approach to Quality and Operations before covering a detailed view of People structures and organisational design. Based in psychology we look at motivation, teaming and large scale structuring covering the HSD Hybrid Dynamic Model in depth.

Finally we look at Governance and HSD variants for simple organisations and COTS before briefly covering Adoption practices.

 

We’re working through the last few edits of version 1.0 currently and hope to have the book published in 2016, you can now sign up to be notified when it’s published on the HSD site.

Howto: Controlling LightwaveRF lights with a Raspberry Pi, Flirc and Logitech Harmony One IR remote

I’ve recently got into home automation and so thought it would be fun to integrate my smart lighting with my media centre and remote control. When I watch TV or streaming video I want the main lights to go off and the side/back lights to come on in my living room. When I pause I want the main lights to come up a little and when I play I want main lights to turn off again 🙂

My setup

I use LightwaveRF devices to control my main lights (2 dimmers) and various side-lights and screen backlights, I’ve also got a LightwaveRF Link hub which allows the Lightwave’d lights to be controlled by app, but also by simple UDP packets.

I’ve got a Logitech Harmony One remote control, because it allows you to setup custom sequences and controls my TV, DVR box and sound bar.

My solution:

I decided to use a Raspberry Pi 3 (now with Wifi and Bluetooth built in!) to do the lightwave udp packets and  Flirc to interpret the IR signals and convert them into simple text commands. Then I wrote a little python program that listens to the incoming commands from the Flirc USB Infrared receiver. There are other ways of interpreting the IR commands, but this was a super simple one!

Harmony One to Lightwave RF integration Read more of this post

Holistic Software Development @AgileInABag London 12 June 2015

Agile In a Bag London 2015

I’ll be presenting with my friend and colleague Steve Handy about Holistic Software Development at the Agile in a Bag conference in London on the 12th June 2015.

If you can make it, do come along to this great 1 day conference to have some fun, share some thoughts and ideas and meet some interesting people 🙂 Here’s the blurb for our talk first thing (9am) in the morning:


 

These are not the practices you are looking for

Is your time to market quick enough for your business to respond?
Is your Programme and Project Management smoothly joined up with your agile teams?
Does everyone understand how their work contributes to business value?
Do you know what end-to-end scenarios will be delivered in the next programme release?

Come to this talk to hear how these common problems are easily solved, even in highly complex system-of-systems organizations by using the freely available “Holistic Software Development” (HSD) framework which aligns agile philosophy throughout the enterprise, at-scale engineering, architecture, strategy, portfolio and programme management. Using a novel but lightweight end-to-end scope level requirement type we iteratively drive the development of well understood Releases and customer feedback loops.

Combined with layered iterative or continuous integration and clearly understood progressive Definitions of Done we can simplify the complex resulting in a perfect join up between customers, requirements, planning, delivery teams and governance. HSD is the glue that plugs together your existing agile team practices (e.g. Scrum) with PPM practices (e.g. Prince2) and business strategy providing people focussed, lightweight guidance firmly based in evidence, experience and excellence.

And here’s the learning outcomes we’re aiming at:

  • Understanding how to de-conflict agile and enterprise portfolio and programme management
  • How to unify agile teams, governance, customers and executives in a simple model
  • The “H-Model” of software development
  • How to join up different schools of thought/processes into a cohesive way of working
  • How a strong approach to understanding business value enables effective software businesses

 

You may detect a slight Yoda-like grammar to the title… Come or come not, there is no spoiler.

%d bloggers like this: