Utilities to connect to a Teleinformation serial device
Project description
Serial Teleinfo
This project provides Python utilities to access data from Enedis energy meters using a serial converter :
serial_teleinfo
provides the classes to read and parse dataserial_teleinfo.server
is a simple web-server to access live readings through a JSON api
You will need a serial adapter such as the Micro Teleinfo to use this package.
Running the server
The web server exposes a JSON API providing live data read from the energy meter :
{
"connected":true,
"ready":true,
"values":{
"ISOUSC": [30, "A"],
"BASE": [804220, "Wh"],
"PTEC": ["TH", null],
"IINST": [1, "A"],
"IMAX": [90, "A"],
"PAPP": [340, "VA"],
"HHPHC": ["A", null],
"MOTDETAT": ["000000", null],
"ADCO": ["012345678901", null],
"OPTARIF": ["BASE", null]
}
}
Configuration file
The configuration is as follows :
[teleinfo]
device=/dev/ttyUSB0
loglevel=INFO
[http]
listen=127.0.0.1:8000
[users]
apiuser=apipassword
teleinfo/device
: The path to the serial port.teleinfo/loglevel
(optionnal) : Modifies the log verbosity, it can beDEBUG
,INFO
,WARNING
,ERROR
. Default isINFO
.http/listen
: The host and port to listen to.users
: A list of user/password allowed to use the API (using basic authentification).
Using python
Install the package :
pip install serial-teleinfo[server]
Create a configuration file teleinfo.ini
as described above and run the command :
python -m serial_teleinfo.server teleinfo.ini
Once the server is running, you can access the values at http://apiuser:apipassword@localhost:8000/status.json.
Using Docker
A docker image is provided, here's an example docker-compose.yml
:
version: '3'
services:
teleinfo:
image: ugomeda/serial-teleinfo
restart: always
devices:
- /dev/ttyUSB0
environment:
HTTP_LISTEN: "0.0.0.0:7777"
USERS_PASSWORD: "Str0ngPa55w0rd!"
TELEINFO_LOGLEVEL: "DEBUG"
ports:
- "7777:7777"
You can access the values at http://apiuser:Str0ngPa55w0rd!@SERVERIP:7777/status.json.
The environment variables are :
Variable | Default value |
---|---|
TELEINFO_DEVICE | /dev/ttyUSB0 |
TELEINFO_LOGLEVEL | INFO |
HTTP_LISTEN | 0.0.0.0:8000 |
USERS_USER | apiuser |
USERS_PASSWORD | apipassword |
Using the library
Install the package :
pip install serial-teleinfo
serial_teleinfo.Client
This class provides direct access to the values read on the serial port.
Here's an example usage :
import serial
from serial_teleinfo import Client, TeleinfoException
try:
with Client("/dev/ttyUSB0") as client:
while True:
print(client.read_value())
except TeleinfoException as e:
print(e)
except serial.SerialException as e:
print(e)
You can also refer to the serial_teleinfo.ValueUpdater
implementation.
serial_teleinfo.ValueUpdater
This utility class manages a background thread to update values indefinitely. It will automatically handle reconnection to the serial port and ignore temporary errors or reccuring unknown keys.
It provides 3 main properties :
values
: A dictionary with all the valuesconnected
: True if the client is connected to the meterready
: True if all the values are available
You can also override the update_value
method to access the read values as they are read.
Heres an example usage :
import time
from serial_teleinfo import ValueUpdater
class MyValueUpdater(ValueUpdater):
def update_value(self, value):
print(f"Updated {value.key}")
super().update_value(value)
updater = MyValueUpdater("/dev/ttyUSB0")
updater.start()
try:
while True:
print(f"Connected : {updater.connected}")
print(f"Ready : {updater.ready}")
for value in updater.values.values():
print(value)
time.sleep(2)
finally:
updater.stop()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file serial-teleinfo-1.0.1.tar.gz
.
File metadata
- Download URL: serial-teleinfo-1.0.1.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce100cc4454bf55a18ae2e53aa83913b58c52eddb9f9d76dc83bd53c5b78c38f |
|
MD5 | 448215b4f6928999eb98df5a050406f6 |
|
BLAKE2b-256 | 14fbd6c9b17531ff1f63aea3d3973f45b4bd2102e1a72572436223e30cd0b63f |
File details
Details for the file serial_teleinfo-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: serial_teleinfo-1.0.1-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4de1da74878a22062385aa40b11064a733cb874fd604629305c3474ea2a2e2a |
|
MD5 | b54330a52a776b220dcdde9e1f398d2a |
|
BLAKE2b-256 | f81b0e679172057e589fadc88074e63c385bd8d15467be4d1a60faff2ed32764 |