timmo001 / ovoenergy

Get energy data from OVO's API.
https://timmo.dev
Apache License 2.0
30 stars 16 forks source link

Add payment/billing support #22

Closed deosrc closed 2 years ago

deosrc commented 3 years ago

Description

I use the ovo integration in Home Assistant (many thanks btw). The portal also includes payment and billing information. I think this would be a great addition in order to see how much your account is in debit/credit by.

Suggested Actions

Add sensor for account balance.

Additional

From the browser dev tools, this seems to be the request to grab the latest billing period. The account balance seems to be the closingBalance

POST https://smartpaymapi.ovoenergy.com/bast/api/graphql

{
    "query": "\nfragment FuelFields on BillingFuel {\n  consumption {\n    rates {\n      rate {\n        pence\n      }\n      cost {\n        pounds\n      }\n      kwh\n      openingRead\n      openingReadType\n      intermediateReads {\n        date\n        read\n        readType\n      }\n      closingRead\n      closingReadType\n      startDate\n      endDate\n      friendlyLabel\n    }\n  }\n  standing {\n    netCharge {\n      pounds\n    }\n    rates {\n      rate {\n        pence\n      }\n      startDate\n      endDate\n      days\n    }\n  }\n}\n\nfragment PeriodFields on SelectedPeriod {\n  next\n  previous\n  data {\n    electricity {\n      ...FuelFields\n    }\n    gas {\n      ...FuelFields\n    }\n    upgrades {\n      description\n      grossCharge {\n        pounds\n      }\n      initialGrossCharge {\n        pounds\n      }\n      startDate\n      endDate\n      taxRate\n    }\n    transactions {\n      description\n      netCredit {\n        pounds\n      }\n      taxRate\n    }\n    payments {\n      date\n      description\n      credit {\n        pounds\n      }\n    }\n    start\n    openingBalance {\n      pounds\n    }\n    end\n    closingBalance {\n      pounds\n    }\n    totalCharge {\n      grossCharge {\n        pounds\n      }\n      netCharge {\n        pounds\n      }\n      vatCharge {\n        pounds\n      }\n    }\n    energyCharge {\n      pounds\n    }\n    isStatementAvailable\n  }\n}\n\nquery Period($id: String!, $index: Int!) {\n  billingSummary(id: $id) {\n    lastUpdated\n    billablePeriod(periodIndex: $index) {\n      ...PeriodFields\n    }\n  }\n}\nquery LatestPeriod($id: String!) {\n  billingSummary(id: $id) {\n    lastUpdated\n    latestPeriod {\n      ...PeriodFields\n    }\n  }\n}",
    "operationName": "LatestPeriod",
    "variables": {
        "id": "<account_id?>"
    }
}

Example response (values redacted):

{
    "data": {
        "billingSummary": {
            "lastUpdated": "2021-07-05T04:23:18.983991Z",
            "latestPeriod": {
                "next": null,
                "previous": 30,
                "data": {
                    "payments": [],
                    "upgrades": [],
                    "openingBalance": {
                        "pounds": "00.00" // Redacted
                    },
                    "gas": {
                        "consumption": {
                            "rates": [
                                {
                                    "rate": {
                                        "pence": "00.00" // Redacted
                                    },
                                    "endDate": "2021-07-04",
                                    "intermediateReads": [],
                                    "closingRead": "00.00", // Redacted
                                    "kwh": "00.00", // Redacted
                                    "openingRead": "00.00", // Redacted
                                    "closingReadType": "SmartReading",
                                    "openingReadType": "SmartReading",
                                    "cost": {
                                        "pounds": "00.00" // Redacted
                                    },
                                    "friendlyLabel": "Anytime",
                                    "startDate": "2021-07-01"
                                }
                            ]
                        },
                        "standing": {
                            "netCharge": {
                                "pounds": "00.00" // Redacted
                            },
                            "rates": [
                                {
                                    "rate": {
                                        "pence": "00.00" // Redacted
                                    },
                                    "startDate": "2021-07-01",
                                    "endDate": "2021-07-04",
                                    "days": 4
                                }
                            ]
                        }
                    },
                    "totalCharge": {
                        "grossCharge": {
                            "pounds": "00.00" // Redacted
                        },
                        "netCharge": {
                            "pounds": "00.00" // Redacted
                        },
                        "vatCharge": {
                            "pounds": "00.00" // Redacted
                        }
                    },
                    "energyCharge": {
                        "pounds": "00.00" // Redacted
                    },
                    "end": "2021-07-31",
                    "closingBalance": {
                        "pounds": "00.00" // Redacted
                    },
                    "isStatementAvailable": false,
                    "start": "2021-07-01",
                    "electricity": {
                        "consumption": {
                            "rates": [
                                {
                                    "rate": {
                                        "pence": "00.00" // Redacted
                                    },
                                    "endDate": "2021-07-04",
                                    "intermediateReads": [],
                                    "closingRead": "00.00", // Redacted
                                    "kwh": "00.00", // Redacted
                                    "openingRead": "00.00", // Redacted
                                    "closingReadType": "SmartReading",
                                    "openingReadType": "SmartReading",
                                    "cost": {
                                        "pounds": "00.00" // Redacted
                                    },
                                    "friendlyLabel": "Anytime",
                                    "startDate": "2021-07-01"
                                }
                            ]
                        },
                        "standing": {
                            "netCharge": {
                                "pounds": "00.00" // Redacted
                            },
                            "rates": [
                                {
                                    "rate": {
                                        "pence": "00.00" // Redacted
                                    },
                                    "startDate": "2021-07-01",
                                    "endDate": "2021-07-04",
                                    "days": 4
                                }
                            ]
                        }
                    },
                    "transactions": []
                }
            }
        }
    }
}
github-actions[bot] commented 2 years ago

There hasn't been any activity on this issue recently, so we clean up some of the older and inactive issues. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thanks!