Metadata-Version: 2.4
Name: elvia
Version: 0.1.0
Summary: Python bindings for the Elvia API
Home-page: https://github.com/andersem/elvia-python
Author: Anders Emil Salvesen
Author-email: andersems@gmail.com
License: MIT
Project-URL: Bug Tracker, https://github.com/andersem/elvia-python/issues
Project-URL: Documentation, https://github.com/andersem/elvia-python
Project-URL: Source Code, https://github.com/andersem/elvia-python
Keywords: electricity
Classifier: Development Status :: 1 - Planning
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aiohttp>=3.8.1; python_version >= "3.4"
Requires-Dist: typing_extensions>=3.10; python_version >= "3.0"
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: project-url
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# Unofficial API bindings for Elvia's consumer facing APIs

![Build Status](https://github.com/andersem/elvia-python/actions/workflows/ci.yml/badge.svg)

With the Elvia API you can access information about your own power consumption and get the
current grid tariffes in Elvia's power grid.

## Installation

Install from pip by using:

```
pip install --upgrade elvia
```

### Requirements

- Python 3.6+

## Getting access tokens

Elvia's APIs are available for consumers using Elvia for their grid fees (nettleie).

The MeterValue and GridTariff APIs uses different authentication methods, and different tokens.

### Meter Value API

Get token using this guide: https://www.elvia.no/smart-forbruk/alt-om-din-strommaler/slik-gjor-du-det-aktivering-og-bruk-av-elvias-metervalueapi/

### Grid Tariff API

Get token by logging into https://elvia.portal.azure-api.net/signin and subscribe to the GridTariffAPI

## Using the API

```python
from elvia import Elvia
import json
import asyncio
import os

# token from elvia.no/minside
meter_value_token = os.environ.get("ELVIA_METER_VALUE_TOKEN")

# token from https://elvia.portal.azure-api.net/signin
grid_tariff_token = os.environ.get("ELVIA_GRID_TARIFF_TOKEN")

# the metering point id of your home
metering_point_id = os.environ.get("ELVIA_METERING_POINT_ID")

elvia = Elvia(meter_value_token = meter_value_token)

async def get_meter_values():
    meter_value_client = elvia.meter_value()
    meter_values = await meter_value_client.get_meter_values(
        start_time = "2021-12-08T01:00:00",
        end_time = "2021-12-08T02:00:00",
        metering_point_ids = [metering_point_id],
        include_production = True
    )
    print(json.dumps(meter_values))
asyncio.run(get_meter_values())

# And use it to get grid tariffs

elvia = Elvia(grid_tariff_token = grid_tariff_token)

async def get_grid_tariffs():
    grid_tariff_client = elvia.grid_tariff()

    grid_tariffs = await grid_tariff_client.grid_tariffs_for_metering_points(
        range = "today",
        metering_point_ids = [metering_point_id]
    )
    print(json.dumps(grid_tariffs))
asyncio.run(get_grid_tariffs())
```
