Hey Daverz, all,
What i eventually did was to use the line:
payload = json.loads(msg.payload)
and as you can see, i have it working
I have been working a bit more on the python code this morning and i have now a pretty solid script that responds to faster/longer turns, has a top limit set up for safety and the button press action triggers mute/unmute. In this regard i think i am done for the moment, maybe i will just adjust the db changes size down the road (see demo video at the end to get an idea). Also, i am seeing the range of the knob is much better than i thought, and works even from a different room with the doors closed!
Where i am stacked now is in creating a service to have it always running in the background and to get it started on boot:
The service i created for zigbee2mqtt (set it up in /etc/systemd/system/zigbee2mqtt.service) works fine.
however, when i try to create a service for the knob "knob.service" either in /etc/systemd/system/ or in /lib/systemd/system/ it doesnt want to work...
i have the feeling that the problem might be on when to start. I have tried different possibilities but nothing worked. My current file is the following, starting after the zigbee2mqtt.service, thinking that it might need that one working before starting (??):
[Unit]
After=zigbee2mqtt.service
StartLimitIntervalSec=10
StartLimitBurst=10
[Service]
Type=simple
ExecStart=python3 /home/marcosch/knob.py
Restart=always
RestartSec=1
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=knob
User=root
Group=root
[Install]
WantedBy=graphical.target
and what i get when i try to start it from the command prompt is:
marcosch@raspcamilla:~$ sudo systemctl start knob
marcosch@raspcamilla:~$ systemctl status knob.service
● knob.service
Loaded: loaded (/lib/systemd/system/knob.service; enabled; preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Mon 2023-01-02 09:30:25 CET; 359ms ago
Process: 27810 ExecStart=python3 /home/marcosch/knob.py (code=exited, status=1/FAILURE)
Main PID: 27810 (code=exited, status=1/FAILURE)
CPU: 444ms
and if i check what is going on with:
sudo journalctl -u knob.service -f
i get this output continuously:
Jan 02 09:48:27 raspcamilla systemd[1]: Started knob.service.
Jan 02 09:48:27 raspcamilla knob[28541]: Traceback (most recent call last):
Jan 02 09:48:27 raspcamilla knob[28541]: File "/home/marcosch/knob.py", line 3, in <module>
Jan 02 09:48:27 raspcamilla knob[28541]:
import paho.mqtt.client as mqtt
Jan 02 09:48:27 raspcamilla knob[28541]:
ModuleNotFoundError: No module named 'paho'
Jan 02 09:48:27 raspcamilla systemd[1]: knob.service: Main process exited, code=exited, status=1/FAILURE
Jan 02 09:48:27 raspcamilla systemd[1]: knob.service: Failed with result 'exit-code'.
Jan 02 09:48:28 raspcamilla systemd[1]: knob.service: Scheduled restart job, restart counter is at 25169.
Jan 02 09:48:28 raspcamilla systemd[1]: Stopped knob.service.
highlighted lines are mine.
Any idea what could i try??
thanks!!
Latest progress: