Bonjour,
Ma communauté de communes utilise Ecocito pour la gestion des déchets, en particulier le nombre de levées par an pour facturer celle en sus d’un nombre forfaitaire. Afin de suivre ça directement dans HA j’ai créé une petite application Appdaemon pour récupérer les informations (je ne sais pas si c’est la meilleure méthode, a voir pour créer une vrai intégration HA) et créer les capteurs correspondants
J’ai dans mon compte seulement les levées déchets ménager et tri selectif donc je n’ai implémenté que ça.
Le fichier python (ecocito.py):
import hassapi as hass
import datetime
from datetime import datetime as dt
from requests import session
import json
MATIERE_DECHETS_MENAGER=1
MATIERE_TRI_SELECTIF=2
MATIERE_DECHETS_VERT=3
MATIERE_BIO_DECHETS=4
MATIERE_VERRE=5
MATIERE_ALL=-1
SERVICE_PAV="ObtenirStatistiqueApportPAVMensuel"
SERVICE_COLLECTE="ObtenirStatistiqueLeveesMensuel"
BASE_URL="https://{cc}.ecocito.com/Usager/Json/{service}?dateDebut={year_start}-01-01T01%3A00%3A00.000Z&dateFin={year_end}-12-31T23%3A59%3A00.000Z&idMatiere={type_matiere}"
class Ecocito(hass.Hass):
def initialize(self):
time = datetime.time(17, 00, 0)
# Schedule a daily callback that will call run_daily() at 17h
self.connection_payload={
'Identifiant': self.args["user"],
'MotDePasse': self.args["passw"],
'MaintenirConnexion': 'false',
'FranceConnectActif': 'False'
}
self.cc = self.args["cc"]
self.set_sensors_callback()
self.run_daily(self.set_sensors_callback, time)
def get_year_total(self, data):
total = 0
for elem in data:
total = total + elem["Nombre"]
return total
def set_sensors_callback(self, *kwargs):
with session() as c:
c.post(F'https://{self.cc}.ecocito.com/Usager/Profil/Connexion', data=self.connection_payload)
totalCollecte = json.loads(c.get(BASE_URL.format(cc=self.cc, service=SERVICE_COLLECTE, year_start=dt.now().year, year_end=dt.now().year, type_matiere=MATIERE_ALL)).text)
totalDechetsMenager = json.loads(c.get(BASE_URL.format(cc=self.cc, service=SERVICE_COLLECTE, year_start=dt.now().year, year_end=dt.now().year, type_matiere=MATIERE_DECHETS_MENAGER)).text)
totalTriSelectif = json.loads(c.get(BASE_URL.format(cc=self.cc, service=SERVICE_COLLECTE, year_start=dt.now().year, year_end=dt.now().year, type_matiere=MATIERE_TRI_SELECTIF)).text)
self.set_state("sensor.ecocito_total",state=self.get_year_total(totalCollecte))
self.set_state("sensor.ecocito_dechets_menager",state=self.get_year_total(totalDechetsMenager))
self.set_state("sensor.ecocito_tri_selectif",state=self.get_year_total(totalTriSelectif))
Le fichier yaml (ecocito.yaml) correspondant:
Ecocito-app:
class: Ecocito
module: ecocito
user: !secret ecocito_user
passw: !secret ecocito_passw
cc: !secret ecocito_cc
Dans l’arborescence Appdaemon ça ressemble à:
Dans home assistant ça donne ça après ajout dans un tableau de bord:
(j’ai mis l’icône sombre pour la ligne qui sert à la facturation )
Si vous avez des commentaires je suis preneur.