enesbcs / shellyteacher4domo

Shelly device teacher for Domoticz MQTT Autodiscovery hardware
Apache License 2.0
10 stars 4 forks source link

Problems when trying to run teacher #23

Closed naeblizz closed 1 year ago

naeblizz commented 1 year ago

Hi . Im getting this when trying to run shellyteacherdomo.py "Traceback (most recent call last): File "shellyteacher4domo.py", line 79, in class MQTTClient(mqtt.Client): # Gen1 detailed infos and Gen2 alive NameError: name 'mqtt' is not defined" Im not so good with linux so maybe someone can tell me what's wrong?

enesbcs commented 1 year ago

You have to install paho-mqtt first, if you want to use the linux version, its on the readme:

pip3 install paho-mqtt

Or simply use the windows precompiled binary: https://github.com/enesbcs/shellyteacher4domo/releases/tag/0.03

naeblizz commented 1 year ago

Ok I have installed it. But still got the same message when trying to run the teacher, "Installing collected packages: paho-mqtt Successfully installed paho-mqtt-1.6.1" Do you need to start the mqtt client manually ?

enesbcs commented 1 year ago

Ok I have installed it. But still got the same message when trying to run the teacher, "Installing collected packages: paho-mqtt Successfully installed paho-mqtt-1.6.1" Do you need to start the mqtt client manually ?

Please download latest shellyteacher4domo from github.

Could you add some details about your installation? Linux family and version, exact python version?

naeblizz commented 1 year ago

Sure. Rpi 3b running Raspbian GNU/Linux 10 Kernel: Linux 5.10.103-v7+ Python Version: 22.3.1

enesbcs commented 1 year ago

Python Version: 22.3.1

There is no such python version. Latest python is 3.11.5

This is mine, for example:

python3 -V
Python 3.10.12
naeblizz commented 1 year ago

Sry thaught it was the pip3 version. Python 3.7.3

enesbcs commented 1 year ago

I have installed a Debian 10 which is basicly the same as Raspbian 10 Buster. It has Python 3.7.3 as your installation and i think i had an educated guess about your problem.

When you are running pip3 install paho-mqtt it will install the package into the actual user home directory and if you are running shellyteacher as other user or with sudo, it wont see that.

Try to use elevated installation of the paho-mqtt package like: sudo pip3 install paho-mqtt

OR make a su command to elevate yourself to root, before executing pip3 install paho-mqtt.

When i removed paho-mqtt with pip3 uninstall paho-mqtt i've got the same error message as you got earlier: 'mqtt' is not defined. After i installed with sudo pip3 install paho-mqtt the error message disappeared.

But i repeat myself: if you are not an experienced linux console user, the Teacher windows binary can be downloaded and can be run on ANY PC (not just the server) on the same network, as your MQTT server.

naeblizz commented 1 year ago

Ok . Thank you for all help you give me . I did install it with sudo but still got the same problem. I did as you advised and ran the windows version . I have all up running , the teacher is connected to broker . And shelly devices , teacher, and domoticz mqtt autodiscovery set to same prefix topic. But no devices is showing up in domoticz. Is it possible to see if teacher finds any devices in a log?

enesbcs commented 1 year ago

I hope you do not set shelly devices report topic the same as the autodiscovery topic. Autodiscovery configs arrives as default into 'homeassistant/', Domoticz awaits configs at "homeassitant/". Shelly Gen1 devices uses 'shellies/SHELLYID/' topics for reporting data and announcing itself, Gen2 devices uses 'SHELLYID/' topics for data reporting. Yep the MQTT server needs to be the same at all three, i hope you do not use 127.0.0.1 or localhost address, as it is only working on the server.

After first start of the Teacher you have to set up MQTT server actual IP, prefix, enable Retain, press "Save settings", then you can press "Start".

ShellyTeacher

And that point you have to restart Shelly devices to force them to send announce messages through MQTT. No announce messages = No detection

As you see it has a log, when it found the SHBTN-2 it wrote onto the console....

naeblizz commented 1 year ago

Ok. No the teacher is connected to mqtt broker like it should with ip of server . I have checked it with Mqtt explorer. But mine dosen't recognize any devices in log like yours did. I have a shelly plus 1, and a shelly i4. Could it be some settings in shellys mqtt settings that make it dont recognize it?

naeblizz commented 1 year ago

This is how my shellies look in mqtt explorer. Skärmbild 2023-09-23 175639

enesbcs commented 1 year ago

Please download latest 0.4 release, it has now a working console mode: https://github.com/enesbcs/shellyteacher4domo/releases/download/0.04/shellyteacher_win_004.zip

In case the default GUI method is not working/not showing results, please start exe in command line with -c parameter as: shellyteacher4domo_win_x64.exe -c

Could you post an image of shellyteacher window, after teacher started, settings saved and Start detection loop pressed, with Shelly i4 restarted after "Detection started" appears in log?

When the teacher receives MQTT topic: "shellyplus1-ID/online" payload: true it will send back a messege to topic: "shellyplus1-ID/rpc" with {"id": 1, "src":"shellies_discovery", "method":"Shelly.GetConfig"} which will post the device data to "shellies_discovery/" MQTT topic. Neither /rpc, nor shellies_discovery/ are seen on your screenshot, the only explanation is that the Teacher has no working MQTT connection. (and please enable "Show debug messages" at settings)

naeblizz commented 1 year ago

Darn. It seems to have been the version of the shelly teacher. It worked right away after I downloaded 0.4 . Thank you for all help and patience. Really nice work

enesbcs commented 1 year ago

Thanks for testing! Closing issue now.