GithubHelp home page GithubHelp logo

monzo-hass-sensor's Introduction

monzo-hass-sensor

A monzo sensor for Home Assistant. Currently this can be used to show your current balance as a sensor.

Installation

To install this component into HASS copy the monzo.py file into a folder called /custom_components/monzo/ in your config directory (typically ~/.homeassistant), then add the following config:

sensor:
  - platform: monzo
    client_id: '***CLIENT ID***'
    client_secret: '***SECRET***'
    name: 'Optional name for the sensor'
    cache_path: '/.homeassistant/.optional-cache-location-for-token'
    current_account: true # only if you the current account

Set current_account true only if you have the Monzo current account.

To get a client ID, and secret go to https://developers.monzo.com/apps/home and click "+ New OAuth Client". Ensure you have set the confidentiality to "Confidential", and set the redirect url to http://ip-of-hass:8123/api/monzo

If you want to use the sensor with multiple accounts ensure you have added all the users to the "collaborators" in the OAuth client registration with monzo, and configure a differant location for the cache_path in hass.

Known Issues:

If you have issues logging into monzo as part of the linking to Home Assistant check the redirect part of the query string (in the address bar) matches the oAuth client you setup on Monzo. Often this just looks like the "submit" button isn't working.

After logging in to Monzo by clicking on the email your browser will download a 0 byte file called "monzo". You do not need this and it's safe to delete it.

Let me know how you get on!

monzo-hass-sensor's People

Contributors

rossdargan avatar stealthcopter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

monzo-hass-sensor's Issues

Incompatible

Hey,

is there any vision to getting this working on the new Home Assistant versions?

Doesn't currently seem to be working :(

Authentication

As stated in the Home Assistant discussion, there's a lot of hit and miss with the authentication. Putting it here so you can track the issue :P

Cleanup

I've posted a few issues now haha! Sorry!

One of the biggest is probably cleanup, you've got a lot of dependencies and it's been pulled from so many places, I'm not sure of the source anymore, perhaps you could compile only the necessary parts into your own single git?

ModuleNotFoundError

Hey Ross great work on this one, im trying to setup this sensor and followed the steps, the sensor load though it has not values and i could see the below errors on the logs :(

HashIO version 93.2

sensor.monzoaccount unknown spend_today: null

Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 220, in async_update_ha_state
await self.async_device_update()
File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 377, in async_device_update
await self.hass.async_add_executor_job(self.update)
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/monzo/sensor.py", line 303, in update
self.refresh_monzo_instance()
File "/config/custom_components/monzo/sensor.py", line 237, in refresh_monzo_instance
import monzo.monzo # Import Monzo Class
ModuleNotFoundError: No module named 'monzo'

Found another version of the script at :
home-assistant/core#17218
though it seems that never happened.

Thanks in advance for the help

cheers
Stelios

No Balance Refresh/Update

I Had someone deposit £30 into my account this morning however there's no balance update on Home Assistant - My balance showing in Home Assistant is the same as when I restarted Home Assistant last night.

Restarted Home Assistant - Back to configuration screen? I'm at work so I'll have a look when I'm home to try and see why this is.

Proposed Structure

I think it should be more modular and able to show many accounts upon request. This structure is simply an idea, even better if you can customise the Name for each one then you can set up the whole family and monitor accounts. "John Monzo", "Becky Monzo", "Barry Monzo", "Jane Monzo" all linking to their respective accounts and can be added to their own groups/views.

sensor:

  • platform: monzo
    client_id: oauthclient_XXXXXXXXXXXXXXXXXXX
    client_secret: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    name: 'Monzo'
    accounts:
    • acc_000xxx000xxx000xxx000 (1)
    • acc_111xxx111xxx000xxx000 (2)

This could then create a new sensor for every account shown, this should also have the "state" set to the monetary value.(Explained Below)
Sensors that should be generated upon launching Home Assistant & Potential Layout inside dev-state page.

- Entity: **sensor.monzo_1.balance**
- State: 25.72
- Attributes:
- - unit_of_measurement: £
- - icon: mdi:credit-card
- - friendly_name: John: Balance

- Entity: **sensor.monzo_1.spent_today**
- State: 4.20
- Attributes:
- - unit_of_measurement: £
- - icon: mdi:credit-card
- - friendly_name: John: Spent Today



- Entity: **sensor.monzo_2.balance**
- State: 5.23
- Attributes:
- - unit_of_measurement: £
- - icon: mdi:credit-card
- - friendly_name: Becky: Balance

- Entity: **sensor.monzo_2.spent_today**
- State: 2.00
- Attributes:
- - unit_of_measurement: £
- - icon: mdi:credit-card
- - friendly_name: Becky: Spent Today



- Entity: **sensor.monzo_2.transactions**
- State: 5 (How many it has generated (Max 5?))
- Attributes:
- - unit_of_measurement: transactions
- - icon: mdi:receipt
- - friendly_name: Becky: Transactions
1: Asda - £2.00 - 2016-02-05 20:12:26
1: Tesco - £12.50 - 2015-03-28 05:35:28

Transactions could potentially be split into their own sensor so they can be put on a card/group and then have their respective icon showing.

Account ID

Currently this is getting the Account_ID by the first ID inside the return from Monzo. For most of us, this will return the prepaid card.

A simple solution to allow current accounts would be to select the second in the list, however this then means it's not viable for when they phase out prepaid cards or, when new people only have one account.

I propose making this more modular to allow people to add as many accounts as they need by setting up Monzo platform.

I managed to get my current account balance showing by changing the following which obviously isn't permanant just so I knew where it was requesting the account from:

  • Old: balance = self._client.get_balance(self._account_id)
  • New: balance = self._client.get_balance('acc_000xxx000xxx000xxx000')

This means that the account can be easily passed through an extra variable in the config.

  • account_id: acc_000xxx000xxx000xxx000

Compatibility with HACS

Hi there.

Bit of a feature request, but would it be possible to add the necessary layout/files to make this repo compatible with HACS please?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.