Skip to main content

ekzexport

This is an exporter for EKZ data provided on the http://my.ekz.ch customer portal written in Python. It uses your credentials to login and then calls the EKZ API the website uses to directly export the data. Data can be synced either to a CSV file or InfluxDB.

Installing

Get it from PyPI:

$ python -m pip install ekzexport

You can then use the ekzexport CLI.

Example Usage

To authenticate, you can either put your credentials into a JSON file ekzexport.json in your home directory:

{
  "user": "myusername",
  "password": "mypassword"
}

If you're using a TOTP token via an authenticator app, you can create a dedicated token to use. Click on the "can't scan QR code" link to get the code to manually enter and put it in the JSON file so it looks similar to this:

{
  "user": "myusername",
  "password": "mypassword",
  "otp": "AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH"
}

Instead of the JSON config file, you can also use the --user and --password (and --otp) CLI options directly. The following examples use a JSON file.

[!IMPORTANT] If you have enabled SMS as a second factor authentication, myEKZ will send you a code each time you run ekzexport. While you can enter it each time, it is more convenient to disable SMS authentication in the account settings or use a TOTP authenticator app.

First, list your contracts to find the installation ID of interest:

$ ekzexport overview
                                        Contracts                                        
                  ╷                                      ╷              ╷
  Installation ID │ Address                              │ Move-in Date │ Move-out Date 
╺━━━━━━━━━━━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┿━━━━━━━━━━━━━━┿━━━━━━━━━━━━━━━╸
  123             │ Somestreet 1, 8000 Someplace         │ 2010-01-01   │ 2020-01-01
  456             │ Some Other Street 2, 8001 Otherplace │ 2020-01-02   │
                  ╵                                      ╵              ╵

With the installation ID, we can then figure out what kind of data is available for your account:

$ ekzexport installation 456 properties
                 Properties                 
                 ╷            ╷
  Property       │ From       │ Until      
╺━━━━━━━━━━━━━━━━┿━━━━━━━━━━━━┿━━━━━━━━━━━━╸
  CONTRACT       │ 2020-01-02 │ 2024-05-01
  SMART_METER    │ 2020-01-02 │ 2024-05-01
  VERB_15MIN     │ 2020-01-02 │ 2024-05-01
  VERB_TAG_EDM   │ 2020-01-02 │ 2024-05-01
  VERB_TAG_METER │ 2020-01-02 │ 2024-05-01
                 ╵            ╵

If you do not see any entry for 15 minute values, you likely have to enable granular data on myEKZ first.

You can print consumption data to get an idea what is available:

$ ekzexport installation 456 data --type PK_VERB_TAG_EDM --from 2024-04-01 --to 2024-04-02 show
                 Consumption Data                 
                      ╷        ╷        ╷
  Time                │ kWh    │ Tariff │ Status 
╺━━━━━━━━━━━━━━━━━━━━━┿━━━━━━━━┿━━━━━━━━┿━━━━━━━━╸
  2024-04-01 00:00:00 │ 12.123 │ NT     │ VALID
  2024-04-01 00:00:00 │ 10.123 │ HT     │ VALID
  2024-04-02 00:00:00 │ 12.678 │ NT     │ VALID
  2024-04-02 00:00:00 │ 8.678  │ HT     │ VALID
                      ╵        ╵        ╵

But the more interesting use-case is to export data. Available exporters are:

  • csv to sync data to a CSV file in the same format as myEKZ offers
  • influxdb to sync data to an InfluxDB 2.x server

The CLI's help command will provide further detail on the exporter-specific options, for example:

$ ekzexport installation 456 data export csv --help

Running Exports Periodically

If you're using a Linux distribution using systemd, you can create a service and trigger to run the export periodically. To do so, create /etc/systemd/system/ekzexport.service with something like:

[Unit]
Description=Pull EKZ data

[Service]
Type=oneshot
ExecStart=/path/to/ekzexport/venv/bin/ekzexport installation 456 data export csv -f data.csv
WorkingDirectory=/path/to/ekzexport

This example assumes you created a Python virtualenv to install ekzexport in (which keeps the dependencies local in the venv). You can also set up an OnFailure hook to send emails in case the export fails.

A corresponding timer can look something like this in /etc/systemd/system/ekzexport.timer:

[Unit]
Description=Run ekzexport once a day

[Timer]
OnCalendar=*-*-* 04:00:00
RandomizedDelaySec=30m
Persistent=true

[Install]
WantedBy=timers.target

Please keep the randomized delay to avoid myEKZ getting a flood of requests at exactly 04:00 every night. Remember to enable and start the timer.

LEG Data

If you are a manager of an LEG, you can also get data about the LEGs you manage. For example, the list the LEGs your account is managing, run:

$ ekzexport legs
                                   Legs                                    

  LEG ID                           │ Leg Name                              
╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸
  0123456789ABCDEF123456789ABCDEF1 │ My awesome LEG number 1              
  0123456789ABCDEF123456789ABCDEF2 │ My awesome LEG number 2                

See help output for more LEG commands.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ekzexport-0.3.0.tar.gz (35.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ekzexport-0.3.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file ekzexport-0.3.0.tar.gz.

File metadata

  • Download URL: ekzexport-0.3.0.tar.gz
  • Upload date:
  • Size: 35.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ekzexport-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e810b87977214fec9fce8e916131371fde6ac87212a0d63eb54fe2d660304be6
MD5 89bf2619db864991e967b348186f8a00
BLAKE2b-256 0bada4f92f03f1875ccf43d81c4485725e25b3de4f596c32b70faa4caf1a83f1

See more details on using hashes here.

File details

Details for the file ekzexport-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: ekzexport-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ekzexport-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c1353fe5e863281e5106b613300057a684be590c22f9f86fc3c2f45419d8573
MD5 9babf6a88c70a05ef659b4e8b8a18cb6
BLAKE2b-256 7df940637a01a8b0756d4304abda350c451c6e4adea5c143cb31c13502f2a2f6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page