eschava / broadlink-mqtt

MQTT client to control BroadLink devices
MIT License
224 stars 61 forks source link

Issue #109

Closed elngejw closed 2 years ago

elngejw commented 2 years ago

Hi all,

I have issues with starting this as a service. I installled according instructions, I changed in broadlink-mqtt.service the folder to /home/openhabian/broadlink-mqtt/mqtt.py. But I keep getting error below. Starting mqtt.py manually is working normally. Anybody any clue for a solution? Many thanks and best regards, GJ

openhabian@openhabian:/lib/systemd/system $ sudo systemctl daemon-reload [sudo] password for openhabian: openhabian@openhabian:/lib/systemd/system $ sudo systemctl start broadlink-mqtt.service openhabian@openhabian:/lib/systemd/system $ sudo systemctl status broadlink-mqtt.service ● broadlink-mqtt.service - Broadlink MQTT Service Loaded: loaded (/lib/systemd/system/broadlink-mqtt.service; disabled; vendor preset: enabled) Active: failed (Result: exit-code) since Mon 2022-08-22 12:34:51 CEST; 4s ago Process: 18975 ExecStart=/usr/bin/python3 /home/openhabian/broadlink-mqtt/mqtt.py (code=exited, status=1/FAILURE) Main PID: 18975 (code=exited, status=1/FAILURE) CPU: 146ms

Aug 22 12:34:51 openhabian systemd[1]: Started Broadlink MQTT Service. Aug 22 12:34:51 openhabian systemd[1]: broadlink-mqtt.service: Main process exited, code=exited, status=1/FAILURE Aug 22 12:34:51 openhabian systemd[1]: broadlink-mqtt.service: Failed with result 'exit-code'.

eschava commented 2 years ago

What happens if you start the script using bash, not systemctl? E.g. using command /usr/bin/python3 /home/openhabian/broadlink-mqtt/mqtt.py ?

elngejw commented 2 years ago

Starts as normally. Remote commands to TV also working

openhabian@openhabian:~ $ /usr/bin/python3 /home/openhabian/broadlink-mqtt/mqtt.py [2022-08-22 13:29:31,348] DEBUG Connected to 'RM4MINI' Broadlink device at '192.168.1.120' (MAC ec:0b:ae:9e:4d:d7) and started listening to MQTT commands at 'broadlink/#' [2022-08-22 13:29:31,353] DEBUG Connected to MQTT broker, subscribing to topic broadlink/#

elngejw commented 2 years ago

I'm still facing this issue....found out that the service is running now (see below). But when I send mqtt command, nothing happens. What can I do to find more information, what is going wrong?

openhabian@openhabian:~/broadlink-mqtt $ sudo journalctl -f -u broadlink-mqtt.service -- Journal begins at Tue 2022-08-23 19:32:40 CEST. -- Aug 24 18:23:57 openhabian systemd[1]: Stopping Broadlink MQTT Service... Aug 24 18:23:57 openhabian systemd[1]: broadlink-mqtt.service: Succeeded. Aug 24 18:23:57 openhabian systemd[1]: Stopped Broadlink MQTT Service. Aug 24 18:23:57 openhabian systemd[1]: broadlink-mqtt.service: Consumed 1.620s CPU time. Aug 24 18:23:57 openhabian systemd[1]: Started Broadlink MQTT Service. Aug 25 14:14:03 openhabian systemd[1]: Stopping Broadlink MQTT Service... Aug 25 14:14:03 openhabian systemd[1]: broadlink-mqtt.service: Succeeded. Aug 25 14:14:03 openhabian systemd[1]: Stopped Broadlink MQTT Service. Aug 25 14:14:03 openhabian systemd[1]: broadlink-mqtt.service: Consumed 16.526s CPU time. Aug 25 14:14:03 openhabian systemd[1]: Started Broadlink MQTT Service.

Aug 25 17:33:45 openhabian systemd[1]: Stopping Broadlink MQTT Service... Aug 25 17:33:45 openhabian systemd[1]: broadlink-mqtt.service: Succeeded. Aug 25 17:33:45 openhabian systemd[1]: Stopped Broadlink MQTT Service. Aug 25 17:33:45 openhabian systemd[1]: broadlink-mqtt.service: Consumed 3.979s CPU time. Aug 25 17:33:45 openhabian systemd[1]: Started Broadlink MQTT Service.


openhabian@openhabian:~/broadlink-mqtt $ systemctl list-units --type=service UNIT LOAD ACTIVE SUB DESCRIPTION alsa-restore.service loaded active exited Save/Restore Sound Card State avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack bluetooth.service loaded active running Bluetooth service broadlink-mqtt.service loaded active running Broadlink MQTT Service

eschava commented 2 years ago

Is it possible to check what the script prints to the console?

elngejw commented 2 years ago

Sorry for late reaction. The output when starting manually is below. Is there also a way to log a service?

Btw...in some way I get continuously every ~22 seconds the "WARNING OOOOPS! MQTT disconnection" message.

openhabian@openhabian:~ $ /usr/bin/python3 /home/openhabian/broadlink-mqtt/mqtt.py [2022-09-07 16:56:57,671] DEBUG Connected to 'RM4MINI' Broadlink device at '192.168.1.120' (MAC ec:0b:ae:9e:4d:d7) and started listening to MQTT commands at 'broadlink/#' [2022-09-07 16:56:57,678] DEBUG Connected to MQTT broker, subscribing to topic broadlink/# [2022-09-07 16:57:08,693] WARNING OOOOPS! MQTT disconnection [2022-09-07 16:57:19,709] DEBUG Connected to MQTT broker, subscribing to topic broadlink/# [2022-09-07 16:57:30,724] WARNING OOOOPS! MQTT disconnection

eschava commented 2 years ago

It looks like there are two processes with the same MQTT client id connected to the MQTT broker at the same time

elngejw commented 2 years ago

Issue with MQTT disconnection is solved.

Still running this as a service is not working. Service looks active running, but when I send mqtt command, nothing happens. With MQTT Explorer I see the MQTT command is sent

openhabian@openhabian:~ $ systemctl list-units --type=service UNIT LOAD ACTIVE SUB DESCRIPTION alsa-restore.service loaded active exited Save/Restore Sound Card State avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack bluetooth.service loaded active running Bluetooth service broadlink-mqtt.service loaded active running Broadlink MQTT Service

openhabian@openhabian:~ $ sudo systemctl status broadlink-mqtt.service [sudo] password for openhabian: ● broadlink-mqtt.service - Broadlink MQTT Service Loaded: loaded (/lib/systemd/system/broadlink-mqtt.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2022-08-25 18:21:01 CEST; 3 weeks 6 days ago Main PID: 1091 (python3) Tasks: 1 (limit: 4915) CPU: 8min 24.330s CGroup: /system.slice/broadlink-mqtt.service └─1091 /usr/bin/python3 /home/openhabian/broadlink-mqtt/mqtt.py

Journal gives no issues (also not after restarting the service)

openhabian@openhabian:~/broadlink-mqtt $ sudo journalctl -f -u broadlink-mqtt.service -- Journal begins at Sun 2022-09-18 17:48:19 CEST. -- Sep 21 18:58:12 openhabian systemd[1]: Stopping Broadlink MQTT Service... Sep 21 18:58:12 openhabian systemd[1]: broadlink-mqtt.service: Succeeded. Sep 21 18:58:12 openhabian systemd[1]: Stopped Broadlink MQTT Service. Sep 21 18:58:12 openhabian systemd[1]: broadlink-mqtt.service: Consumed 8min 24.396s CPU time. Sep 21 18:58:21 openhabian systemd[1]: Started Broadlink MQTT Service.

eschava commented 2 years ago

could you please share your mqtt.log file?

elngejw commented 2 years ago

Hmm...with starting manually no issues with "Unrecognized MQTT message power". Might be "Unknown" device. See below output of mqtt.log. First connect is service, second connect is starting manually after stopping service. Mqqt message is then accepted normally

[2022-09-22 11:24:08,594] DEBUG Connected to 'Unknown' Broadlink device at '192.168.1.120' (MAC ec:0b:ae:9e:4d:d7) and started listening to MQTT commands at 'broadlink/#' [2022-09-22 11:24:08,599] DEBUG Connected to MQTT broker, subscribing to topic broadlink/# [2022-09-22 11:24:51,001] DEBUG Received MQTT message broadlink/masterbedroom/samsungtv power [2022-09-22 11:24:51,002] WARNING Unrecognized MQTT message power [2022-09-22 11:30:02,493] DEBUG Connected to 'RM4MINI' Broadlink device at '192.168.1.120' (MAC ec:0b:ae:9e:4d:d7) and started listening to MQTT commands at 'broadlink/#' [2022-09-22 11:30:02,499] DEBUG Connected to MQTT broker, subscribing to topic broadlink/# [2022-09-22 11:33:52,603] DEBUG Received MQTT message broadlink/masterbedroom/samsungtv power [2022-09-22 11:33:52,604] DEBUG Replaying command from file /home/openhabian/broadlink-mqtt/commands/masterbedroom/samsungtv/power

elngejw commented 2 years ago

SOLVED: issue solved by replacing 'lookup' by 'rm4' in mqtt.config

Many thx eschava for your support!!