So for beginners, HA-Bridge is a piece of software (a very nice piece of software) that runs on for example a Raspberry Pi, who’s job (in my case) is to talk to Amazon’s Alexa and send off MQTT commands to control things. In reality I’ve always had it return commands to Node-Red – because many of my controlled items are on timers and I need the two put together.
WELL! You learn something new every day. Just had a call from a pal of mine (we both have multiple Amazon Alexa units around the house). Not only can you now call the thing “computer” – but one can now call the other… so “Alexa, call house” rings the house Alexa from my office and makes an Intercom call – love it.
I really do wish they’d offer way more flexibility with keyword naming however. It is pretty much impossible to hold a Skype conversation about the subject without using the word “Alexa” at which point the units on either side of the call start apologising. I can’t imagine “computer” is the best idea either…
Imagine the conversation…. “Yup, I was just upgrading the computer the other day”. “I’m sorry, I didn’t understand…”
A key word like abracadabra might be nice – something you don’t use umpteen times a day.
Some of you may recall that in the dim and distant past, Aidan and I wrote a SKILL for Amazon’s Alexa – which let us do anything by simply passing the speech back to Node-Red… and we could sent text as speech to Alexa. Well, that relied on SSL port access and writing skills and… we’re still waiting for something easier and so without effort, that arbitrary response is still a little way off, but..
If you want REAL EASY - read on. (updated 13/10/2017)
It’s been a busy week already – I’ve been saving up a load of “Can we write articles for your blog?” emails and this morning I decided to take a look. The sample articles were ATTROCIOUS and now I know why so many articles are bad out there – they are written to order by people who just write stuff. Well, no thanks. I’ve asked the lot of them to remove me from their databases.
In the course of the post coming in I noted a Github notice of a new version of ALEXAPI – now for those of you who don’t live in the USA or America, Amazon Alexa is a box that you can talk to and control your home, play music (theirs, not yours) and generally buy Amazon products without needing to be able to read and write. It’s a wonderful thing. ALEXAPI claims to do the same on a Raspberry Pi or similar.
I have two of the Amazon DOT devices (which are very reasonably priced at £49 as against the full on unit which IMHO is, like the Google unit and others, way OVER priced). Very happy with them. Well, I’d be happier if they had an RJ45 connection instead of just WIFI – but that’s ok.
So what do we do with these? Well, we have shopping lists, we listen to music (on Maureen’s account as she has Prime, I don’t) and we control house heating, lighting etc. All in all they’re part of the family – and the BIRDSONG skill drives our cats NUTS which is a lot of fun.
And so it was that I found this link interesting in the email this morning. With this software, a usb mic and speaker of some kind, not only can you emulate an Alexa on a Raspberry Pi but on all manner of other devices.
Now, I long ago gave up on using a Pi, £32 for the Pi, plus powered speaker, plus decent mic plus case plus power supply comes to WAY over the cost of a ready-built Echo complete with REALLY pretty lights and a microphone array.
But this morning for a moment I was distracted – one could use an Orange Pi Zero which is only a few quid!!! And off I went and followed the instructions. So – before I start, if you want to play with this – you CAN install this on an Orange Pi Zero (Armbian is good), it DOES work and you CAN completely uninstall if. Been there, done that.
I stuck in my USB audio adaptor, powered speaker, 3.5mm stereo microphone and installed the software. I filled in the details on Amazon which gave me the necessary keys to update the config on the AlexaPi. I rebooted the Orange Pi Zero and…
Nothing. As usual, audio settings. I talked to some VERY helpful people on their forums who guided me through changing the settings to the USB audio device. I tested it – audio output – perfect. Audio input – perfect. I thanked them, rebooted and…
Well, I nearly fell off my seat. “Alexa, what time is it?” – after quite some delay (this is NOTHING like a DOT which responds almost instantly) the unit came back with the time. I tried a radio station and LO, it played the radio station. By now I was getting excited… I could put up with the delay.
Sadly, and this is no reflection on the obviously hard work done by the designers, things went downhill from there.
“change accounts” I said, wanting to switch to my wife’s account as she has Amazon music. No other people in the account setup. That could have been just a technicality so I ignored that. remember I know exactly how to use these things as I have two DOTS.
“Set a timer” – turns out the unit does not do lists – most likely API-related.
“Find my devices” – this was the killer. It took some hunting down but it was actually in the UNINSTALL instructions that I found … “AVS API doesn't have a way to connect the devices to Amazon.”
That last one was the killer. That and the mic – the problem is – Amazon put a lot of work into the mics – and they handle speech over background music reasonably well. I can blast my music and shout over the couch “ALEXA – SHUT UP” – and it promptly obeys. Not so the AlexaPi – while playing the radio could I HELL get it to take any notice of me until I turned the music down – and I was only sitting 2ft away.
I uninstalled the lot – and my Orange Pi Zero seems to be as good as new. So if you want something new to play with – or if you have a very limited set of needs – have a play. For me – I’d rather fork out £49 at this point.
It was suggested that one thing this software could to that the real thing can’t – is respond asynchronously – i.e. use it to output speech without a command – that is an annoying omission on the Amazon system – though if you write a special skill you can have it say what you want in reply – but then you have to call the skill and have a secure connection etc.
But then it occurred to me – I have a Raspberry Pi running the house and HABRIDGE – and it has Node-Red and I already have IVONA speech on it – all I need is a speaker and when the DOT talks to HABRIDGE to fire an MQTT control message to my lighting and heating – it can also send off some speech itself. Don’t know why I didn’t think of that before.
So there it is.
What is Alexa?
Before I go any further – let me backtrack for those who’ve been in – well, a cave or something – what the hell is Alexa? Ok, you’ve seen SIRI and OK GOOGLE etc. and probably talked to one or the other. Well, this is better. A LOT better. This is the fore-runner of the companion you’ll be talking to when you get old!
So the Amazon Echo is a tall, round black box with a speaker that plugs into the wall, hooks into your WIFI and you talk to it and it talks back. The Dot is the same thing, third the price – without the big speaker. It has a small speaker and you can plug another speaker into it or hook to a Bluetooth speaker. For my money, the Dot is the best buy.
So far so good. But why would you spend £45 on that?
The Dot unit has a microphone “array” – all you need to know is that when it is blasting music – it can still hear you! If you happen to have an Amazon Prime account or a full Spotify account – you can say things like “Alexa, play some Pink Floyd”. Now that might not seem like much – but trust me – this is going to be a party trick for MONTHS. No you can’t play your own stuff – well, that’s probably not strictly true – depends how clever you are.
Ok, so we have a talking, listening music centre? Is that it? HELL NO!!! Alexa can handle everything including “what is the meaning of life”. But also – “Alexa – add beans to my shopping list” – and variations (you can get the list of on the somewhat lacklustre APP) – alarm clock, timer – the list goes on.
But where it gets really exciting and frustrating at the same time is when you realise you can attach it to NODE-RED and have it control your house – securely. Where’s the frustrating bit? The HTTPS: bit… it won’t work without it (don’t even DREAM of mentioning certain sites that only work in America or those who are still talking about deprecated code). Well, the good news is that today we tackled this and cracked it and we have this now working in Node-Red without any special libraries and when you see it you’ll immediately realise the fantastic potential – heating, lighting, security, kettle boiling and other important items – all within grasp. Take a Raspberry Pi and a speaker amp and a microphone array and a power supply and a case and spend £60+ or just buy the DOT at £45 !!! The alternatives simply are not worth it as far as I can see.
No – not easy at first – which is why Aidan and I plan to sit down to document the lot. In reality – it should be possible to reduce the whole procedure to half an hour and the cost to a few quid a year. Right now I have everything in front of me and it is merely down to some trivial coding to get my various heating systems, lighting systems and the rest on voice control. My next job after writing this preliminary blog – is to order another DOT.
But I can do this for free?
There are countless stories of alternatives out there. I'll just ignore any hardware solutions that don't use special microphones – and when I asked SEED about the apparent fact that their solution plus microphone board come to MORE than the Amazon product – I didn’t get as much as a reply. As for free SSL? Show me a free SSL that does not require constant renewal, that works with subdomains (xxxx.xxxx.com), which has been proven to work with Amazon's system (please DO) and which doesn’t rely specifically on one machine like a Pi - until then - a REALLY cheap SSL seems a reasonable way forward and despite the sweat at the very thought of it, obtaining and using the certificates was actually quite easy.
Is code needed?
I've seen solutions requiring java and other languages - I wanted to do everything in Node-Red - i.e. generally visually - and this is what we have done. No compiling, no special requirements - just Node-Red and some nodes and functions. There is absolutely no requirement to be using a Raspberry Pi here.
We spent a lot of time yesterday getting to grips with terms like “intent” – I don’t know why people keep coming up with new terms… and initially we were looking at various “intents” but I’m half-convinced you only need one or two and the rest can be done in Node-Red. I won’t go into the image below – it won’t look like this when we’re done – but if you ignore that “status report” you pretty much have the basics – I can turn a light on an off already via MQTT (but the actual mechanism is irrelevant – I just happy to use MQTT for everything – all my little ESP8266 boards run MQTT ultra-reliably.
So the basic idea is simple enough – in order not to confuse your home control with other stuff, you can hand control over to your stuff using what I would call a keyword… so “Alexa – ask XXX” or “Alexa – tell XXX” – which seem to do the same thing… where XXX is your chosen word or phrase. I’m going to call my controller “Charlie” because “controller” sounds too geeky and if you use “house” then when video Skyping your friends with the same keyword you’ll chance to mess up their heating
So (and you can add irrelevant words like please and thanks and to etc…. but I won’t) – I’m thinking – “Alexa ask Charlie location device action” - for example “kitchen heating up”, “bathroom lights off”, “office heating status” etc…. others may do things a different way but that works for me with the minimum number of words.
When implemented – I’ll be back! But to be clear – this is working NOW, completely reliably and there is no chance the idea above is not going to work. However today the BT man is coming over to fix our rotten broadband and I’m sure he’ll want to turn it on and off.
About the only down side up to now – is the ATROCIOUS Amazon music library which is as much use as an Ashtray on a motorbike. No AC/DC – WHAT!!!!?!?!?!?!?!? Clearly if not on a budget – Spotify must be worth the investment.
Alexa – play “I’m not in love”
Update Monday: We’ve spent the entire day on this – and that flow up there is out of the window – it turns out that all is not perfect in the standard way to handle Alexa – for example you would thing that by defining a range of words that are acceptable, no other words could creep in there – but in fact if you read the Amazon docs – they can. So for “light” you could end up with “flight” – so for all that range checking you STILL need to do your own checks.
We’ve taken a different approach. I’ll soon present some Node-Red code… that will do this. “Alexa tell the computer to turn the kitchen lights on” – the relevant bits of this are “turn the kitchen lights on” – and by the time you remove irrelevant words you are down to “kitchen lights on” – out block for Node-Red will do exactly that, return a cleaned up array of up to 15 words. What you do with them is entirely up to you. No chance of getting words wrong and have Alexa sit and time out. This is all working now – but it is also very late at night. The beauty of doing your own thing is that you can do things Alexa might balk at..
“Alexa tell the computer to turn the kitchen lights off and heating down”
So you end up with “kitchen lights off heating down”
Look through a series of acceptable locations, if none, bomb out otherwise look at a series of units – got it…. next parameter is what you want to do. Next parameter is location – but if not found – use the last one – then a device – then status. In one instruction you might be able to control 3 or 4 items!
I can’t wait to get started – no matter what we add – more messing with the Amazon site!
I recall a couple of questions in earlier blogs about Itead (Sonoff) and CE. Well, they’ve just written to me to confirm that “CE marking on Sonoff products does mean Conformity European, not China Export.” which should set some minds at ease – they also sent me the test reports.
I’m sitting on a Sonoff Dual, a Sonoff POW and a Sonoff TH16 here. Right now my Amazon DOT has turned up – I’ve just got it hooked into their music system and having great fun – next step is to figure out how to get a cheap SSL certificate running on the Pi so I can use the Node-Red-Contrib-Alexa – that will likely happen tomorrow – THEN I’ll get around to dismantling these Sonoff units and let you know a little more about them.
I’ve just been up to Northern Spain with a friend and our wives looking at some property up there and when we got to our hotel and got the wine open, Aidan showed me his new toy – Amazon Echo.
The Echo Moment
Well, I was so excited I’ve ordered the new Dot which should turn up next week – after all my failed experiments with Google Now and Microsoft’s Cortana trying to fire text at Node-Red so I could control things, this might just do the job – but that is something for next week.
Of course – you could always hang around and wait for the forthcoming fluffy version called FABRIQ – which appears to be rechargeable – but no mention of microphone arrays so you take pot luck on how good the audio capture is. You could even take the kit route with Seeed’s ReSpeaker – but by the time you add up the cost of ReSpeaker and the microphone array… well, I’m wondering if they’ve lost the plot. They sent me a ReSpeaker to play with minus the microphones – I nearly choked when I saw the additional cost. If you have an Amazon account you can play with Alexa here.
I’ve not had a lot of luck with the Raspberry Pi versions, one only works in the USA, others are out of date and require button presses… anyway I’ve ordered a USA mic any my DOT turns up next week so maybe in a couple of weeks this will start to fly at this end.
We came back to the cave on Friday and yesterday my friend Jonathan rang me up full of new stuff he’s been playing with.
Glasswire and Divvy
So first things first – for Windows enthusiasts – check out GLASSWIRE. I have it sitting here making pretty graphs of my network – I’m not saying it is any good – I’m saying it is extremely pretty and possibly deserves a corner of your desktop. Something else you might like to play with is DIVVY from MIZAGE. I’ll leave you to look those up. I found them interesting.
Meanwhile as some of you know I’ve been experimenting with Armbian on my little Nanopi NEO. Lovely operating system and I managed to get my script working on it no problem – but for one thing – WIFI - the NEO doesn’t have WIFI and so you have to stick one of those cheap Chinese WIFI dongles in – and on most of the SBC boards I’ve tried – no problem. However after jumping through some hoops to get the WIFI working on this little Neo board – I was very disappointed – WIFI performance was so poor you could see delays when doing the likes of apt-get update etc. I wrote off to the Armbian forum and the response was along the lines of “you should try an Orange Pi Lite if you want WIFI” – well that’s all very nice but I already have two NEOs.
Well, I was sitting getting depressed about this when my friend Jonathan rang me up with some new things to try.
WinDiskManager and Etcher
So first things first – you know that Win32DiskImager that everyone uses to FLASH Linux SDs – he’s spotted something not only a little faster but a little nicer looking called Etcher – so the first useful takeaway from this blog entry is Etcher. I installed it on my Windows 10 64-bit system no problem – none of your “administrator-only” stuff – and Etcher works - point it to an image file – and it flashes it to SD!! Mind you that’s ALL it does. If you need to READ images onto your PC you still need Win32DiskManager.
The DietPi Moment
He then reminded me that before I was playing with Armbian I’d had a go at DietPi for the Raspberry Pi. It only worked on the Pi itself - it was a nice, lean installation of Debian – but hey – the normal Pi setup was fine – so I put Diet-Pi to one side.
WELL – take a look at DietPi today – it is no longer for the Pi only – and it can install lots of goodies – kind of complimentary to my script (with a nicer interface). And in the process of this conversation I noted it has a setup for the NEO and other FriendlyArm boards.
Well, wouldn’t you know it – there’s a menu driven setup for WIFI – and it WORKS!!! And the funny thing is – the designer credits Armbian – WELL!! Ok, so there’s a LOT more to this and I’m only at the beginning – I noted that this Diet-Pi on the NEO seems to run even faster than the hardwired version on Armbian – and I’m only at the surface of finding out why – but one reason it seems nippy is you have full control over logging – which by default is running in RAM and at a minimal – a very sensible starting point.
In the process of setting things up I discovered some sillies in my script (which takes a basic Debian setup and installs a while raft of useful goodies centred around Node-Red) and I’ve fixed those.
I have now run my updated script on DietPi on the NEO and M2 and up to now everything seems to work – and it’s a small installation for a small board – and nippy… I need to go way more deeply into this – there is SO much in Diet-Pi now but I’ve no idea how much of it actually works – I DO know that not everything works on all boards but as I’ve only installed this on the FriendlyArm M2 and NEO I’ll keep my mouth shut except to say I’m mildly enthusiastic – my little NEOs are now useful wireless devices – which is a great step forward.
Experiments above with Node-Red, MQTT and serial – all working. And below – with a simple mod – a nice colour terminal… all on my NEO soon to be replicated on M2 and T2.
Now there DO seem to be some issues with DietPi – I’ve reported them – on a real Pi the serial port needs permissions altering to work (added to script just for belt and braces) – and on all installations, Mosquitto fails to run at power up – MAYBE starting too early I don’t know but taking a line out of the RESTART bit of the start-up script and putting it in /etc/rc.local does the job.
Up to now everything seems ok and I’m working with MrShark to looking toward the lightweight LIGHTTPD.. we’ve already improved my script – and you know how it goes – once someone triggers you off…
More of that soon – for now – I have my script (as of today) running (with the caveats above) on a Pi2, M2, NEO and BananaPiM2 – and that’s only due to restricted time… DietPi has the advantage of making a MUCH smaller footprint at under 2GB compared to nearly twice that on, say a standard Pi – as there is only in there what’s needed.
Oh while I think on, here’s the link to my original Neo article.
Expect to hear more about this in the coming week – I’m off now travelling with my wife and 3 cats ALL the way up Spain – 24 hour ferry – ALL the way up England… you won’t hear anything from me in here as I’ve not mastered blogging on a phone
.By now Aidan has his Alexa turning his lights on and off via Node-Red and so that will be the next job – integrating this whole lot together.