From Entryphone to Home Automation and IoT

This post is the 2nd part in my Arduino Entryphone project, which has expanded somewhat since first planned.

I’d always intended for this to be a learning project, and the number of things I want to learn from it has grown, covering the electronics side, programming languages and tools I’d not used before. Whilst my original intention was to build a web front-end that could be hosted, and therefore updated, externally and look better than a basic submit button, this has now grown to include microservices, serverless and message queues.

Capgemini IoT stand at Devoxx London 2019

Whilst it would be best in most projects to come up with a list of requirements and then choose the tools to fit around these, for this project I’m adding requirements to specifically try out new tools. I attended Devoxx London 2019 last month and came away with quite a few ideas, especially from the Capgemini IoT stand.

HTTP POST Implementation

Before last weekend, I’d got a basic page and an externally hosted page up and running, and aside from the issues discussed here (HSTS), working. This didn’t use any user authentication other than the user having to be on the Wi-Fi network to be able to send the request. I really need to be able to give individual users access and log any actions which they take. I’d initially planned to do this through a database (sticking to what I know with PHP, Javascript, jQuery UI and MySQL), but thought it would be a good opportunity to learn more about other web frameworks and cloud service offerings.

Minimum Viable Product

I hit my first issue during the PoC of this when I found that hosting externally and trying to POST to an internal IP gave me a cross origin scripting error. I managed to get around this by setting the Access-Control-Allow-Origin header in the HTTP response from the Arduino to allow posts from anywhere. If I decided to go forward with this I’d restrict it to be the domain I serve the page from.

The next issue that I hit was that I appear to have the HSTS Policy for my domain set to Strict-Transport-Security, meaning that https applies to all subdomains too. This was problematic, because I didn’t have HTTPS set up on the Arduino, and therefore got another error when trying to POST:
Mixed Content: The page was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint. This request has been blocked; the content must be served over HTTPS.

I’m still trying to work out where the HSTS policy is being set; either through WordPress on my website or by Apache, so that I can exclude it for the subdomain I’m using for the door controller. In the interim, I’m able to get around it by using incognito mode.

First QA Testing

I shared the PoC link with my housemate, who immediately found a flaw with using jQuery load() when the connection drops: Requests are queued up and then keep running on the Arduino once re-connected. I was planning to fix this, but then thought I’d move over from HTTP POST requests to MQTT, and would be able to handle this with QoS.

The web page was in a state though where I was happy to share it, and the next day a friend who is habitually late (her record is 4 hours) turned up to mine on time, whilst I was still out shopping. I sent her the Wi-Fi code and URL and she was able to let herself in.

MQTT Implementation

Over last week’s bank holiday weekend I worked on moving over to message queues, using Docker to host mosquitto on my Mac. I seemed to have a few problems with websockets when using it directly on Mac, but the docker container worked fine. I used the HiveMQ MQTT Websocket Demo App to get up and running and check everything was able to connect. Yesterday I got Node-RED running under Docker on my Mac, allowing me to incorporate IFTTT Maker Webhooks for push notifications and limit the number of requests within a five-second period.

There is a limitation in the library I’m using, that it can only publish QoS 0 messages, which shouldn’t be too much of a problem, although means that providing feedback to the user could be challenging.

Since the first round of testing, I’ve moved all of the code over to Bitbucket and added a Trello Board, which my flatmate is using for feature requests and me for bug fixes. Maybe at some point I’ll open up the repo and board rather than adding to additional lists. The roadmap for my project now includes the following:

Software Roadmap

  • Build out a progressive web app allowing logins, push notifications and user provisioning (depending on access level)
  • Add Alexa support so the door can be opened by voice (ignoring the obvious security issue of somebody shouting loudly from outside).

Alexa Integration

For the Alexa integration, I considered a few options:

  • Going down the developer route and building a skill
  • Using IFTT / Maker webhooks and AWS IoT MQTT connected to my internal mosquitto message broker to relay messages
  • Using a tool like Home Assistant – Hass.io to relay messages (I’m currently also trying this out in Docker)

Hardware Roadmap

  • Detect when the buzzer outside is pressed, to allow notifications to be sent to those who have subscribed.
  • Detect when the door is opened (for no particular reason)
  • Detect motion in the hallway (again, not sure Javascript use case for this yet).

Arduino Entryphone

First Pass

Entryphone
Testing out wiring into the phone, without the cover.

It seems to be a May Spring Bank Holiday tradition that I decide to pick up Arduino projects. When I looked back at my WhatsApp history with my flatmate to find the photo that I’d sent to him showing what I’d started it was the 28th May 2018. At the time, I had an Arduino Uno microcontroller board (based on the Microchip ATmega328P) that I’d had since my University days, along with a relay, which I decided to put to use to make a tool to allow us to unlock our front door from our smartphones. Continue reading “Arduino Entryphone”

Getting Back Online

One of my New Years Resolutions for 2018 is to get back online and engage with social media and start blogging. I have ‘posts’ that I’ve been drafting in OneNote since June 2016, and haven’t contributed much to my social media channels at all. Having had my domain name registered since 2010 and done little with it other than email I though it was about time I put it to use.

Here are the social media I use and what for. More to follow… Continue reading “Getting Back Online”

First Thoughts on Logitech Harmony

I seem to have a habit for writing up blog posts when on long train journeys but never spend any time finalising and posting them after. This is one of those posts that’s been ‘Under Construction’ since June 2016.

My current (2016) technology setup includes:

  • TV – Sony KDL-37P3020
  • Google Chromecast
  • Bose SoundTouch 20
  • Raspberry Pi
  • Belkin WeMo (WeMo LINK and 2x bulbs)
  • Logitech Harmony Companion

This post covers setting up my new Harmony and getting it to work with my existing entertainment tech.

Sony KDL-37P3020 TV

The Harmony remote works well with my TV as this has discrete commands for on and off (as opposed to a power toggle). As I only use this for the AV inputs and not live TV I’m not too sure how well it works for channel switching, but with discrete commands for AV4/5 (HDMI inputs) I can send the command and almost every time the TV behaves as it should. As this was the one device I couldn’t already control from my phone (it’s not a smart device – no network connectivity) this is a major plus point.

Google Chromecast

Although the Chromecast was discovered over the network (which I hoped was a sign of things to come with XBMC and SoundTouch… it wasn’t), Harmony did not actually do anything when tested with iPlayer or YouTube when casted from my iPhone – the play and pause buttons don’t work, so I’m not sure what the point in it taking up a device is.

Having done some searching online it should be possible to have some control using the Chromecast API, for example to Play and Pause, however Harmony doesn’t seem to send any of these.

Bose SoundTouch 20 Speaker

I’ve had multiple problems with my Bose SoundTouch. The first problem was that the ‘Aux’ button didn’t show on the virtual remote within Harmony. Logitech phone support were helpful getting this added (they are able to add buttons via your account and you can then sync the remote to detect them), although that was far from problem solved.

The second problem was although I now have an ‘Aux’ button, this appears to be a toggle (although labelled as discrete, if the button is pressed a 2nd time it goes to a ‘please select an input’ screen). One way I tried to get around this was by having the speaker go to a preset and then back to aux, so that whatever the input (e.g. Aux, Spotify or a Preset), it will always go to Preset 1 and then Aux. This doesn’t seem to be working every time – I’ll need to check the setup again but for instance when moving from Chromecast to XBMC although the input will change to a Preset it then changes back to ‘select an input’ – I’m not sure where the 2nd Aux input is being sent.

With the toggle it’s difficult as Harmony can’t really track what state the speaker is in – it is often turned on by Spotify from my laptop, phone or computer. Ideally I want it never to send an ‘On’ command, and just press Aux (providing the last thing it sent was an Off signal) – that way if the speaker is on Spotify it will change over, and if it’s off it will turn on to Aux. I’ve tested this manually to confirm which does work (this was how I turned the speaker on previously) as it should know the state and input it shouldn’t change when flicking between XBMC and Chromecast.

After almost an hour on the phone to support (which were helpful, although having to manually Sync after each change was a minor annoyance) we weren’t able to get anything better working. It looked to work most of the time but I hadn’t really tried out all use cases at that point.

As a final workaround for this I’ve assigned the ‘E’ button at the bottom of the numeric keypad to the Aux button, so that when 50% of the time it doesn’t work I can press the button to manually change to input over.

Settings Tried:

  • My device does not have power buttons
  • Power off but do not power on
  • Send Preset 1, Delay 1s|2s , Send Aux

Although my speaker is Wi-Fi and can be controlled by Telnet / HTTP, commands are still sent by IR. It would be useful if it was seen as a ‘smart’ device so that the status could be found for currently playing media.

Raspberry Pi (Kodi – XMBC)

I have a Microsoft remote and USB IR sensor I have connected to my Raspberry Pi (running Kodi, formerly XBMC) to enable remote control. This works perfectly after setting the remote type in the XBMC settings, although it would be a problem if I did want to reconnect my Xbox 360 as would use the same IR signals.

It would be nice if it Harmony could connect over the network to XBMC instead of IR, sending API commands (JSON-RPC API). This would allow Harmony to get the current status – e.g. playing Video or Audio and turn on the relevant devices.

Conclusion

This definitely seems like something that would fit right in with a ‘standard’ setup – I think it would be ideal for my parents with their basic setup (TV / Sky / BluRay / Kindle Fire / Surround Sound) and would really cut down on the remote clutter, but for more customised setups although it does reduce the amount of remotes I need, it very rarely does the right thing first time.

Whilst the majority of issues can be overcome with manually added buttons this isn’t user-friendly for anyone else – for example I had to program an additional ‘Turn speaker to Aux’ button. I don’t feel like it would be any easier for friends to turn on the TV when visiting without assistance than it was when I had 3 remotes (or 5 at one point – standby adaptor and HDMI switch).