2024-02-24 14:32:40 +00:00
|
|
|
#!/usr/bin/env python2
|
2024-02-04 20:19:01 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# # pip install teleinfo
|
|
|
|
# https://pypi.org/project/teleinfo/
|
|
|
|
# https://www.magdiblog.fr/gpio/teleinfo-edf-suivi-conso-de-votre-compteur-electrique/
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import json
|
|
|
|
from teleinfo import Parser
|
|
|
|
from teleinfo.hw_vendors import UTInfo2
|
2024-06-08 20:00:17 +00:00
|
|
|
import subprocess
|
2024-02-04 20:19:01 +00:00
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='Téléinfo retriever.')
|
|
|
|
parser.add_argument("-f", "--format", help="Output format.",
|
|
|
|
type=str, choices=['human-readable', 'raw_json', 'custom_json'], default='human-readable')
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2024-06-08 20:00:17 +00:00
|
|
|
find_ttyUSB_output = subprocess.check_output(["./find_ttyUSB.sh"])
|
|
|
|
device = None
|
|
|
|
for line in find_ttyUSB_output.decode('utf-8').split("\n"):
|
|
|
|
if "Cartelectronic_Interface_USB_1_TIC_DA6TLO1X" in line:
|
|
|
|
device = line.split(" ")[0]
|
|
|
|
break
|
|
|
|
|
|
|
|
if device is None:
|
|
|
|
print ("USB teleinfo device not found.")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
ti = Parser(UTInfo2(port=device))
|
2024-02-04 20:19:01 +00:00
|
|
|
res = ti.get_frame()
|
|
|
|
|
|
|
|
if args.format == 'human-readable':
|
|
|
|
print "Puissance apparente compteur : "+str(int(res['PAPP']))+"VA"
|
|
|
|
# moins précis car Intensité arrondie à l'entier
|
|
|
|
print "Puissance apparente calculée : "+str(int(res['IINST'])*230)+"VA"
|
|
|
|
print "Puissance souscrite : 6kVA"
|
|
|
|
print "Puissance max avant coupure (marge 30%) : 7,8kVA"
|
|
|
|
print "Intensité : "+str(int(res['IINST']))+"A"
|
|
|
|
print "Intensité abonnement : "+str(int(res['ISOUSC']))+"A"
|
|
|
|
print "Consommation : "+str(int(res['BASE']))+"Wh"
|
|
|
|
elif args.format == 'raw_json':
|
|
|
|
print json.dumps(res)
|
|
|
|
elif args.format == 'custom_json':
|
|
|
|
data = {}
|
|
|
|
data['Modane_elec_main_power'] = int(res['PAPP'])
|
|
|
|
data['Modane_elec_energy_index'] = int(res['BASE'])
|
|
|
|
print json.dumps(data)
|
|
|
|
#for frame in ti:
|
|
|
|
# print frame
|