Package: serial-teleinfo
Serial TeleinfoThis project provides Python utilities to access data from Enedis energy meters using a serial converter :serial_teleinfoprovides the classes to read and parse dataserial_teleinfo.serveris a simple web-server to access live readings through a JSON apiYou will need a serial adapter such as theMicro Teleinfoto use this package.Running the serverThe 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 fileThe configuration is as follows :[teleinfo]device=/dev/ttyUSB0loglevel=INFO[http]listen=127.0.0.1:8000[users]apiuser=apipasswordteleinfo/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 pythonInstall the package :pipinstallserial-teleinfo[server]Create a configuration fileteleinfo.inias described above and run the command :python-mserial_teleinfo.serverteleinfo.iniOnce the server is running, you can access the values athttp://apiuser:apipassword@localhost:8000/status.json.Using DockerA docker image is provided, here's an exampledocker-compose.yml:version:'3'services:teleinfo:image:ugomeda/serial-teleinforestart:alwaysdevices:-/dev/ttyUSB0environment:HTTP_LISTEN:"0.0.0.0:7777"USERS_PASSWORD:"Str0ngPa55w0rd!"TELEINFO_LOGLEVEL:"DEBUG"ports:-"7777:7777"You can access the values athttp://apiuser:Str0ngPa55w0rd!@SERVERIP:7777/status.json.The environment variables are :VariableDefault valueTELEINFO_DEVICE/dev/ttyUSB0TELEINFO_LOGLEVELINFOHTTP_LISTEN0.0.0.0:8000USERS_USERapiuserUSERS_PASSWORDapipasswordUsing the libraryInstall the package :pipinstallserial-teleinfoserial_teleinfo.ClientThis class provides direct access to the values read on the serial port.Here's an example usage :importserialfromserial_teleinfoimportClient,TeleinfoExceptiontry:withClient("/dev/ttyUSB0")asclient:whileTrue:print(client.read_value())exceptTeleinfoExceptionase:print(e)exceptserial.SerialExceptionase:print(e)You can also refer to theserial_teleinfo.ValueUpdaterimplementation.serial_teleinfo.ValueUpdaterThis 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 availableYou can also override theupdate_valuemethod to access the read values as they are read.Heres an example usage :importtimefromserial_teleinfoimportValueUpdaterclassMyValueUpdater(ValueUpdater):defupdate_value(self,value):print(f"Updated{value.key}")super().update_value(value)updater=MyValueUpdater("/dev/ttyUSB0")updater.start()try:whileTrue:print(f"Connected :{updater.connected}")print(f"Ready :{updater.ready}")forvalueinupdater.values.values():print(value)time.sleep(2)finally:updater.stop()