Add missing teleinfo library. Use Python3.

This commit is contained in:
yohan 2024-06-09 07:18:22 +02:00
parent bcb565a559
commit 3008197732
3 changed files with 15 additions and 15 deletions

View File

@ -3,6 +3,8 @@ MAINTAINER yohan <783b8c87@scimetis.net>
ENV DEBIAN_FRONTEND noninteractive ENV DEBIAN_FRONTEND noninteractive
ENV TZ Europe/Paris ENV TZ Europe/Paris
RUN apt-get update && apt-get -y install gunicorn sqlite3 python3-pip python3-requests python3-yaml python3-flask python3-serial udev RUN apt-get update && apt-get -y install gunicorn sqlite3 python3-pip python3-requests python3-yaml python3-flask python3-serial udev
ENV PIP_BREAK_SYSTEM_PACKAGES 1
RUN pip install teleinfo
WORKDIR /root WORKDIR /root
COPY find_ttyUSB.sh /root/ COPY find_ttyUSB.sh /root/
COPY read_one-wire_sensor.py /root/ COPY read_one-wire_sensor.py /root/

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# # pip install teleinfo # # pip install teleinfo
# https://pypi.org/project/teleinfo/ # https://pypi.org/project/teleinfo/
# https://www.magdiblog.fr/gpio/teleinfo-edf-suivi-conso-de-votre-compteur-electrique/ # https://www.magdiblog.fr/gpio/teleinfo-edf-suivi-conso-de-votre-compteur-electrique/
@ -23,27 +22,27 @@ for line in find_ttyUSB_output.decode('utf-8').split("\n"):
break break
if device is None: if device is None:
print ("USB teleinfo device not found.") print("USB teleinfo device not found.")
sys.exit(1) sys.exit(1)
ti = Parser(UTInfo2(port=device)) ti = Parser(UTInfo2(port=device))
res = ti.get_frame() res = ti.get_frame()
if args.format == 'human-readable': if args.format == 'human-readable':
print "Puissance apparente compteur : "+str(int(res['PAPP']))+"VA" print("Puissance apparente compteur : "+str(int(res['PAPP']))+"VA")
# moins précis car Intensité arrondie à l'entier # moins précis car Intensité arrondie à l'entier
print "Puissance apparente calculée : "+str(int(res['IINST'])*230)+"VA" print("Puissance apparente calculée : "+str(int(res['IINST'])*230)+"VA")
print "Puissance souscrite : 6kVA" print("Puissance souscrite : 6kVA")
print "Puissance max avant coupure (marge 30%) : 7,8kVA" print("Puissance max avant coupure (marge 30%) : 7,8kVA")
print "Intensité : "+str(int(res['IINST']))+"A" print("Intensité : "+str(int(res['IINST']))+"A")
print "Intensité abonnement : "+str(int(res['ISOUSC']))+"A" print("Intensité abonnement : "+str(int(res['ISOUSC']))+"A")
print "Consommation : "+str(int(res['BASE']))+"Wh" print("Consommation : "+str(int(res['BASE']))+"Wh")
elif args.format == 'raw_json': elif args.format == 'raw_json':
print json.dumps(res) print(json.dumps(res))
elif args.format == 'custom_json': elif args.format == 'custom_json':
data = {} data = {}
data['Modane_elec_main_power'] = int(res['PAPP']) data['Modane_elec_main_power'] = int(res['PAPP'])
data['Modane_elec_energy_index'] = int(res['BASE']) data['Modane_elec_energy_index'] = int(res['BASE'])
print json.dumps(data) print(json.dumps(data))
#for frame in ti: #for frame in ti:
# print frame # print(frame)

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse import argparse
import json import json
@ -21,7 +20,7 @@ try:
try: try:
value = round(float(returned_output.decode("utf-8").strip().strip("'")), 1) value = round(float(returned_output.decode("utf-8").strip().strip("'")), 1)
except ValueError: except ValueError:
print ("Got garbage: "+returned_output) print("Got garbage: "+returned_output)
sys.exit(1) sys.exit(1)
except Exception as e: except Exception as e:
print(e) print(e)