Python Plugin: Shelly MQTT

Python and python framework

Moderator: leecollings

leby
Posts: 98
Joined: Monday 28 July 2014 9:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Stockholm
Contact:

Re: Python Plugin: Shelly MQTT

Post by leby »

Thx lwolf, not sure whats goes wrong but I tried to follow the instructions you pointed out.
In this installation I have a Pi3 with raspbian-stretch-lite that is updated.
I have Python 3.5 installed.

It was two different jessie or wheezy to chosse from, I don't know but earlier versions of Pi
installation instructions points to jesse so i choose that one.

I get this error, any one that cant point me in any direction?

Code: Select all

/etc/apt/sources.list.d $ sudo apt-get install mosquitto
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 mosquitto : Depends: libssl1.0.0 (>= 1.0.0) but it is not installable
             Depends: libwebsockets3 (>= 1.2) but it is not installable
E: Unable to correct problems, you have held broken packages.
/lennart
lwolf
Posts: 216
Joined: Saturday 10 November 2018 18:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Hungary
Contact:

Re: Python Plugin: Shelly MQTT

Post by lwolf »

leby wrote: Monday 21 January 2019 6:53 In this installation I have a Pi3 with raspbian-stretch-lite that is updated.


It was two different jessie or wheezy to chosse from, I don't know but earlier versions of Pi
installation instructions points to jesse so i choose that one.
Its a little fuzzy... wheezy, jessie and stretch is 3 different version, stretch is the current. Mixing versions is not a good choice.

https://www.raspberrypi.org/forums/view ... p?t=198213

https://github.com/eclipse/mosquitto/issues/529

If you are using Raspbian Stretch, try:

Code: Select all

cd /etc/apt/sources.list.d/
rm mosquitto-jessie.list
wget http://repo.mosquitto.org/debian/mosquitto-stretch.list
apt-get update
apt-get install libwebsockets-dev mosquitto
leby
Posts: 98
Joined: Monday 28 July 2014 9:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Stockholm
Contact:

Re: Python Plugin: Shelly MQTT

Post by leby »

Thx @lwolf now it looks better, with a bit of luck the shelly should arive in a few days so I can test but now I get this

Code: Select all

pi@raspberrypi:~/domoticz/plugins $ sudo netstat -tlnp | grep mosq
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN      24774/mosquitto            
tcp6       0      0 :::1883                 :::*                    LISTEN      24774/mosquitto 
I think at least that above means to the MQTT server is installed and listening...
Not sure if I did the next thing correct but I removed phyton 2.7 and now have

Code: Select all

pi@raspberrypi:/etc $ python3 -V
Python 3.5.3
pi@raspberrypi:
then installed according to your instructions. well I will see in a few days.. thx for now
/lennart
besix
Posts: 99
Joined: Friday 25 January 2019 11:33
Target OS: Linux
Domoticz version: beta
Location: Poland
Contact:

Re: Python Plugin: Shelly MQTT

Post by besix »

Hi @lwolf
I installed the Python plugin to integrate Shelly MQTT with Domoticzem. Now I have to test only Shelly 1.
The plugin works, and I'm glad I only have a question
Why the plugin adds new 2 device?
The first is a switch and is Ok
What is this second?
Sorry for my English I'm Polish and I know the language
Intercede photo for a better understanding of the

Image

Image
lwolf
Posts: 216
Joined: Saturday 10 November 2018 18:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Hungary
Contact:

Re: Python Plugin: Shelly MQTT

Post by lwolf »

besix wrote: Friday 25 January 2019 12:26 The plugin works, and I'm glad I only have a question
Why the plugin adds new 2 device?
The first is a switch and is Ok
Hi!
From firmware version 1.4 Shelly supports "detached buttons".
The normal behavior is that "input" and "relay" state is equal, when the Shelly switch (SW) input changes, than the relay output will change. (of course there are also selectable multiple button behaviou switch/momentary in the Shelly WebGUI)
In detached mode, if you press the Switch on Shelly, than it reports back the changes to the MQTT server, but do not change the relay state.

This device is created by the plugin automatically, but can be changed manually to "not in use" state. (if you delete it, the plugin will recreate it, as shelly's publishes it's state)
besix
Posts: 99
Joined: Friday 25 January 2019 11:33
Target OS: Linux
Domoticz version: beta
Location: Poland
Contact:

Re: Python Plugin: Shelly MQTT

Post by besix »

@Iwolf Hello
Thank you very much for great info.
I am ordering shelly 2 for roller blinds, I hope it will work like shelly 1
Have a nice weekend
leby
Posts: 98
Joined: Monday 28 July 2014 9:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Stockholm
Contact:

Re: Python Plugin: Shelly MQTT

Post by leby »

@Iwolf I seem to have no luck getting the Shelly to report back to Domoticz. No new device is turning up.
I attache some screenshots on the config, probably some mistake from my side, any help appreciated.

192.168.1.22 is the IP of Domoticz

/lennart
Skärmklipp0.JPG
Skärmklipp0.JPG (59.12 KiB) Viewed 5386 times
Skärmklipp1.JPG
Skärmklipp1.JPG (77.39 KiB) Viewed 5386 times
Skärmklipp2.JPG
Skärmklipp2.JPG (45.93 KiB) Viewed 5386 times
/lennart
lwolf
Posts: 216
Joined: Saturday 10 November 2018 18:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Hungary
Contact:

Re: Python Plugin: Shelly MQTT

Post by lwolf »

leby wrote: Tuesday 29 January 2019 6:43 @Iwolf I seem to have no luck getting the Shelly to report back to Domoticz. No new device is turning up.
Devices only appears if "accept Devices" settings enabled in Domoticz, and the device sends an mqtt message.
Image
leby
Posts: 98
Joined: Monday 28 July 2014 9:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Stockholm
Contact:

Re: Python Plugin: Shelly MQTT

Post by leby »

Thx, but I have that to accept as per your screenshot.. any other idea?
/lennart
leby
Posts: 98
Joined: Monday 28 July 2014 9:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Stockholm
Contact:

Re: Python Plugin: Shelly MQTT

Post by leby »

Hi again, did like most here i guess and scanned internet for knowledge. I have not been able to solve why I cant get the Shelly up in the device list but fund a test tool that might say something to someone more knowledgeable than me.

The tool detects both the broker and the shelly client, it also say that the broker has 3 clients indicating that it is my 2 shellys and the test tool that is connected (well this is my armature conclusions).

What could I have missed in the phyton part that is typical beginner mistakes?

Accept hardware is on:
acceptHW.JPG
acceptHW.JPG (25.43 KiB) Viewed 5334 times
Subscribing to the Shelly works:
MQTT.fx.JPG
MQTT.fx.JPG (85.6 KiB) Viewed 5334 times
The broker also looks ok as far as I can tell:
MQTT.fx.2.JPG
MQTT.fx.2.JPG (80.78 KiB) Viewed 5334 times
Anyone that can point me in some directions?
/lennart
leby
Posts: 98
Joined: Monday 28 July 2014 9:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Stockholm
Contact:

Re: Python Plugin: Shelly MQTT

Post by leby »

Finally solved :-) Unfortunately I cant be sure what solved since I made the mistake to do several changes between testing.
I did fiddle with the Python though.

1) made a new install and compiled the package on the rpi
2) installed "sudo apt install python3-dev"
3) Added this line "alias python='/usr/bin/python3'" to the .bashrc that made Pyhton3 as default version to be used

after this actions an a reboot a new HW turned up in the list:
newhw.JPG
newhw.JPG (41.1 KiB) Viewed 5333 times
Then toggled the Shelly and they all poped up as they should, great!!

I did however see when I hade the MQTT.fx tool running that Domoticz published sensor info on the network.
To minimize interference I therefor changed broker publish to "None"
none.JPG
none.JPG (54.69 KiB) Viewed 5333 times
Many thanks for the plugin @iwolf
/lennart
Thorgal789
Posts: 850
Joined: Wednesday 15 August 2018 14:38
Target OS: -
Domoticz version:
Contact:

Re: Python Plugin: Shelly MQTT

Post by Thorgal789 »

Hi, first thx for the plugin, but I have a question, why have you used mqtt ?
It's just http api, you can make the plugin interact directly with the device, why have you added intermediary, there is a reason for that ?
lwolf
Posts: 216
Joined: Saturday 10 November 2018 18:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Hungary
Contact:

Re: Python Plugin: Shelly MQTT

Post by lwolf »

Thorgal789 wrote: Sunday 03 February 2019 18:29 Hi, first thx for the plugin, but I have a question, why have you used mqtt ?
It's just http api, you can make the plugin interact directly with the device, why have you added intermediary, there is a reason for that ?
Hi,
Not sure what you mean under "intermediary" and "just http api".
Shellies supports HTTP API and MQTT API also.

Shelly devices could be polled one-by-one with HTTP, if you knew they IP addresses but why? Sending commands to a device is only a part of the story, there has to be some status messages... Do you think that polling several IP addresses through HTTP in every second is more efficient than connecting only one address: the MQTT broker, which will let you know almost instantly if there are anything changed? Such as a user pushed a detached Shelly button...
I do not think so.

This plugin grabs incoming MQTT messages from Shellies, and updates or creates the appropriate Domoticz device, and forwards incoming messages from Domoticz to the appropriate MQTT path. There are no HTTP parts in it.
lwolf
Posts: 216
Joined: Saturday 10 November 2018 18:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Hungary
Contact:

Re: Python Plugin: Shelly MQTT

Post by lwolf »

leby wrote: Saturday 02 February 2019 12:37 I did however see when I hade the MQTT.fx tool running that Domoticz published sensor info on the network.
To minimize interference I therefor changed broker publish to "None"
none.JPG
I am very glad, that you can make it work.
But i am a little confused about the second image in your post. ShellyMQTT has nothing to do with "MQTT Client Gateway with LAN interface". And in fact they are using different topic's (shellies/#, domoticz/in, domoticz/out) and it is unlikely to ever interfere with each other's operation. Unless you are using the same IDX that Domoticz assigned to a Shelly device in an other device also, such as a Sonoff-Tasmota through standard MQTT. :D
leby
Posts: 98
Joined: Monday 28 July 2014 9:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Stockholm
Contact:

Re: Python Plugin: Shelly MQTT

Post by leby »

I am very glad, that you can make it work.
But i am a little confused about the second image in your post. ShellyMQTT has nothing to do with "MQTT Client Gateway with LAN interface". And in fact they are using different topic's (shellies/#, domoticz/in, domoticz/out) and it is unlikely to ever interfere with each other's operation. Unless you are using the same IDX that Domoticz assigned to a Shelly device in an other device also, such as a Sonoff-Tasmota through standard MQTT. :D


Probably only me that misunderstood how to set it up in the first place. Do I understand you correctly that I can scrap the "MQTT Client Gateway with LAN interface" and only using the HW "Shelly MQTT"?

btw, have Allterco Robotics supplied you with a 2.5 version so we can expect support for that one also?
/lennart
Thorgal789
Posts: 850
Joined: Wednesday 15 August 2018 14:38
Target OS: -
Domoticz version:
Contact:

Re: Python Plugin: Shelly MQTT

Post by Thorgal789 »

lwolf wrote: Monday 04 February 2019 10:34
Thorgal789 wrote: Sunday 03 February 2019 18:29 Hi, first thx for the plugin, but I have a question, why have you used mqtt ?
It's just http api, you can make the plugin interact directly with the device, why have you added intermediary, there is a reason for that ?
Hi,
Not sure what you mean under "intermediary" and "just http api".
Shellies supports HTTP API and MQTT API also.

Shelly devices could be polled one-by-one with HTTP, if you knew they IP addresses but why? Sending commands to a device is only a part of the story, there has to be some status messages... Do you think that polling several IP addresses through HTTP in every second is more efficient than connecting only one address: the MQTT broker, which will let you know almost instantly if there are anything changed? Such as a user pushed a detached Shelly button...
I do not think so.

This plugin grabs incoming MQTT messages from Shellies, and updates or creates the appropriate Domoticz device, and forwards incoming messages from Domoticz to the appropriate MQTT path. There are no HTTP parts in it.
Sorry, I m ready better the doc, no websoket for HTTP API so MQTT obligatory, I thought I had read there is a websocket on it (mistake with webserver !).
zygios
Posts: 15
Joined: Saturday 01 December 2018 6:42
Target OS: Linux
Domoticz version:
Contact:

Re: Python Plugin: Shelly MQTT

Post by zygios »

Hi,
Maybe someone can help me with Shelly 2 and Shelly MQTT plugin.
On my Domotincz I already have Device MQTT Client Gateway with LAN interface switch send/receives information from DIY devices.
I installed Shelly MQTT plugin and directed to same IP. After enabling Shellt MQTT Domoticz server crash, restarting is not helping, only deleting Shelly MQTT plugin and restarting Domoticz start to work.

I tryed to disable my currect MQTT Client Gateway with LAN interface and install Shelly MQTT and it works perfectly with Shelly2 (5 new devices found and I can control it from Domoticz).

How to make connections to same mqtt server?
lwolf
Posts: 216
Joined: Saturday 10 November 2018 18:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Hungary
Contact:

Re: Python Plugin: Shelly MQTT

Post by lwolf »

zygios wrote: Monday 04 February 2019 19:01 I tryed to disable my currect MQTT Client Gateway with LAN interface and install Shelly MQTT and it works perfectly with Shelly2 (5 new devices found and I can control it from Domoticz).
How to make connections to same mqtt server?
I tried it on several occasions, and on my configurations it works perfectly with several Tasmota joining onto the same MQTT gateway, than the ShellyMQTT.
There are reports, that under Ubuntu 16.04 the Domoticz crashes with python plugins, but with 18.04 it works flawlessly:
https://github.com/enesbcs/Shelly_MQTT/issues/5
But honestly, without knowing your settings, and linux and domoticz logfiles around that event there are nothing to say about.
zygios
Posts: 15
Joined: Saturday 01 December 2018 6:42
Target OS: Linux
Domoticz version:
Contact:

Re: Python Plugin: Shelly MQTT

Post by zygios »

I'm running on ARMBIAN 5.60 stable Ubuntu 18.04.1 LTS 4.14.84-sunxi
Python 3.6.7 version.

Mqtt:
MQTT Client Gateway with LAN interface 192.168.6.40 1883
Shelly MQTT 192.168.6.40 1883
Shelly 2 with The current Firmware version of your Shelly device is 20190122-162045/v1.4.5@5cbc6229 No newer firmware available.

How to get domoticz logfiles?
lwolf
Posts: 216
Joined: Saturday 10 November 2018 18:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Hungary
Contact:

Re: Python Plugin: Shelly MQTT

Post by lwolf »

leby wrote: Monday 04 February 2019 14:22 Probably only me that misunderstood how to set it up in the first place. Do I understand you correctly that I can scrap the "MQTT Client Gateway with LAN interface" and only using the HW "Shelly MQTT"?
Yep, MQTT Client Gateway with LAN interface only for devices that supports Domoticz (ESPEasy, Tasmota, ESPurna...).
Shelly is another one, which uses MQTT an other way, this is what ShellyMQTT understand. As you can see the installation instructions page:
https://github.com/enesbcs/Shelly_MQTT
there are no mention about MQTT Client Gateway.. as it is not needed.
leby wrote: Monday 04 February 2019 14:22 btw, have Allterco Robotics supplied you with a 2.5 version so we can expect support for that one also?
Currently there are no further discussions from Allterco about the integration of additional Shelly devices for Domoticz.
I only bought Shelly1, because this is the only type i needed, and made a plugin to use it with Domoticz. After that they were sent me from types that most users missed (That's what I thank them in this way.). :)
However I assume that v2.5 uses the same protocol the same way, as the Shelly2 earlier. We can see when it published.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest