Giter VIP home page Giter VIP logo

stromnetzgraz's Introduction

Python client library for Stromnetz Graz API

PyPI package version number License

This is a simple client library for the (unofficial) Stromnetz Graz Smart Meter Web API.

Please note that you must be able to login and view data on the portal before this library will work. Please refer to Stromnetz Graz how to set up access to the smart meter statistics. Best results are achieved in the IME mode (15 minute reading intervals), however the library can also fall back to IMS (daily reading interval). The most recent data available will be the one for the previous day (see also their FAQ).

Example

from sngraz import StromNetzGraz

sn = StromNetzGraz(mail, password)
await sn.authenticate()
await sn.update_info()

for installation in sn.get_installations():
    print("Installation ID", installation._installation_id)
    print("Installation is installed at", installation._address)
    for meter in installation.get_meters():
        print("Meter ID", meter.id)
        print("Meter Name", meter._short_name)
        await meter.fetch_consumption_data()

        # meter._data now contains the meter readings of the last 30 days
        print(meter._data)

await sn.close_connection()

The example needs to run in an async context, please see issue #6 for an example if you want to run it standalone.

An installation is usually an house or apartment with an individual address and may contain multiple meters (for example a second meter for a hot water boiler). A meter is the actual single meter.

Stromnetz Graz assigns individual numerical IDs to both installations and meters. The usually used meter number (33 characters usually starting with AT00) is available as attributes (meter._name & meter._short_name).

Home Assistant Integration

This library is used in my Home Assistant Custom Component ha-stromnetzgraz, available via HACS. It allows you to have your Smart Meter readings inside Home Assistant! See the ha-stromnetzgraz repository for more details.

stromnetzgraz's People

Contributors

dreautall avatar notz avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

notz

stromnetzgraz's Issues

Feature Request: Home-Assistant Integration

I just discovered your client library, and it works wonderful with my user data.

I would love to have that data available in Home-Assistant, the software for home automation.
Maybe you already have a WIP of some kind of Data-Logger already in use?

If nothing like that exists yet, I would be very interested to develop something.
It looks pretty easy to add Python Scripts to the Home-Assistant.

https://www.home-assistant.io/integrations/python_script

FirstReading fails with with ContentTypeError (API Request rejected)

On my smart meter installation the first reading request seems to fail all the time, because of my readings available since.

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/sngraz/sngraz.py", line 107, in _query
    result = await resp.json()
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 1103, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8', url=URL('https://webportal.stromnetz-graz.at/api/getMeterReading')

My reading available since is:

readingsAvailableSince: 2022-04-12T12:49:00

If i correctly understand your code that the first reading makes following requests:

Opt-In

{
 "meterPointId": xxx,
 "fromDate": "2022-04-12T12:49:00.000+01:00",
 "toDate": "2022-04-19T12:49:00.000+01:00",
 "interval": "QuarterHourly",
 "unitOfConsump": "KWH"
}

Which fails with error request rejected. If i change the time to 12:00 or 12:45 the request succeeds.

I opted in yesterday, but had the same problem before with "Opt-Middle". But i can't reproduce the error in this case, because the requests are working:

{
 "meterPointId": xxx,
 "fromDate": "2022-04-12T12:49:00.000+01:00",
 "toDate": "2022-04-19T00:00:00.000+01:00",
 "interval": "Daily",
 "unitOfConsump": "KWH"
}

login failed but user/pw are correct

hi,

thx for your awesome library!

it seems i've a hard time getting it to work, i always get "login failed" even with the correct user/pw.

with the example code i get

  File "/home/user/.cache/pypoetry/virtualenvs/stromnetz-graz-cli-oyNzUIS4-py3.11/lib/python3.11/site-packages/sngraz/sngraz.py", line 155, in authenticate
    raise Exception("login failed")
Exception: login failed

But email/pw is correct, when i print out the token in function authenticate:152 i get

jwt.decode('e...Q', options={"verify_signature": False, "verify_exp": True})
{'email': MY_EMAIL, 'iat': 1681232478, 'exp': 1681318878}

if i simply remove the self.ok check in authenticate:153 i get

Error connecting to API, response code 401

any idea what could be wrong?

sw version from pyprojects.toml

[tool.poetry.dependencies]
python = "^3.11"
aiohttp = "^3.8"
jwt = "^1.3"
stromnetzgraz = "^0.1.5"

resolved dependencies

aiohttp            3.8.4  Async http client/server framework (asyncio)
aiosignal          1.3.1  aiosignal: a list of registered asynchronous callbacks
async-timeout      4.0.2  Timeout context manager for asyncio programs
attrs              22.2.0 Classes Without Boilerplate
cffi               1.15.1 Foreign Function Interface for Python calling C code.
charset-normalizer 3.1.0  The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet.
cryptography       40.0.1 cryptography is a package which provides cryptographic recipes and primitives to Python developers.
frozenlist         1.3.3  A list-like structure which implements collections.abc.MutableSequence
idna               3.4    Internationalized Domain Names in Applications (IDNA)
jwt                1.3.1  JSON Web Token library for Python 3.
multidict          6.0.4  multidict implementation
pycparser          2.21   C parser in Python
stromnetzgraz      0.1.5  Python client library for Stromnetz Graz API
yarl               1.8.2  Yet another URL library

Example not working anymore

The example is not working anymore with new python3...It took me a while to figure out new syntax.
If someone needs...or maybe @dreautall you update example:

#!/usr/bin/env python3

import asyncio, aiohttp
from src.sngraz import StromNetzGraz


async def get_sngrazdata():
  print("Starting sngraz...")
  sn = StromNetzGraz('email', 'password')
  await sn.authenticate()
  await sn.update_info()

  for installation in sn.get_installations():
    print("Installation ID", installation._installation_id)
    print("Installation is installed at", installation._address)
    for meter in installation.get_meters():
        print("Meter ID", meter.id)
        print("  Meter Name", meter._short_name)

        await meter.fetch_consumption_data()
        # meter._data now contains the meter readings of the last 30 days
        print(meter._data)

  await sn.close_connection()
  print("End sngraz...")

if __name__ == "__main__":
  loop = asyncio.get_event_loop()
  loop.run_until_complete(get_sngrazdata())

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.