AccountRight meets IoT

There is a lot of talk lately about the Internet of Things (IoT) where things around us become internet connected, able to sense changes or do something or alert us to activity. Not long ago internet-connected items used to be the story of folk lore living firmly in the hands of hard core developers.

Today that’s changing with more consumer products connected to the internet, the cost and size of hardware dropping radically, and many open source libraries enabling developers to connect to them.

Fascinated by this space I recently bought myself a set of Philips Hue lamps. If you are unaware, Hue lights are wifi connected smart lights, that you can control from your iPhone or services like IFTTT.

I saw an opportunity here … What if you had a desk lamp that could alert you when some specific behaviour happened in your MYOB AccountRight file? Maybe a new bill was uploaded via SmartBills? Maybe a customer just settled an invoice? What about a new sale? There could be a range of activity that happening in MYOB AccountRight which could do with some soft way of notifying you - without disrupting your flow.

The video above shows a lamp at home, which starts out a nice bright white, then after receiving a payment on an outstanding invoice, it changes to pink, pulses for 30 seconds and then resumes white (well it would but I stopped the video)

So how hard was this to do? Surprisingly it’s actually really quite easy. You do need to have the computer running the script on the same network as your lights (Philips are working on a remote api) - for me that was easy, I’m running PHP locally on my Mac. My script is talking to AccountRight in the cloud, however it is talking to my lights over the local network.

Lets look at how I am getting the updates from AccountRight. As I only want updates (not the full details), I’m going to use the /GeneralLedger/JournalTransaction (MYOBApi docs) to get these. Almost every activity going through the accounts updates the journal transaction making it a great place to easily check for updates & changes to AccountRight.

For example I can quickly check for the following items:

  • Bill
  • Invoice
  • SupplierPayment
  • CustomerPayment
  • SpendMoneyTxn
  • ReceiveMoneyTxn
  • TransferMoneyTxn
  • GeneralJournal
  • InventoryAdjustment
  • CreditRefund
  • CreditSettlement
  • DebitRefund
  • DebitSettlement

by simply filtering the URL like this

GeneralLedger/JournalTransaction/$filter=SourceTransaction/TransactionType eq ’CustomerPayment’ and DatePosted gt datetime'2015-03-16T21:36:32  

where CustomerPayment is the item you want to look for - the DatePosted filters based on the last time I made this call.

Performing that call gives me the latest CustomerPayment to be updated into AccountRight. Now all I need to do is to ‘poll’ that endpoint see if it changes, and simply change the DatePosted time to the last time I called.

So now I have a script that checks the API looking for new customer payments - a script that is light touch and fast, and only returns data IF something changed (in this case, that change is a new customer payment).

Now that we have updated activity, lets play with some lights.

Philips provide developers with a great API over at meethue.com. The base unit that controls the lights actually includes a web server and a tool that lets you explore your lights and the API calls to change them. You can learn about that over at their getting started guide.

Turns out updating the lights is super easy. You need to know the IP address of your base station, and you need to register a user with your base station (all covered on the getting started guide).

Once you know those things you simply PUT a set of JSON data to the API running on your base unit. For me the URL I called was http://IPADDRESS/api/USER/lights/2/state - that’s the url for updating the state of light number 2 on my base station.

The JSON I passed over to the API was {“on”:true,“bri”:255,“sat”:255,“hue”:56100,“alert”:“lselect”} which sets the light to on, the brightness and saturation to full, the hue to pink and the “alert” item tells it to breathe (pulse) for 30 seconds then remain steady after that.

It really is that simple, just PUT that JSON to the local api and the light turns on and pulses for 30 seconds.

Right now I have my script polling activity in AccountRight and if a customer pays me (or I fake it in AccountRight) the light beside me pulses gently. It surprised me how easy that was to do. Of course I didn’t stop there, I actually have the script checking ALL the items listed above and changing colours based on the activity (probably overkill, but it was fun!).

So what will you connect our MYOBapi up to now that IoT is becoming so much easier for people to do?