Améliorer les messages d'erreur quand plusieurs équipements sont installés

Bonjour

J’ai installé le plugin Broadlink pour piloter 2 télécommandes universelles Broadlink RM pro+
J’ai régulièrement des pb de perte de connexion sur mes équipements (voir broadlink_daemon.log)

Je vais passer le log en « Debug » pour mieux identifier le pb, mais serait il possible de modifier le code du daemon Python (broadlinkd.py) pour faciliter l’identification de l’équipement à problème même en log « Defaut »

J’ai utilisé Claude AI pour modifier broadlinkd.py. : j’ai tester le code et cela fonctionne maintenant (voir second log)
J’ai proposé le nouveau code sur Github, si l’equipe Jeedom veut l’adopter.

Merci

broadlink_daemon.log original

0000|[2026-04-22 12:14:49.428] ERROR  : The device is offline
0001|[2026-04-22 12:15:04.920] ERROR  : The device is offline
0002|[2026-04-22 12:15:30.448] ERROR  : The device is offline
0003|[2026-04-22 12:44:43.113] ERROR  : The device is offline
0004|[2026-04-22 12:45:05.787] ERROR  : The device is offline
0005|[2026-04-22 12:45:28.464] ERROR  : The device is offline
0006|[2026-04-22 12:45:51.146] ERROR  : The device is offline
0007|[2026-04-22 19:38:29.882] ERROR  : The device is offline
0008|[2026-04-22 19:38:45.369] ERROR  : The device is offline
0009|[2026-04-22 19:39:00.857] ERROR  : The device is offline
0010|[2026-04-22 19:39:16.357] ERROR  : The device is offline
0011|[2026-04-22 20:08:14.389] ERROR  : The device is offline
0012|[2026-04-22 20:08:43.595] ERROR  : The device is offline
0013|[2026-04-22 20:09:06.280] ERROR  : The device is offline
0014|[2026-04-23 06:52:32.896] ERROR  : The device is offline
0015|[2026-04-23 12:48:57.028] ERROR  : The device is offline
0016|[2026-04-23 12:49:12.532] ERROR  : The device is offline
0017|[2026-04-23 12:49:38.786] ERROR  : The device is offline
0018|[2026-04-23 13:32:16.647] ERROR  : The device is offline
0019|[2026-04-23 13:32:39.908] ERROR  : The device is offline
0020|[2026-04-23 13:33:02.506] ERROR  : The device is offline
0021|[2026-04-23 20:04:21.253] ERROR  : The device is offline
0022|[2026-04-23 20:04:36.744] ERROR  : The device is offline
0023|[2026-04-23 20:28:49.015] ERROR  : The device is offline

broadlink_daemon.log modifié
avec 1 equipement (AN03) débranché sur les 2
09:50 : envoie d’une commande et msg d’erreur sur AN03
09:52 : polling des 2 équipements avec 1 erreur sur celui débranché AN03 mais pas AN02

[2026-04-26 09:50:39.831] DEBUG  : Client connected to [127.0.0.1:50708]
[2026-04-26 09:50:39.832] DEBUG  : Message read from socket: b'{"apikey":"xx","cmd":"send","cmdType":"command","mac":"eb3db9770f78","device":{"hex2send":"260028007e0001177d0001167e0001167e0001154b0001494d0001464b0001494b0001497d0001164d000d05","ip":"192.168.1.104","port":"80","type":"rm2","name":"T\\u00e9l\\u00e9commande chauffage AN03","mac":"eb3db9770f78"}}'
[2026-04-26 09:50:39.832] DEBUG  : Client disconnected from [127.0.0.1:50708]
[2026-04-26 09:50:39.840] DEBUG  : Message received in socket JEEDOM_SOCKET_MESSAGE
[2026-04-26 09:50:39.841] DEBUG  : Send command
[2026-04-26 09:50:39.843] DEBUG  : Connecting to Broadlink device with name Télécommande chauffage AN03....
[2026-04-26 09:50:49.860] ERROR  : The device is offline [nom:"Télécommande chauffage AN03" | mac:eb3db9770f78 | ip:192.168.1.104]
[2026-04-26 09:52:52.579] DEBUG  : Handling RM2 for Télécommande chauffage AN03
[2026-04-26 09:52:52.580] DEBUG  : Connecting to Broadlink device with name Télécommande chauffage AN03....
[2026-04-26 09:53:02.596] ERROR  : The device is offline [nom:"Télécommande chauffage AN03" | mac:eb3db9770f78 | ip:192.168.1.104]
[2026-04-26 09:53:02.765] DEBUG  : Handling RM2 for Télécommande home cinéma AN02
[2026-04-26 09:53:02.765] DEBUG  : Connecting to Broadlink device with name Télécommande home cinéma AN02....
[2026-04-26 09:53:02.825] DEBUG  : Connected to Broadlink device with name Télécommande home cinéma AN02....
[2026-04-26 09:53:02.946] DEBUG  : {'mac': 'c8f7424861d2', 'temperature': 0.0}

Informations Jeedom Atlas

Core : 4.5.3 (master)
DNS Jeedom Atlas : oui

Plugin : Broadlink
Version : 2025-02-28 01:00:55 (stable)
Statut Démon : Démarré - (2026-04-26 09:27:48)
Santé
🟢 Matériel : Atlas
🟢 Système à jour : OK
🟢 Cron actif : OK
🟢 Scénario actif : OK
🟢 Démarré : OK 2026-04-22 01:02:07
🟢 Date système (dernière heure enregistrée) : OK 2026-04-26 09:48:27 (2026-04-26 09:19:02)
🟢 Droits sudo : OK
🟢 Version Jeedom : 4.5.3
🟢 Version OS : debian 11.11
🟢 Version PHP : 7.4.33
🟢 Nombre de processus Apache : 17
🟢 Version OS : Linux JeedomAtlas 6.16.4-arm64 #1 SMP PREEMPT 2025-09-11 aarch64 GNU/Linux  [11.11]
🟢 Version database : 10.5.29-MariaDB-0+deb11u1
🟢 Espace disque libre : 64 %
🟢 Connexion active/max/autorisée : 21/43/151
🟢 Taille base de données : 705.57 MB
🟢 Espace disque libre tmp : 99 %
🟢 Mémoire disponible : 26 % (Total 3849 Mo)
🟢 Mémoire suffisante : 0 
🟢 Erreur I/O : 0
🟢 Swap disponible : 86 % (Total 1024 Mo)
🟢 Swappiness : 10 %
🟢 Charge : 1.1 - 1.54 - 1.54
🟢 Configuration réseau interne : OK
🟢 Configuration réseau externe : OK
🟢 Node : v22.22.0 
🟢 Python 3 : Python 3.9.2 
🟢 Persistance du cache : OK
🟢 Apache private tmp : OK

2 « J'aime »

Bonjour,

Je ne sais pas où vous avez proposé quelque chose mais ce n’est pas sur le repo github du plugin.

Bonjour @Mips

J’essaye de contribuer au mieux de mes connaissances (limitées)
Je n’ai pas du faire ce qu’il fallait, désolé…

sinon voila le code modifié de broadlinkd.py

# -*- coding: utf-8 -*-
# This file is part of Jeedom.
#
# Jeedom is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Jeedom is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Jeedom. If not, see <http://www.gnu.org/licenses/>.

import logging
import sys
import os
import time
import datetime
import signal
import argparse
import traceback
import json
from broadlink import broadlink, rm2, a1, mp1, sp2, rm4
import globals

from jeedom.jeedom import jeedom_com, jeedom_socket, jeedom_utils, JEEDOM_SOCKET_MESSAGE

# ----------------------------------------------------------------------------


def listen():
    logging.debug("Start listening...")
    jeedom_socket.open()
    try:
        while 1:
            time.sleep(0.02)
            read_socket()
            read_broadlink()
    except KeyboardInterrupt:
        shutdown()


def read_socket():
    try:
        if not JEEDOM_SOCKET_MESSAGE.empty():
            logging.debug("Message received in socket JEEDOM_SOCKET_MESSAGE")
            message = JEEDOM_SOCKET_MESSAGE.get().decode('utf-8')
            message = json.loads(message)
            if message['apikey'] != _apikey:
                logging.error("Invalid apikey from socket: %s", message)
                return
            if message['cmd'] == 'add':
                logging.debug('Add device : %s', message['device'])
                if 'mac' in message['device']:
                    globals.KNOWN_DEVICES[message['device']['mac']] = message['device']
            elif message['cmd'] == 'remove':
                logging.debug('Remove device : %s', message['device'])
                if 'mac' in message['device']:
                    del globals.KNOWN_DEVICES[message['device']['mac']]
            elif message['cmd'] == 'learnin':
                logging.debug('Enter in learn mode')
                globals.LEARN_MODE = True
                globals.JEEDOMCOM.send_change_immediate({'learn_mode': 1})
                devices = broadlink.discover(timeout=5)
                logging.debug("found %s", devices)
                globals.LEARN_MODE = False
                globals.JEEDOMCOM.send_change_immediate({'learn_mode': 0})
                for device in devices:
                    type = device.type
                    devtype = device.devtype
                    ip = device.host[0]
                    port = device.host[1]
                    mac = device.mac.hex()
                    reversemac = "".join(reversed([mac[i:i+2] for i in range(0, len(mac), 2)]))
                    globals.JEEDOMCOM.add_changes('devices::' + mac, {'type': type, 'ip': ip, 'mac': mac, 'reversemac': reversemac, 'port': port, 'learn': 1, 'devtype': devtype})
            elif message['cmd'] == 'send':
                if 'mac' in message['device']:
                    logging.debug('Send command')
                    send_broadlink(message)
    except Exception as ex:
        logging.error(ex)
# ----------------------------------------------------------------------------


def read_broadlink():
    now = datetime.datetime.now(datetime.timezone.utc)
    result = {}
    for device in list(globals.KNOWN_DEVICES):
        dev = globals.KNOWN_DEVICES[device]
        mac = dev['mac']
        if mac in globals.LAST_TIME_READ and now < (globals.LAST_TIME_READ[mac]+datetime.timedelta(milliseconds=int(dev['delay'])*1000)):
            continue
        if mac[-3:] == 'sub':
            continue
        try:
            globals.LAST_TIME_READ[mac] = now
            if dev['type'] == 'rm2':
                logging.debug('Handling RM2 for ' + dev['name'])
                result = rm2.read_rm2(dev)
            elif dev['type'] == 'a1':
                logging.debug('Handling A1 for ' + dev['name'])
                result = a1.read_a1(dev)
            elif dev['type'] == 'sp2':
                logging.debug('Handling SP2 for ' + dev['name'])
                result = sp2.read_sp2(dev)
            elif dev['type'] == 'mp1':
                logging.debug('Handling MP1 for ' + dev['name'])
                result = mp1.read_mp1(dev)
            elif dev['type'] == 'rm4':
                logging.debug('Handling RM4 for ' + dev['name'])
                result = rm4.read_rm4(dev)
            if result:
                if mac in globals.LAST_STATE and result == globals.LAST_STATE[mac]:
                    continue
                else:
                    globals.LAST_STATE[mac] = result
                    globals.JEEDOMCOM.add_changes('devices::'+mac, result)
        except Exception as ex:
            err = str(ex)
            if err in ('timed out', 'The device is offline'):
                logging.error('The device is offline [nom:"%s" | mac:%s | ip:%s]',
                    dev.get('name','?'), mac, dev.get('ip','?'))
            else:
                logging.error('Erreur [nom:"%s" | mac:%s] : %s',
                    dev.get('name','?'), mac, ex)

# ----------------------------------------------------------------------------


def send_broadlink(message):
    result = {}
    dev = message['device']
    device_label = '[nom:"{}" | mac:{} | ip:{}]'.format(
        dev.get('name', '?'), dev.get('mac', '?'), dev.get('ip', '?')
    )
    try:
        if message['cmdType'] == 'refresh':
            if dev['type'] == 'rm2':
                result = rm2.read_rm2(dev)
            elif dev['type'] == 'a1':
                result = a1.read_a1(dev)
            elif dev['type'] == 'mp1':
                result = mp1.read_mp1(dev)
            elif dev['type'] == 'sp2':
                result = sp2.read_sp2(dev)
            elif dev['type'] == 'rm4':
                result = rm4.read_rm4(dev)
            if result:
                if dev['mac'] in globals.LAST_STATE and result == globals.LAST_STATE[dev['mac']]:
                    return
                else:
                    globals.LAST_STATE[dev['mac']] = result
                    globals.JEEDOMCOM.add_changes('devices::'+dev['mac'], result)
            return
        elif dev['type'] == 'rm2':
            if message['cmdType'] == 'learn':
                result = rm2.learn_rm2(dev)
                if result:
                    globals.JEEDOMCOM.add_changes('devices::'+dev['mac'], result)
            else:
                rm2.send_rm2(dev)
        elif dev['type'] == 'rm4':
            if message['cmdType'] == 'learn':
                result = rm4.learn_rm4(dev)
                if result:
                    globals.JEEDOMCOM.add_changes('devices::'+dev['mac'], result)
            else:
                rm4.send_rm4(dev)
        elif dev['type'] == 'mp1':
            result = mp1.send_mp1(dev)
            if result:
                globals.JEEDOMCOM.add_changes('devices::'+dev['mac'], result)
        elif dev['type'] == 'sp2':
            result = sp2.send_sp2(dev)
            if result:
                globals.JEEDOMCOM.add_changes('devices::'+dev['mac'], result)
    except Exception as ex:
        err = str(ex)
        if err in ('timed out', 'The device is offline'):
            logging.error('The device is offline ' + device_label)
        else:
            logging.error('Erreur envoi commande vers %s : %s', device_label, ex)
    return


# ----------------------------------------------------------------------------

def handler(signum=None, frame=None):
    logging.debug("Signal %i caught, exiting...", signum)
    shutdown()


def shutdown():
    logging.debug("Shutdown")
    logging.debug("Removing PID file %s", _pidfile)
    try:
        os.remove(_pidfile)
    except Exception as ex:
        logging.warning("Error while removing PID file: %s", ex)
    try:
        jeedom_socket.close()
    except Exception as ex:
        logging.warning("Error while closing socket: %s", ex)
    logging.debug("Exit 0")
    sys.stdout.flush()
    os._exit(0)

# ----------------------------------------------------------------------------


_log_level = "error"
_socket_port = 55013
_socket_host = '127.0.0.1'
_pidfile = '/tmp/broadlinkd.pid'
_apikey = ''
_callback = ''
_cycle = 0.3

parser = argparse.ArgumentParser(description='Broadlink Daemon for Jeedom plugin')
parser.add_argument("--socketport", help="Socketport for server", type=str)
parser.add_argument("--sockethost", help="Sockethost for server", type=str)
parser.add_argument("--loglevel", help="Log Level for the daemon", type=str)
parser.add_argument("--callback", help="Callback", type=str)
parser.add_argument("--apikey", help="Apikey", type=str)
parser.add_argument("--cycle", help="Cycle to send event", type=str)
parser.add_argument("--pid", help="Pid file", type=str)
args = parser.parse_args()

if args.socketport:
    _socket_port = int(args.socketport)
if args.loglevel:
    _log_level = args.loglevel
if args.callback:
    _callback = args.callback
if args.apikey:
    _apikey = args.apikey
if args.cycle:
    _cycle = float(args.cycle)
if args.pid:
    _pidfile = args.pid

jeedom_utils.set_log_level(_log_level)

logging.info('Start broadlinkd')
logging.info('Log level: %s', _log_level)
logging.debug('Socket port: %s', _socket_port)
logging.debug('Socket host: %s', _socket_host)
logging.debug('PID file: %s', _pidfile)
logging.debug('Callback: %s', _callback)
logging.debug('Cycle: %s', _cycle)

signal.signal(signal.SIGINT, handler)
signal.signal(signal.SIGTERM, handler)

try:
    jeedom_utils.write_pid(_pidfile)
    globals.JEEDOMCOM = jeedom_com(apikey=_apikey, url=_callback, cycle=_cycle)
    if not globals.JEEDOMCOM.test():
        logging.error('Network communication issues. Please fix your Jeedom network configuration.')
        shutdown()
    jeedom_socket = jeedom_socket(port=_socket_port, address=_socket_host)
    listen()
except Exception as ex:
    logging.error('Fatal error : %s', ex)
    logging.debug(traceback.format_exc())
    shutdown()

on ne va pas travailler avec des copiés/collés via forum :wink:

Il faut cliquer ici pour proposer le changement:
image

seulement à ce moment il pourra être revu et vérifié

C’est parti !


image