Monzo bank integration

I’ve created a sensor for Monzo (a bank with an api…). Currently it’s just a sensor that tells you how much is in your account. Hopefully I’ll add more features that people want.

I’d love to get some testers on board, so if you use Monzo take a look at my repo here: https://github.com/rossdargan/monzo-hass-sensor/

Note this probably only works for the cash cards, and not current accounts at the minute.

Please let me know if you use it, and what you have done with it (as well as any feature requests!)

6 Likes

Hi,

thanks for creating this!

trying to set up but cannot get past the configurator screen. here is my code.

sensor:
  - platform: monzo
    client_id: 'my_client_id'
    client_secret: 'my_client_secret'
    name: 'monzo-hass-sensor'
    cache_path: '/.homeassistant/cache'

monzo.py is saved in /custom_components/sensor/

when I restart hass the configurator shows up in the ui asking to authorise the app, this then takes me to a webpage asking to authorise the app, then I receive an email with a link that downloads a file called ‘monzo’

When i then click “I authorized successfully” nothing happens

Do I need to put this file called ‘monzo’ somewhere?

That should be enough! Can you have a look in your config directory and see if there is a file that looks like “.monzo-cache-token”

Hi,

I thought maybe because i’m using docker the cache_path might not be correct so have commented this line out & restarted

I now get the sensor showing but with value “unknown” (the configurator has gone now too)

file named “.monzo-cache-token” is also showing up - so i must be nearly there!!

Ah fab. Is it showing up now (it takes maybe a minute to show up, but it should be there now!)? If not can you check the logs?

docker logs home-assistant --tail 10000 2>/dev/null | grep monzo

that might be the easiest way!

Here’s something from the logs…(still “unknown”)

2017-09-14 20:39:28 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.monzo_hass_sensor fails
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/entity.py", line 225, in async_update_ha_state
    yield from self.hass.async_add_job(self.update)
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 332, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
    future.result()
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/sensor/monzo.py", line 277, in update
    self.refresh_monzo_instance()
  File "/config/custom_components/sensor/monzo.py", line 232, in refresh_monzo_instance
    import monzo.monzo  # Import Monzo Class
ModuleNotFoundError: No module named 'monzo'

odd. Thought I’d fixed that.

Try running this

sudo pip install monzo==0.5.3 --target ~/.homeassistant/deps

where the .homeassistant folder is your config folder (on the host)

Not sure if I can run that command as I use docker on a synology, and don’t know how to do it!

Edit: this is odd, I have just commented out my client_id & client_secret and restarted hass and now the sensor is showing the correct value

Cheers,
James

Eh?!

OK… to be honest you really shouldn’t need that command. You will however need your client_id and secret so put it back in (it uses it to refresh the authentication token).

Honestly I suspect the reboot fixed it.

Just removed all traces of the code then recreated the oauth token and it worked without a hitch!

Must have been a glitch somewhere along the line

Good work!

1 Like

Hello,
Looks great and I can’t wait to use it. In your readme file, at the bottom, you talk about the submit button issue. I don’t suppose you could elaborate please? I know I have signed into it once before but I have never been able to get back in!

Thanks,
Sam

When you click the submit button it just does nothing (it puts an error in the javascript console if you know how to find it!)

Is that what you are seeing?

exactly what I’m seeing. However, I have just returned to it today and its let me through to the developer console finally! I have made my OAuth client and added my config to home assistant. the configurator now won’t let me authenticate my new OAuth bit. its now saying ive had too many attempts. even though its my first try !

Failed to load resource: the server responded with a status of 429 (Too Many Requests)

Thanks for replying

I saw somebody else have this issue. They said after trying again a little later it just worked… monzo are quite clear that it’s not ready from prime time… a good example I suppose!

Perfect I’ll just wait it out and see what happens. I’ll repost here if things resolve with time just in case anybody else sees this thread

Do you know what, if anything, will need to be done to support current accounts.
(Just got mine).

I’ve heard the 3rd party python library I’m using needs a change. I’ve applied for a card and I’m hoping I’ll get in soon so I can fix it!

Here is the update as promised. Some time last night it just started working flawlessly! all up and running. thanks !

I’m having an issue with authentication? Probably me doing something stupid haha, however every time I try to “Link Monzo account” I link it and when I press “I AUTHORISED SUCCESSFULLY” I simply get a duplication of “Monzo Balance CONFIGURE”, Don’t suppose you could help haha?
image

I was going to ATTEMPT a component, but I’m glad to see you’ve already started haha, I’ll help where I can as it’s something I was willing to try myself.

I’m also glad to see someone else from Monzo in Home-Assistant :smiley:

Here’s a redacted screenshot of the accounts I see :wink:
image


Limited to three posts… @rossdargan

Nope, it doesn’t seem to be generating the cache file.
And yep, I clicked the link and it downloaded the file which I discarded and clicked AUTHORISED and it then duplicated the Configurator as shown above.


Not sure what i did, but I’m now seeing the sensor haha! My have been me removing the ’ ’ around the client ID and


Ideas:
sensor.monzo_balance
sensor.monzo_spendtoday

sensor.monzo_transactions (latest 5 or something)
name: Merchant
State: Spent there
indead of mdi, you can get the PNG from the API as the icon.

I managed to get my current account balance showing simply by physically putting my current account ACCOUNT_ID

Could be easily modified to allow another config variable, unless you find a better way to get the current account ID, as when the prepaid cards go out it would essentially become account1 rather than currently account2

    balance = self._client.get_balance('acc_0000000XXXXXXXXX00000000') # Get your balance object