March 15, 2017

Button Box for Home Assistant

Here I show you how to make a simple button box that can be used to control lights, set scenes, or other automation things connected to your Home Assistant system.

 


It works by detecting short or long presses of 4 momentary push buttons, and sending an appropriate message over MQTT. The software detects "short" and "long" presses of each button. If you press and release in less time than a "long" press, then it is "short".

You set up a corresponding automation rule in Home Assistant to take action based on the incoming MQTT message. You can have different rules for long and short presses of each button.

Why build this?

I have a Home Assistant system running controlling the lighting in my flat. While the web UI for Home Assistant is excellent, sometimes it's handy to just have a button to press.

I already had most of the components to build this project, and so ... why not?

Hardware

My project is based on a Freetronics EtherTen board. I used this because I had a few lying around. It's an Arduino compatible board with Wiznet W5100 chip. The same sketch would work with any similar board.

I purchased 4 momentary push buttons. Essentially I just wanted something with a definite action. I ended up with these red and black buttons from Jaycar.

Connections

The sketch is designed to use 4 digital inputs with the inbuilt pullup resistors enabled. The buttons are wired to connect the digital input to ground when the button is pressed. In the photo the black wire is connected to ground.


The other connection for the buttons goes to a free digital input. Partly I chose ones that were a little bit apart so that I didn't need to put heat shrink on the pins, and partly because this board uses a couple of the inputs to talk to the ethernet hardware.

I used some breadboard connecting wires. I cut off one end and soldered the wires to the buttons, and the other end goes into the sockets on the Arduino. The wires used to have black insulating plastic around the pins, but I removed it so that they fit in the case.


The connections look like this:



The only other connections are power (micro-USB) and the ethernet cable.

Software

The Arduino sketch is included here. The README shows which part of the code should be configured to match your situation.

Want more or less buttons? No problem. Just choose pins, and also a bit mask (powers of 2).

Of course you need to configure;
  • The address of your MQTT server
  • The login and password for your MQTT server
  • The base topic that you will send updates on (this should match your automation script in Home Assistant)
  • The topic names for each button. (I use b1, b2, r1, r2)
  • How long you need to hold the button for to be a "long" press. I chose 1 second.
  • The topic that Home Assistant sends status updates on. Initially I thought I might use discovery, so I was watching for the startup message, but for momentary buttons, discovery actually makes it harder to configure.
  • If your board doesn't assign a MAC address, then you need to make one up. If it is written on the board, then use the appropriate one.
After startup, the software tries to connect to the MQTT server repeatedly if disconnected. Then it watches for button presses, and sends a payload of either "short" or "long" to the appropriate topic when you press the button.

Automation rules

On the Home Assistant side, set up an automation rule listening to the appropriate topic and payload. Your rule can do whatever you think is appropriate.

I have my buttons configured this way:
  • Short press of black 1 turns on one of the lounge lights.
  • Long press of black 1 turns on all the lounge lights.
  • Short press of red 1 turns off all the lounge lights.
  • Long press of red 1 turns off all lights.
etc

The automation rule will end up looking like this in your configuration.yaml

automation:
  - alias: Turn lounge lights 1 on when black 1 short pressed
    trigger:
      platform: mqtt
      topic: myhome/buttons/b1
      payload: short
    action:
      service: light.turn_on
      entity_id: group.loungelights1
  - alias: Turn all lounge lights on when black 1 long pressed
    trigger:
      platform: mqtt
      topic: myhome/buttons/b1
      payload: long
    action:
      service: light.turn_on
      entity_id: group.loungelights
  - alias: Turn off all lights when red 1 long pressed
    trigger:
      platform: mqtt
      topic: mhome/buttons/r1
      payload: long
    action:
      service: light.turn_off
      entity_id: group.all_lights



September 24, 2016

Wall rack for laptops - an Ikea hack

The need:

At work we have WiFi everywhere. If you go to a meeting you take your laptop with you. If you go to do some work at someone else's desk on another floor, you take your laptop with you. If you need the bathroom, well you will probably take your laptop with you, but where do you put it?

The solution:

Enter the Hack Rack.



Given an idea, a 24 hour company hack-a-thon, a team of keen hackers, we set out to design, build and install 13 laptop racks around the office.

This is a modified Ikea Spontan magazine rack. I'll cover some of the steps we took to make it.

We started with the base Spontan.


The Spontan is made of metal (with an enamel coating). While it is designed for magazines and newspapers, it is quite strong, and can hold a laptop fairly easily. One of the problems though is that the metal surfaces may scratch the body of our precious laptops. We needed a padding solution.

We want padding on the "inside" of the rack, so the part that you can't see. This must extend down to where the bottom edge of the laptop will rest.

We also need padding on some of the front facing surfaces, as the laptop will rest against these as well.

Enter Reverse Garbage. Reverse Garbage gets industrial discards that are useful for re-purposing. Perfect.

My first find was a roll of high density foam that is self adhesive on one side.


This is the edge of a larger sheet (presumably). The roll I picked was about 15cm wide, and several metres long. The white part is removed to reveal the self adhesive backing. We cut pieces of this to size, and stuck it on the "inside" surfaces of the rack.


For the front facing surfaces my first thought was to find some kind of thick fabric. I ended up with 3 great purchases from Reverse Garbage.

The first was an offcut of a roll of "event carpet". They had 3 colours (blue, pink and green) of which I grabbed some blue. The roll was about 2m x 4m, which set me back $10.


Next was a book of fabric samples for chairs. I figured we could cut up each sheet into 2 strips, which would make an interesting design. Here's are a couple.

 

Third was a sheet of polyurethane. These look like offcuts from making thongs (flip-flops). They are quite thin (2-3mm) but provide enough padding so that a laptop won't scratch.


Attaching the covering to the front facing surfaces ended up being more of a challenge than I had expected. I researched glues that would stick to metal, and 2 part epoxies like Araldite seemed to fit the bill.


The problem of course is that with 13 racks to build and mount in 24 hours, mixing up and applying a 2 part epoxy is going to take a lot of time.

We experimented with hot glue, but it didn't stick well to the rack.

We ended up getting some sandpaper and roughing up the front facing surfaces that needed padding, and then using the hot glue. I wasn't totally satisfied with the bond, but there won't be a lot of lateral pressure, so it should stick pretty well. I think if any need re-sticking I will use Araldite.


Of course beware that hot glue sets fairly fast. You need to glue in sections.

Here's our first prototype with the green polyurethane on the front.

 

The chair covering ended up being more fiddly than expected. I was quite proud of the finished product, but we only made one.


In the end the blue "event carpet" was our favourite.


I thought mounting the racks might be a challenge. The rack weighs about 1kg. With 3 laptops attached the total weight could be 5-8kg. We needed to attach the racks to plasterboard (drywall). On the advice of my good friend Mark I investigated various attachment strategies on YouTube. It seemed like some kind of toggle screw would be the best.



The toggle sits sideways inside the anchor screw. You screw this into the wall. It has a sharp point and is self drilling. Then you place whatever you want to mount in place, and screw in the holding screw. As the holding screw goes in, the toggle flips sideways inside the wall, and tightens against the inside of the wall. Each screw can hold 20kg, so more than enough for what I need.

All that's needed now is some testing...


And a label so that people know what these strange racks on the walls outside the company bathrooms are for...


So how did we do? For our hack-a-thon we were awarded the non-technical prize! Thanks heaps to Alex, Malcom, Ricardo and Yuting, and especially for Alex and her video production work for the presentation!

September 08, 2016

Thanks to Petersham Public School

Thanks to the year 4/5/6 students at Petersham who made me this fantastic thankyou present:

May 15, 2016

XBox retro games emulator part II

In this section I connect up the front panel socket for the game controller to a USB plug, so that it can plug in to the Raspberry Pi USB port.

For this I bought some USB plugs and some 4 conductor wire. The plugs have a little groove where you can solder the wire on. You can also get USB plugs with wires already attached, which might save you a soldering step. Note that normally USB cabling has red, black, green and white. I am using a telecoms cable here, so I will need to be careful with the colours.


With the wires soldered, it's time to assemble the plug. Remember that this end of the cable will connect the controllers to the USB port on the Pi. If you used a standard USB cable, make sure the correct colours go to the correct pins. (e.g. Check the Wikipedia page on USB.) For me, I just had to make a note of which colours I used, so that I can connect the other end of the cable easily.


Now for the other end of the cable. The ports for controllers 1 and 2 go to a common header that connected to the motherboard.





I am taking a gable here in guessing that the XBox does use the standard colours for USB cabling. As can be seen elsewhere, the yellow cable for the controller is not used for USB.

I cut the plug off here, stripped the red, black, green and white wires, put on some heat shrink tubing, and soldered the wires together. If your USB cable was standard colours, then connect red to red, black to black, green to green, and white to white. (Yellow is not connected.) Shrink the tubing over the solder joints to insulate it.


May 11, 2016

XBox retro games emulator part I

I wanted to build a retro gaming system. Simple enough idea. I have a spare Raspberry Pi lying around, so why not install RetroPie on it?

Again, simple enough, but of course games are not so easy to play using a keyboard. I really need some game controllers, as well as some kind of case for the Pi.

Why not get an old XBox? The controllers can interface to USB, it has a power supply, and plenty of room inside the case presumably.


Vky commented "So you're using the biggest console ever to house the smallest pc ever?" Like I said, plenty of room.

Opening up the case shows that it is full of all this XBox stuff though!


I'll need to get rid of some things. That hard disk can go for starters.


As can that DVD drive. What were they thinking?


There's still a big circuit board I don't need. Out it goes.

Actually the mounting brackets for those drives might be handy. They can go back in.


Now to put back the Xbox drive tray cover. 


Perfect.

Stand by for chapter II as I start to wire in the new bits.

September 20, 2015

Automatically adding your Jethro Roster/Rota assignments to your calendar


Do you find yourself coping your church roster assignments into your electronic calendar each month? Wouldn't it be handy if you could just subscribe to a feed for your roster assignments so that your calendar updated itself automatically?

This is a feature I have been working on in Jethro with Tom Barrett. Jethro can now publish your roster assignments as an iCal feed. Common electronic calendars can subscribe to this, so that your roster assignments update themselves in your calendar whenever the roster is updated.

This post will show you how to set it up. The latest version of Jethro supports this feature. If your church uses Jethro, you should check with your church administrator as to whether your church has this version. Easy Jethro now has this feature. CCIW uses Easy Jethro, and so I will use this as an example here.

Step 1. Log in to your Jethro member account.

For CCIW this is at https://cciw.easyjethro.com.au/members/

If your e-mail address is listed in Jethro (e.g. you get sent newsletters by e-mail) but have never used Jethro before, then you will need to create an account. Enter your e-mail address and click Create New Account. It will send you a link where you can set your password.

If Jethro doesn't know your e-mail address, maybe contact a staff member at your church to let them know so they can set it up for you.

Step 2. Check your Subscription settings

Once logged in you should see your roster assignments on the right, along with a new Subscribe link.


Click Subscribe to see your settings.

Step 3. Enable iCal

Clicking the Subscribe link will show whether you have this feature enabled, and if enabled, your unique URL for your roster assignments.
If you have not used this feature before it will be disabled. Click Enable iCal Feed to enable it. This will generate a unique URL you can use to subscribe to your roster assignments.

This URL is just for your roster assignments. Don't share it with anyone else.

Step 4. Subscribe your calendar to this URL

Did you just click the link to see what will happen? Possibly not what you expected (unless you tapped the link on your iPhone I think).

You need to check with your calendar software on the correct method to subscribe to an iCal calendar. Maybe Google this for the correct instructions. If you get stuck, leave a comment here and I can probably provide some tips. Some pointers:
  • Android. Log in to Google Calendars on the web. Click the drop down to the right of Other Calendars. Choose Add by URL. Enter your iCal link from Jethro there. If you want to see this calendar on your device, go to Settings in Calendar on the device, tap this calendar, and enable Sync.
  • iPhone/iPad. Probably just tap the iCal link in Safari on your iPhone or iPad. It will ask you if you want to subscribe.
  • Outlook on your desktop. You need to go into account settings and add an internet calendar. Paste the URL from Jethro and click Subscribe. Note that if you click the iCal link on your PC, it will offer to open it in Outlook. This is not the same as subscribing, as if you do it this way, Outlook won't periodically check for updates to your roster.

Step 5. Oh no! I published my calendar URL on the internets by mistake!

If you want to disable this feature, or simply change the URL, go back to the Manage Roster iCal Feed page, and click either Generate New URL, or Disable iCal feed.

The time seems wrong for my band or gardening roster? If the roster is tied to a particular service, the iCal feed lists the start time as the start time of the service. If the roster is not tied to a service, the iCal feed will show a whole day event on the day you are rostered. Sorry if band practice is on the previous Thursday for Sunday's service.

But I'm not rostered on anything? Have you thought about helping out at your church?

But I don't go to a church? It's great to meet together with other people that God loves. Maybe drop in on your local church one day and ask about it?

August 11, 2015

Cycling

A nice detour around Iron Cove on the way to work this morning.