Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Most sensors do not populate #3

Open
elstevega opened this issue Jan 25, 2024 · 17 comments
Open

Most sensors do not populate #3

elstevega opened this issue Jan 25, 2024 · 17 comments

Comments

@elstevega
Copy link

The only sensor that is retrieving data from Monarch Money is 'Net Worth'. All the others are coming back as 0.

@konecnyna
Copy link

konecnyna commented Jan 27, 2024

I've got the same issue.

I made a quick script to test monarch money portion of the code (not sure how you properly test a home assistant sensor in isolation) and it returns all the expect data. Still trying to narrow it down but looks right now it seems like a sensor write issue.

from monarchmoney import MonarchMoney
mm = MonarchMoney()


ATTR_ASSETS = "ASSETS"
ATTR_LIABILITIES = "LIABILITIES"

ATTR_BROKERAGE = "Investments"
ATTR_CREDIT = "Credit Cards"
ATTR_DEPOSITORY = "Cash"
ATTR_LOAN = "Loans"
ATTR_OTHER = "Other"
ATTR_REAL_ESTATE = "Real Estate"
ATTR_VALUABLE = "Valuables"
ATTR_VEHICLE = "Vehicles"
ATTR_OTHER_ASSET = "Other Assets"
ATTR_OTHER_LIABILITY = "Other Liabilities"
SENSOR_TYPES_GROUP = {
    ATTR_BROKERAGE: {
        "type": "brokerage",
        "group": ATTR_ASSETS,
        "icon": "mdi:chart-line",
    },
    ATTR_CREDIT: {
        "type": "credit",
        "group": ATTR_LIABILITIES,
        "icon": "mdi:credit-card",
    },
    ATTR_DEPOSITORY: {"type": "depository", "group": ATTR_ASSETS, "icon": "mdi:cash"},
    ATTR_LOAN: {"type": "loan", "group": ATTR_LIABILITIES, "icon": "mdi:bank"},
    ATTR_OTHER: {"type": "other", "group": "OTHER", "icon": "mdi:information-outline"},
    ATTR_REAL_ESTATE: {"type": "real_estate", "group": ATTR_ASSETS, "icon": "mdi:home"},
    ATTR_VALUABLE: {
        "type": "valuables",
        "group": ATTR_ASSETS,
        "icon": "mdi:treasure-chest",
    },
    ATTR_VEHICLE: {"type": "vehicle", "group": ATTR_ASSETS, "icon": "mdi:car"},
    ATTR_OTHER_ASSET: {
        "type": "other_asset",
        "group": ATTR_ASSETS,
        "icon": "mdi:file-document-outline",
    },
    ATTR_OTHER_LIABILITY: {
        "type": "other_liability",
        "group": ATTR_LIABILITIES,
        "icon": "mdi:account-alert-outline",
    },
}

def balances(accounts, category): 
    account_type = SENSOR_TYPES_GROUP[category]["type"]
    account_data = {}

    sensor_type_accounts = [
        account
        for account in accounts
        if account.get("type").get("name") == account_type
    ]

    for account in sensor_type_accounts:
        institution = None
        try:
            institution = account.get("credential").get("institution").get("name", "")
        except AttributeError:
            pass

        account_data[account.get("id", "")] = {
            "id": account.get("id", ""),
            "name": account.get("displayName", ""),
            "balance": account.get("displayBalance", ""),
            "account_type": account.get("type").get("name", ""),
            "institution": institution,
        }
    sensor_type_accounts_sum = round(
        sum(
            sensor_type_account["displayBalance"]
            for sensor_type_account in sensor_type_accounts
        )
    )
    print(category)
    print(sensor_type_accounts_sum)
    #print(account_data)
def net_worth(accounts):
    print("=======================")
    print("Net worth")
    print("=======================")
    
    active_accounts = [
        account for account in accounts if account["includeInNetWorth"] is True
    ]

    asset_accounts = [
        account
        for account in active_accounts
        if account["isAsset"] is True
        # and account["type"]["name"] in ASSET_ACCOUNT_TYPES
    ]
    liability_accounts = [
        account
        for account in accounts
        if account["isAsset"] is False
        # and account["type"]["name"] in LIABILITY_ACCOUNT_TYPES
    ]

    asset_accounts_sum = round(
        sum(asset_account["displayBalance"] for asset_account in asset_accounts)
    )
    liability_accounts_sum = round(
        sum(
            liability_account["displayBalance"]
            for liability_account in liability_accounts
        )
    )

    active_accounts_sum = asset_accounts_sum - liability_accounts_sum

    print(active_accounts_sum)
    print(asset_accounts_sum)
    print(liability_accounts_sum)

async def login_to_monarch(email, password):
    await mm.login(email, password)
    data = await mm.get_accounts()
    accounts = data["accounts"]
    net_worth(accounts)
    categories = SENSOR_TYPES_GROUP.keys()
    
    print("=======================")
    print("Balances")
    print("=======================")
    for category in categories:
        balances(accounts, category)

    
    
import asyncio

EMAIL=""
PASSWORD=""
asyncio.run(login_to_monarch(EMAIL, PASSWORD)) 

@elstevega
Copy link
Author

Thanks for looking into this - curious to see what you find.

@sanghviharshit
Copy link
Owner

The default update interval is 1 hour. Can you check if it updates in 1 hour or not?

@konecnyna
Copy link

konecnyna commented Jan 30, 2024

I've changed it between 30mins and 1hr doesn't seem to change the sensor. The state doesn't seem to persist either when I alter the settings but i suspect that might be an artifact of HACs or HA.

It's strange be because the net worth sensor is accurate and updates but all other sensors are 0.

Running:

Core 2024.1.5
Supervisor 2023.12.1
Operating System 11.4

@TBTHEDBA
Copy link

TBTHEDBA commented Feb 2, 2024

Also having the same issue.

@itzalgd24
Copy link

Just installed and having the same issue. All 0's except Net Worth.

@elstevega
Copy link
Author

I'm wondering if there is a problem with the repo? Downloading through HACs does not bring back the most recent code changes made two weeks ago. If I download the whole repo and drop it in HA I get a 'failed to initialize' error.

If I just selectively use the latest sensor.py, config_flow.py & update_coordinator.py the integration initializes but then again, all sensor except net_worth are 0.

@sanghviharshit
Copy link
Owner

HACS expects we publish a new release in github, I just did that. See if you can pull latest release and if it fixes the issue

@elstevega
Copy link
Author

Completely deleted the integration & started over in HACs. Looks like it grabbed the 0.0.2 release, which is good, however now it's caught in loop of "Failed setup, will retry" & "Initializing". Nothing in the log.

@konecnyna
Copy link

Same issue as @elstevega

1 similar comment
@ZarielZariel
Copy link

Same issue as @elstevega

@elstevega
Copy link
Author

elstevega commented Feb 14, 2024

Ok - some updates:
In sensor.py starting at line 313, comment these lines out & then add:
'# c = cashflow.get("summary")[0]

'# self._state = c.get("summary").get("savings")
'# self._income = c.get("summary").get("sumIncome")
'# self._expenses = c.get("summary").get("sumExpense")
'# self._savings = c.get("summary").get("savings")
'# self._savings_rate = c.get("summary").get("savingsRate") * 100

    self._income = 0
    self._expenses = 0
    self._savings = 0
    self._savings_rate = 0

and in update_coordinator.py comment out lines 109-110
'# cashflow = await self._api.get_cashflow()
'# data["cashflow"] = cashflow

Seems Monarch doesn't like the get_cashflow() API call

Now I'm getting data for Cash, Credit, Net Worth & Vehicles.
Expense, Income & Cash Flow are unknown

Monarch Loans, Monarch Other, Monarch Other Assets, Monarch Other Liabilities, Monarch Real Estate, Monarch Valuables are all still $0.00 - but that may be correct as I don't have any data that fits those categories. (edit: not true as I have a ton of investment accounts - not sure which bucket they should be in...)

@sanghviharshit
Copy link
Owner

Can you please update to the latest release (0.0.3) and report if it's still an issue?

@konecnyna
Copy link

It works! Thank you!

@TBTHEDBA
Copy link

TBTHEDBA commented Jun 30, 2024 via email

@cowboyrushforth
Copy link

Just installed, same thing, most sensors do not update.

I have installed 0.0.3, but:

"version": "0.0.1",

Is still listed in the manifest.json. I notice even in the source code, that this is set to 0.0.1, for the 0.0.3 tag.

@cowboyrushforth
Copy link

cowboyrushforth commented Sep 25, 2024

Also I think I figured out why part of it was not updating.

In Monarch one of my accounts had a question mark. I deleted it from Monarch and many more sensors are populated.

Screenshot 2024-09-25 at 5 02 24 PM

however the "investments" is still "Unknown", but in Monarch there is money in ithere, and no zero or question mark accounts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants