Python Plugin: Shelly MQTT

Python and python framework

Moderator: leecollings

User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Python Plugin: Shelly MQTT

Post by FireWizard »

Hello @Cronosm

Unfortunately I do not own a Shelly Plus device, but I do own a Shelly Dimmer2, which is 1st generation.
For the plus you will need the 2nd generation.

I do not know, what the difference is (except the protocol), but with some modification the flow might be useful.


Screenshot_Shelly_flow.png
Screenshot_Shelly_flow.png (25.78 KiB) Viewed 3783 times
Are you interested?

Regards
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python Plugin: Shelly MQTT

Post by waltervl »

CronoS wrote: Friday 18 November 2022 15:38 Does anyone has a working Node Red Node for the Shelly Plus devices? This because the Shelly MQTT plugin is not compatible.

Perhaps you can use the mqttmapper plugin. viewtopic.php?t=39279
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
CronoS
Posts: 135
Joined: Wednesday 15 July 2015 23:40
Target OS: -
Domoticz version:
Contact:

Re: Python Plugin: Shelly MQTT

Post by CronoS »

waltervl wrote: Friday 18 November 2022 21:04
CronoS wrote: Friday 18 November 2022 15:38 Does anyone has a working Node Red Node for the Shelly Plus devices? This because the Shelly MQTT plugin is not compatible.

Perhaps you can use the mqttmapper plugin. viewtopic.php?t=39279
This looks interesting... I will have a look at it!
mastadook
Posts: 58
Joined: Wednesday 18 April 2018 13:03
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Deutschland
Contact:

Re: Python Plugin: Shelly MQTT

Post by mastadook »

mastadook wrote: Wednesday 02 November 2022 14:16 Hi All,

one Question regarding this Plugin and Shelly3EM:
Will there a Power Device created automatically?
In my Setup it creates 3 Devices per Phase:
1 Current in A
2 Voltage in V
3 Powerfactor
But no Device for Power but via mqtt Explorer I can see that the Shelly send all needed data.

What I am doing wrong?
The Plugin is the newest one and Domoticz is Version 2022.1 Stable
I try to use the mqtt auto detection Plugin also, but there I got very much Error Messages.
No one with Idea here?
Attachments
Errormessage
Errormessage
errormessages_1.jpg (373.22 KiB) Viewed 3738 times
Scan from mqtt Explorer showing that the Data will be send
Scan from mqtt Explorer showing that the Data will be send
errormessages_2.jpg (228.08 KiB) Viewed 3738 times
________________________________________________________________________
global chief of permanent lightning and strike detonator
User avatar
Sjonnie2017
Posts: 361
Joined: Wednesday 02 August 2017 19:43
Target OS: Linux
Domoticz version: Latest ß
Location: The Netherlands
Contact:

Re: Python Plugin: Shelly MQTT

Post by Sjonnie2017 »

Thank you @iwolf for this plugin and most importantly for keeping it up to date!

I switched to your plugin today using Mosquitto in a docker (since al my applications run in a Docker nowadays :) ) and after some fiddling I now have complete control over my Shelly 2.5 roller shutter devices after some problems after upgrading to 2022.2.

Much appreciated!
ConBee II - TRÅDFRI lights + switches, loads of ChingLing dimmers and switches, Heiman and Xiaomi sensors
SolarEdge SE4000H (with active modbus_tcp)
YouLess Energy meter
Shelly 2.5 in roller shutter mode
Robinjoo94
Posts: 21
Joined: Saturday 25 May 2019 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Contact:

Re: Python Plugin: Shelly MQTT

Post by Robinjoo94 »

Robinjoo94 wrote: Monday 14 March 2022 15:17
ProjektC wrote: Wednesday 09 March 2022 20:00 But it's not clear to me how I can just turn anything on and off.
Or how I can assign the commands somewhere to a lamp or scene.
So I'm not sure if that works at all.
Have a look at: https://www.domoticz.com/wiki/Events
Robinjoo94 wrote: Monday 07 March 2022 17:47
waltervl wrote: Monday 07 March 2022 16:33 Is MQTT broker (eg mosquitto) running on the same server or a different one?
As it seems that the disconnecting issue could trigger the crash (it should not).
Perhaps another issue in your environment that is triggering this? Wifi issues, Network issues, Memory issues?
Yes, running on the same Raspberry Pi.
Will keep an eye on the logs upcoming days.
So I still do not have a clear cause for my issues.
I now have a "watchdog" script running that restarts domoticz whenever went to "active (exited)".
Added a simple script/domoticz device to track the memory consumption, there seems to be some memory leak, but the error happens already when the memory consumption is at 70%, so too early in my oppinion to be caused by memory issues.
I will have to add some more monitoring to get to the root cause.
Almost 10 months with the same issue... even updated to Domoticz Stable 2022.2, and pulled the latest changes from the plugin.
Happens multiple times a day:

Code: Select all

2022-12-01 03:52:19.038  Error: Domoticz(pid:23351, tid:23366('Shelly MQTT')) received fatal signal 11 (Segmentation fault)
2022-12-01 03:52:19.040  Error: siginfo address=0x5b37, address=(nil)
2022-12-01 03:52:22.802  Error: Thread 14 (Thread 0x6edff200 (LWP 23366)):
2022-12-01 03:52:22.802  Error: #0  __waitpid (options=0, stat_loc=0x6edfde18, pid=29392) at ../sysdeps/unix/sysv/linux/waitpid.c:30
2022-12-01 03:52:22.802  Error: #1  __waitpid (pid=29392, stat_loc=0x6edfde18, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:25
2022-12-01 03:52:22.802  Error: #2  0x00279814 in dumpstack_gdb(bool) ()
2022-12-01 03:52:22.802  Error: #3  0x00279de0 in signal_handler(int, siginfo_t*, void*) ()
2022-12-01 03:52:22.802  Error: #4  <signal handler called>
2022-12-01 03:52:22.802  Error: #5  raise (sig=11) at ../sysdeps/unix/sysv/linux/raise.c:50
2022-12-01 03:52:22.802  Error: #6  <signal handler called>

Code: Select all

2022-12-01 16:34:15.463  Error: Domoticz(pid:27707, tid:27722('Shelly MQTT')) received fatal signal 11 (Segmentation fault)
2022-12-01 16:34:15.464  Error: siginfo address=0x6c3b, address=(nil)
2022-12-01 16:34:19.120  Error: Thread 14 (Thread 0x6edff200 (LWP 27722)):
2022-12-01 16:34:19.120  Error: #0  __waitpid (options=0, stat_loc=0x6edfde00, pid=19282) at ../sysdeps/unix/sysv/linux/waitpid.c:30
2022-12-01 16:34:19.120  Error: #1  __waitpid (pid=19282, stat_loc=0x6edfde00, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:25
2022-12-01 16:34:19.120  Error: #2  0x00279814 in dumpstack_gdb(bool) ()
2022-12-01 16:34:19.120  Error: #3  0x00279de0 in signal_handler(int, siginfo_t*, void*) ()
2022-12-01 16:34:19.120  Error: #4  <signal handler called>
2022-12-01 16:34:19.120  Error: #5  raise (sig=11) at ../sysdeps/unix/sysv/linux/raise.c:50
2022-12-01 16:34:19.120  Error: #6  <signal handler called>
2022-12-01 16:34:19.120  Error: #7  0x75c8cd2c in ?? () from /lib/arm-linux-gnueabihf/libpython3.7m.so
2022-12-01 16:34:19.120  Error: #8  0x75c8d19c in ?? () from /lib/arm-linux-gnueabihf/libpython3.7m.so
Anyone has an idea? Although my "watchdog" script is ensuring functionality, I am not too happy with the instability.
mk01
Posts: 5
Joined: Thursday 22 December 2022 5:46
Target OS: Linux
Domoticz version:
Contact:

Re: Python Plugin: Shelly MQTT

Post by mk01 »

guys,

two days ago I deployed bunch of Pro 4PM to my place. I'm using Shelly-MQTT since --- basically since I deployed Domoticz and with some smallish fixes to deal properly with power&energy on Gen1 devices, it served me ever since (zero maintenance most importantly),

after spending few minutes with the physical installation, I then spent MANY hours looking for optiions here, which none of them seem to provide a way moving ahead without some struggles. and as I like things which just work (specially if already deployed), I finally approached the problem from the other side.
it seems those Gen2 boxes took the term "open system" to completely different level with the JS-like scriptings and in few minutes I made the boxes understand how to speak Gen1 language (relay providing power/energy/total data). I won't be controlling them - so now just the power/energy (and total) sensor is exposed. Anyhow, as the code-pluggable architecture is SO EASY to write and use, I will add the switching control too. Voltage & current sensors are also no brainer ... and that's it for the 4PM box.

If anyone still looking for a way to integrate Gen2 device with PM with no other changes into existing setup like I was, here goes the extention. Installation is easy, just use browser, go to your device, on the left "<> scripts", click add script, add the code, click save, enable the script (for auto-start on device boot - or just click the "play" icon for runtime testing it) and thats it. It uses the MQTT configuration from the device itself - specifically mqtt server address + user/pass. topic/prefix is just so it works automatically with Shelly-MQTT (using device-id as name of the device).

the announce and data msgs are managed within the script extension.

After the script is enabled and device rebooted (or script started manually) in maximum 60s seconds you will see the new devices being created (if auto-creation enabled).
As already being said, I use it with mine Pro4PM boxes, but it should work exactly the same on any Gen2 device with PM function.

script available at

https :// github com /mk01/shelly-2to1-mqtt

mk
Attachments
devices.jpg
devices.jpg (240.42 KiB) Viewed 3569 times
mqtt-setup.jpg
mqtt-setup.jpg (222.79 KiB) Viewed 3569 times
add-script.jpg
add-script.jpg (85.37 KiB) Viewed 3569 times
patvandijk
Posts: 8
Joined: Thursday 10 April 2014 17:20
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Shelly MQTT

Post by patvandijk »

Hi,

Thanks for this. I have a Shelly Plus1PM which also seems to have the gen:2 version.
I've used your code and now see a switch in Domoticz but no power readings.
shelly1pm.jpg
shelly1pm.jpg (77 KiB) Viewed 3445 times
In Domoticz all I see is a switch
domoticz.jpg
domoticz.jpg (26.87 KiB) Viewed 3445 times
Is there info missing in the announce part?
Any help appreciated


EDIT: Oh, my....just found it....just enable Power and Energy....on the Shelly MQTT Plugin...
shelly_mqtt.jpg
shelly_mqtt.jpg (111.95 KiB) Viewed 3435 times
mk01
Posts: 5
Joined: Thursday 22 December 2022 5:46
Target OS: Linux
Domoticz version:
Contact:

Re: Python Plugin: Shelly MQTT

Post by mk01 »

patvandijk wrote: Wednesday 11 January 2023 9:35 EDIT: Oh, my....just found it....just enable Power and Energy....on the Shelly MQTT Plugin...
shelly_mqtt.jpg
Good point, will add that to readme.

I added support for INPUTS as well, so if you want to use it grab the latest version from github.

mk
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 »

Shelly Plus 1 can be teached to work with plain Domoticz MQTT Autodiscovery hardware by manually or by running this script once:
https://github.com/enesbcs/shellyteacher4domo
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 »

Robinjoo94 wrote: Thursday 01 December 2022 18:40 Anyone has an idea? Although my "watchdog" script is ensuring functionality, I am not too happy with the instability.
Yes. Do not use python plugins. Use Domoticz integrated hardwares only, such as Domoticz MQTT Autodiscovery. Almost any mqtt-able device can be teached by hand (eg. mosquitto_pub) if you know the rules of discovery config: https://home-assistant-china.github.io/ ... discovery/

I stopped using my own shellymqtt plugin instead using mqtt AutoDiscovery since 2022 when AD appeared in Domoticz.

For simplicity i started to write a script (not a plugin!) shellyteacher4domo
AimoPaukku
Posts: 43
Joined: Saturday 28 January 2017 9:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Contact:

Re: Python Plugin: Shelly MQTT

Post by AimoPaukku »

I cant find any devices with this.
I just want Shelly relay status to my domotics, On/Off

I see Shelly in my mqtt
My hardware has Shelly plugin and IP address is correct.

I cannot produce any script, and don't know what to do?

I have tried also add HTTP commands to shelly... Nothing happens in domotics dummy

Soon I will add z-wave sensor after shelly :evil:
Gravityz
Posts: 583
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Netherlands
Contact:

Re: Python Plugin: Shelly MQTT

Post by Gravityz »

did you turn on ACCEPT NEW HARDWARE DEVICES in settings?

after that switch on/off and a new device should be created.

you mention dummy device so i guess you use that one.

that will work also but you need to put in the correct http command in your shelly under I/O url actions

change the ip adress and port to the one you use and use the correct is for the domoticz switch(379 is the id of my domoticz switch)

on command

Code: Select all

http://192.168.1.50:8084/json.htm?type=command&param=switchlight&idx=379&switchcmd=On
off command

Code: Select all

http://192.168.1.50:8084/json.htm?type=command&param=switchlight&idx=379&switchcmd=Off
AimoPaukku
Posts: 43
Joined: Saturday 28 January 2017 9:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Contact:

Re: Python Plugin: Shelly MQTT

Post by AimoPaukku »

Gravityz wrote: Sunday 26 February 2023 21:24 did you turn on ACCEPT NEW HARDWARE DEVICES in settings?

after that switch on/off and a new device should be created.
I did that. Plugin does nothing
you mention dummy device so i guess you use that one.

that will work also but you need to put in the correct http command in your shelly under I/O url actions

change the ip adress and port to the one you use and use the correct is for the domoticz switch(379 is the id of my domoticz switch)

on command

Code: Select all

http://192.168.1.50:8084/json.htm?type=command&param=switchlight&idx=379&switchcmd=On
off command

Code: Select all

http://192.168.1.50:8084/json.htm?type=command&param=switchlight&idx=379&switchcmd=Off
I pasted mine, seem like same. These will work if I paste it it other browser, so problem in shelly or my network

Code: Select all

http://192.168.1.2:8080/json.htm?type=command&param=switchlight&idx=333&switchcmd=On
http://192.168.1.2:8080/json.htm?type=command&param=switchlight&idx=333&switchcmd=Off
This latest domotics update broke also my 3d printer octoprint plugin. ( there is another question)
Maybe these problems are related together, it worked for years, but after update it started to say
Status unknown for http://192.168.1.2:8080. Double check IP Address\Hostname in Domoticz Settings.
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Python Plugin: Shelly MQTT

Post by FireWizard »

Hi,

This error message looks like the "authentication" issue, that has come up in various Domoticz setups from different people.
Check your authentication, so that Domoticz is reachable.

Regards
AimoPaukku
Posts: 43
Joined: Saturday 28 January 2017 9:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Contact:

Re: Python Plugin: Shelly MQTT

Post by AimoPaukku »

I do not understand. How do i do that?

Something new to do with passwords?
I have had a password in use for a long time, and all worked just fine till now

Still my domoticz communicate to my heat pump via mqtt witn no problem
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python Plugin: Shelly MQTT

Post by waltervl »

Check the new security wiki page: https://www.domoticz.com/wiki/Security
Check Trusted Networks setting and the setting "Allow Basic Authentication over plain HTTP"
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
AimoPaukku
Posts: 43
Joined: Saturday 28 January 2017 9:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Contact:

Re: Python Plugin: Shelly MQTT

Post by AimoPaukku »

Hi. That one was also known by me too and ok.
I can control via HTTP using different browser. I have tested domoticz with Edge and commands from Chrome.

Everything is done like this, but my commands are above.
https://www.thesmarthomeblog.com/post/r ... /domoticz/
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 »

AimoPaukku wrote: Sunday 26 February 2023 20:47 I cant find any devices with this.
I just want Shelly relay status to my domotics, On/Off
Steps to use the teacher script:
- Add a "Domoticz MQTT Autodiscovery" hardware, set the MQTT broker address
https://www.domoticz.com/wiki/MQTT#Add_ ... Gateway.22

- Set the Shelly device to use the same MQTT broker, and enable MQTT of course
https://stevessmarthomeguide.com/introd ... elly-mqtt/

- Download and Run the teacher script as written at https://github.com/enesbcs/shellyteacher4domo

When you restart the Shelly device, it will announce itself on MQTT, and will be registered on Domoticz MQTT AD as a new device

Shelly_MQTT is not needed, neither any plugin. No need for dummy devices, idx, http urls, no need to produce scripts, just run it...
Domoticz AutoDiscovery (AD) MQTT communication is 2way so every registered device status will be in sync when wifi is working and mqtt broker is online of course.
AimoPaukku
Posts: 43
Joined: Saturday 28 January 2017 9:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Contact:

Re: Python Plugin: Shelly MQTT

Post by AimoPaukku »

Thanks.
I removed plugins etc and want to try again mqtt.

Mosquetto is online and I see my shelly in it.


Code: Select all

login as: pi
[email protected]'s password:
Linux raspberrypi 5.10.103-v7+ #1529 SMP Tue Mar 8 12:21:37 GMT 2022 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Mar  1 22:24:06 2023 from 192.168.1.21
pi@raspberrypi:~ $ sudo apt install python3-pip git
Luetaan pakettiluetteloita... Valmis
Muodostetaan riippuvuussuhteiden puu
Luetaan tilatiedot... Valmis
git is already the newest version (1:2.20.1-2+deb10u7).
python3-pip is already the newest version (18.1-5+rpt1).
0 päivitetty, 0 uutta asennusta, 0 poistettavaa ja 0 päivittämätöntä.
pi@raspberrypi:~ $ pip3 install paho-mqtt
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: paho-mqtt in ./.local/lib/python3.7/site-packages (1.6.1)
pi@raspberrypi:~ $ git clone https://github.com/enesbcs/shellyteacher4domo.git
fatal: destination path 'shellyteacher4domo' already exists and is not an empty directory.
pi@raspberrypi:~ $ git pull
fatal: not a git repository (or any of the parent directories): .git
pi@raspberrypi:~ $
This sounds so easy... Edit settings.py file with a plain text editor, and set MQTT server IP address.

How?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest