Python Plugin: Shelly MQTT
Moderator: leecollings
-
- Posts: 216
- Joined: Saturday 10 November 2018 18:29
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Hungary
- Contact:
Python Plugin: Shelly MQTT
If anyone interested, I've made a Python plugin for Shelly MQTT integration into Domoticz. Currently I have only got a Shelly1 device to test, but more will come soon.
I would like to thank the zigbee2mqtt project for it's nice MQTT library that i reused.
https://github.com/enesbcs/Shelly_MQTT
I would like to thank the zigbee2mqtt project for it's nice MQTT library that i reused.
https://github.com/enesbcs/Shelly_MQTT
-
- Posts: 18
- Joined: Thursday 15 November 2018 15:41
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Python Plugin: Shelly MQTT
Great, thats something I'm looking. My shelly devices will arrive soon (hope so). So I will test this soon.
Because I want to use Shelly2 for shutter control, do you think theres a way to get them support soon, too?
Thanks alot in advance
Georg
Because I want to use Shelly2 for shutter control, do you think theres a way to get them support soon, too?
Thanks alot in advance
Georg
-
- Posts: 216
- Joined: Saturday 10 November 2018 18:29
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Hungary
- Contact:
Re: Python Plugin: Shelly MQTT
My Shelly2 arrived yesterday, so i think roller shutter will be supported within a few days.
update: roller shutter is supported
-
- Posts: 18
- Joined: Thursday 15 November 2018 15:41
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Python Plugin: Shelly MQTT
Great job. Hopefully my devices will arrive this week. Can't wait for testing them.
Thanks alot for your work!
Thanks alot for your work!
-
- Posts: 11
- Joined: Sunday 10 January 2016 3:22
- Target OS: Linux
- Domoticz version: 3.8805
- Contact:
Re: Python Plugin: Shelly MQTT
Hello, I tried you plugin for a Shelly1.
I have Domoticz v3.8805 on linux amd_x64 with mosquitto on board and python version
I cloned repository into
Restarted domoticz.
I crated hw with mqtt server 127.0.0.1:1883.
Looking on domticz log I have
On mosquitto
How can I solve it?
Thanks
I have Domoticz v3.8805 on linux amd_x64 with mosquitto on board and python version
Code: Select all
python --version
Python 2.7.9
Code: Select all
/opt/domoticz/plugins/Shelly_MQTT
I crated hw with mqtt server 127.0.0.1:1883.
Looking on domticz log I have
Code: Select all
2018-12-03 12:16:28.464 (Shelly) Calling message handler 'onHeartbeat'.
2018-12-03 12:16:28.464 (Shelly) Heartbeating...
2018-12-03 12:16:28.464 (Shelly) Reconnecting
2018-12-03 12:16:28.464 (Shelly) MqttClient::Open
2018-12-03 12:16:28.464 (Shelly) MqttClient::Close
2018-12-03 12:16:28.464 (Shelly) Protocol set to: 'MQTT'.
2018-12-03 12:16:28.464 (Shelly) Transport set to: 'TCP/IP', 127.0.0.1:1883.
2018-12-03 12:16:28.464 (Shelly) Connect directive received, action initiated successfully.
2018-12-03 12:16:28.514 (Shelly) Calling message handler 'onConnect'.
2018-12-03 12:16:28.514 (Shelly) MQTT connected successfully.
2018-12-03 12:16:28.514 (Shelly) MqttClient::Connect
2018-12-03 12:16:28.514 (Shelly) MQTT CONNECT ID: 'Domoticz_1543835788'
2018-12-03 12:16:28.515 Error: (ProcessOutbound) Send request Python object parameter was not of type Unicode or Byte, ignored.
2018-12-03 12:16:28.515 (Shelly) Sending 0 bytes of data:
2018-12-03 12:16:28.965 (Shelly) Disconnect directive received for '127.0.0.1:1883'.
2018-12-03 12:16:28.965 (Shelly): CPluginTransportTCP::handleDisconnect
2018-12-03 12:16:29.015 (Shelly) Calling message handler 'onDisconnect'.
2018-12-03 12:16:29.016 (Shelly) MqttClient::onDisonnect Disconnected from: 127.0.0.1:1883
2018-12-03 12:16:29.016 (Shelly) MqttClient::Close
2018-12-03 12:16:29.016 (Shelly) onMQTTDisconnected
2018-12-03 12:16:29.466 (Shelly) Disconnect directive received for '127.0.0.1:1883'.
2018-12-03 12:16:29.466 (Shelly): CPluginTransportTCP::handleDisconnect
2018-12-03 12:16:29.517 (Shelly) Calling message handler 'onDisconnect'.
2018-12-03 12:16:29.517 (Shelly) MqttClient::onDisonnect Disconnected from: 127.0.0.1:1883
2018-12-03 12:16:29.517 (Shelly) MqttClient::Close
2018-12-03 12:16:29.517 (Shelly) onMQTTDisconnected
2018-12-03 12:16:38.479 (Shelly) Calling message handler 'onHeartbeat'.
2018-12-03 12:16:38.479 (Shelly) Heartbeating...
2018-12-03 12:16:38.479 (Shelly) Reconnecting
2018-12-03 12:16:38.479 (Shelly) MqttClient::Open
2018-12-03 12:16:38.479 (Shelly) Protocol set to: 'MQTT'.
2018-12-03 12:16:38.479 (Shelly) Transport set to: 'TCP/IP', 127.0.0.1:1883.
2018-12-03 12:16:38.479 PluginSystem: Starting I/O service thread.
2018-12-03 12:16:38.479 (Shelly) Connect directive received, action initiated successfully.
2018-12-03 12:16:38.529 (Shelly) Calling message handler 'onConnect'.
2018-12-03 12:16:38.529 (Shelly) MQTT connected successfully.
2018-12-03 12:16:38.529 (Shelly) MqttClient::Connect
2018-12-03 12:16:38.529 (Shelly) MQTT CONNECT ID: 'Domoticz_1543835798'
2018-12-03 12:16:38.530 Error: (ProcessOutbound) Send request Python object parameter was not of type Unicode or Byte, ignored.
2018-12-03 12:16:38.530 (Shelly) Sending 0 bytes of data:
Code: Select all
1543832868: New connection from 192.168.2.40 on port 1883.
1543832868: New client connected from 192.168.2.40 as shelly1-4A5936 (c1, k60).
Thanks
-
- Posts: 216
- Joined: Saturday 10 November 2018 18:29
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Hungary
- Contact:
Re: Python Plugin: Shelly MQTT
Please install Python 3.4 or newer following the Domoticz guide:gianfrdp wrote: ↑Monday 03 December 2018 12:18 Hello, I tried you plugin for a Shelly1.
I have Domoticz v3.8805 on linux amd_x64 with mosquitto on board and python versionHow can I solve it?Code: Select all
python --version Python 2.7.9
Thanks
https://www.domoticz.com/wiki/Using_Python_plugins
-
- Posts: 11
- Joined: Sunday 10 January 2016 3:22
- Target OS: Linux
- Domoticz version: 3.8805
- Contact:
Re: Python Plugin: Shelly MQTT
Sorry, I checked on domoticz log: I have
Code: Select all
2018-12-11 15:43:32.794 PluginSystem: Started, Python version '3.4.2'.
Code: Select all
python3 --version
Python 3.4.2
-
- Posts: 216
- Joined: Saturday 10 November 2018 18:29
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Hungary
- Contact:
Re: Python Plugin: Shelly MQTT
I've downgraded my Python 3.6.6 to the oldest possible 3.4.9 version, but i am unable to reproduce this error.gianfrdp wrote: ↑Tuesday 11 December 2018 15:52 Sorry, I checked on domoticz log: I have
Code: Select all
2018-12-11 15:43:32.794 PluginSystem: Started, Python version '3.4.2'.
Code: Select all
python3 --version Python 3.4.2
"Error: (ProcessOutbound) Send request Python object parameter was not of type Unicode or Byte, ignored."
I assume you purged the previously installed Python 2.x to not interfere with v3.4?
My test environment is producing the logs below with Verbose debug output and works fine:
Code: Select all
2018-12-11 20:25:55.567 Status: Domoticz V4.9701 (c)2012-2018 GizMoCuz
2018-12-11 20:25:55.868 Status: PluginSystem: Started, Python version '3.4.9'.
2018-12-11 20:25:58.384 (shelly) Debug logging mask set to: PYTHON PLUGIN DEVICE CONNECTION MESSAGE
2018-12-11 20:25:58.384 (shelly) MqttClient::__init__
2018-12-11 20:25:58.384 (shelly) MqttClient::Open
2018-12-11 20:25:58.384 (shelly) Protocol set to: 'MQTT'.
2018-12-11 20:25:58.384 (shelly) Transport set to: 'TCP/IP', 192.168.2.100:1883.
2018-12-11 20:25:58.384 PluginSystem: Starting I/O service thread.
2018-12-11 20:25:58.384 (shelly) Connect directive received, action initiated successfully.
2018-12-11 20:25:58.434 (shelly) MQTT connected successfully.
2018-12-11 20:25:58.435 (shelly) MqttClient::Connect
2018-12-11 20:25:58.435 (shelly) MQTT CONNECT ID: 'Domoticz_1544556358'
2018-12-11 20:25:58.435 (shelly) Sending 33 bytes of data
2018-12-11 20:25:58.435 (shelly) 10 1f 00 04 4d 51 54 54 04 02 00 3c 00 13 44 6f 6d 6f 74 69 ....MQTT...<..Domoti
2018-12-11 20:25:58.435 (shelly) 63 7a 5f 31 35 34 34 35 35 36 33 35 38 .. .. .. .. .. .. .. cz_1544556358
2018-12-11 20:25:58.485 (shelly) Received 4 bytes of data
2018-12-11 20:25:58.485 (shelly) 20 02 00 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ....
2018-12-11 20:25:58.485 (shelly) MqttClient::Subscribe
2018-12-11 20:25:58.485 (shelly) Sending 17 bytes of data
2018-12-11 20:25:58.485 (shelly) 82 0f 00 01 00 0a 73 68 65 6c 6c 69 65 73 2f 23 00 .. .. .. �.....shellies/#.
2018-12-11 20:25:58.535 (shelly) Received 5 bytes of data
2018-12-11 20:25:58.536 (shelly) 90 03 00 01 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. �....
2018-12-11 20:25:58.536 (shelly) onMQTTSubscribed
2018-12-11 20:25:58.342 Status: PluginSystem: Entering work loop.
2018-12-11 20:25:58.382 Status: (shelly) Initialized version 0.2.0
2018-12-11 20:25:58.384 Status: (shelly) Entering work loop.
2018-12-11 20:26:07.934 (shelly) Heartbeating...
2018-12-11 20:26:07.934 (shelly) MqttClient::Ping
2018-12-11 20:26:07.934 (shelly) Sending 2 bytes of data
2018-12-11 20:26:07.934 (shelly) c0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. �.
2018-12-11 20:26:07.985 (shelly) Received 2 bytes of data
2018-12-11 20:26:07.985 (shelly) d0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. �.
Domoticz.Connection() object has a Send() method and that is raising the error you sent.
However the mqtt.py that I've reused is in use by several other plugins, and i do not see any controversy that's code and the Domoticz Python documentation - which is not too long, neither talkative.
https://www.domoticz.com/wiki/Developin ... hon_plugin
Can you use any other MQTT or HTTP based Python plugin on your installation?
Do you have any specific reason for sticking old softwares, such as 4 year old python and Domoticz 3.8? I do not have this version, and do not know, how to downgrade to it, so the further debugging seems impossible to me.
You can try to change this code in mqtt.py from this:
Code: Select all
else:
ID = 'Domoticz_'+str(int(time.time()))
Domoticz.Debug("MQTT CONNECT ID: '" + ID + "'")
self.mqttConn.Send({'Verb': 'CONNECT', 'ID': ID})
Code: Select all
else:
try:
ID = 'Domoticz_'+str(int(time.time()))
Domoticz.Debug("MQTT CONNECT ID: '" + ID + "'")
self.mqttConn.Send({'Verb': 'CONNECT', 'ID': ID})
except Exception as e:
Domoticz.Debug("Unknown connection error: "+str(e))
-
- Posts: 11
- Joined: Sunday 10 January 2016 3:22
- Target OS: Linux
- Domoticz version: 3.8805
- Contact:
Re: Python Plugin: Shelly MQTT
Hello,
I have a Debian Jessie on a OpenMediaVault server, which provides
I installed a separate python3.5 on /usr/local, I have to understand how to force Domoticz to use it.
I will try also your suggested changes
I downgraded Domoticz to v3.8805 because last versions crash with signal 6.
I have no other python plugin.
Thanks
EDIT:
I tried another python plugin https://github.com/emontnemery/domoticz_mqtt_discovery with same error.
Searching into domoticz source files I found in https://github.com/domoticz/domoticz/bl ... tocols.cpp point where error message is printed
so I think it should be a general problem with domoticz version.
I will try to upgade domoticz and see what appens.
Thanks
I have a Debian Jessie on a OpenMediaVault server, which provides
Code: Select all
python 2.7.9-1
python3 3.4.2-2
I will try also your suggested changes
I downgraded Domoticz to v3.8805 because last versions crash with signal 6.
I have no other python plugin.
Thanks
EDIT:
I tried another python plugin https://github.com/emontnemery/domoticz_mqtt_discovery with same error.
Searching into domoticz source files I found in https://github.com/domoticz/domoticz/bl ... tocols.cpp point where error message is printed
Code: Select all
std::vector<byte> CPluginProtocol::ProcessOutbound(const WriteDirective* WriteMessage)
{
std::vector<byte> retVal;
// Handle Bytes objects
if ((((PyObject*)WriteMessage->m_Object)->ob_type->tp_flags & (Py_TPFLAGS_BYTES_SUBCLASS)) != 0)
{
const char* pData = PyBytes_AsString(WriteMessage->m_Object);
int iSize = PyBytes_Size(WriteMessage->m_Object);
retVal.reserve((size_t)iSize);
retVal.assign(pData, pData + iSize);
}
// Handle ByteArray objects
else if ((((PyObject*)WriteMessage->m_Object)->ob_type->tp_name == std::string("bytearray")))
{
size_t len = PyByteArray_Size(WriteMessage->m_Object);
char* data = PyByteArray_AsString(WriteMessage->m_Object);
retVal.reserve(len);
retVal.assign((const byte*)data, (const byte*)data + len);
}
// Handle String objects
else if ((((PyObject*)WriteMessage->m_Object)->ob_type->tp_flags & (Py_TPFLAGS_UNICODE_SUBCLASS)) != 0)
{
std::string sData = PyUnicode_AsUTF8(WriteMessage->m_Object);
retVal.reserve((size_t)sData.length());
retVal.assign((const byte*)sData.c_str(), (const byte*)sData.c_str() + sData.length());
}
else
_log.Log(LOG_ERROR, "(%s) Send request Python object parameter was not of type Unicode or Byte, ignored.", __func__);
return retVal;
}
I will try to upgade domoticz and see what appens.
Thanks
-
- Posts: 20
- Joined: Sunday 12 February 2017 13:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Python Plugin: Shelly MQTT
Hello
I want to thank you so very very much for this plugin!
I received my shelly2 yesterday, today I made a mock-up installation to test
I found your plugin, and it now all works, all the way to Domoticz's !
Good to know:
This line below was incorrect, mqtt server 1883 can be used, no problem
Now you can set it all up in Domoticz as you'll like
Finally,
- if like me you're using the Shelly2 behind a double switch (one switch per lamp), you will want to go into the individual button settings in Shelly's interface and change button type to "Edge Switch"
you may also want to update the "power on mode" - I need to check that one out myself.
I want to thank you so very very much for this plugin!
I received my shelly2 yesterday, today I made a mock-up installation to test
I found your plugin, and it now all works, all the way to Domoticz's !
Good to know:
This line below was incorrect, mqtt server 1883 can be used, no problem
- Spoiler: show
Now you can set it all up in Domoticz as you'll like
Finally,
- if like me you're using the Shelly2 behind a double switch (one switch per lamp), you will want to go into the individual button settings in Shelly's interface and change button type to "Edge Switch"
you may also want to update the "power on mode" - I need to check that one out myself.
Last edited by midomot on Monday 17 December 2018 14:32, edited 2 times in total.
-
- Posts: 216
- Joined: Saturday 10 November 2018 18:29
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Hungary
- Contact:
Re: Python Plugin: Shelly MQTT
You are welcome. Could you send the error messages, that you got? I am using the Shelly's on the same MQTT broker and port 1883 as my other Tasmota devices, and i did not saw any interesting yet.
Errors maybe pop up when it tries to create a new device, that just found, and automatic device creation is disabled?
-
- Posts: 20
- Joined: Sunday 12 February 2017 13:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Python Plugin: Shelly MQTT
I think I owe you an apology !
Not sure what happened, but it seems like I had set Port back to 1883 for this plugin - and it worked just fine for last couple days on my test-setup !
I now changed the port to 1884 (on shelly and in domoticz) and got
I probably confused myself and saw a problem where there was none
One thing I did notice: in hardware page, the port number is not visible on the Shelly_MQTT line
When that line is selected, the port is however properly visible in the lower part where settings can be adjusted
Domoticz V4.10276
Pi with Raspbian Jessie Lite
Python V3.4.2 installed
Not sure what happened, but it seems like I had set Port back to 1883 for this plugin - and it worked just fine for last couple days on my test-setup !
I now changed the port to 1884 (on shelly and in domoticz) and got
So better leave it with standard MQTT port 1883(Shelly_MQTT) Failed to connect to: 192.168.178.3:1884, Description: Connection refused
I probably confused myself and saw a problem where there was none
One thing I did notice: in hardware page, the port number is not visible on the Shelly_MQTT line
When that line is selected, the port is however properly visible in the lower part where settings can be adjusted
Domoticz V4.10276
Pi with Raspbian Jessie Lite
Python V3.4.2 installed
-
- Posts: 16
- Joined: Monday 06 November 2017 9:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Python Plugin: Shelly MQTT
hello,
great plugin- i tested with shelly 2 in roller mode.
it works perfect.
is it possible to use slider and percentage -blinds percentage-as in web config-shelly?
it is usefull for roller shutter to set position.
U
great plugin- i tested with shelly 2 in roller mode.
it works perfect.
is it possible to use slider and percentage -blinds percentage-as in web config-shelly?
it is usefull for roller shutter to set position.
U
-
- Posts: 16
- Joined: Monday 06 November 2017 9:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Python Plugin: Shelly MQTT
New in v1.4.0: roller mode position control. For this to work, the device must first be successfully calibrated, so that the time it takes for closing and opening are known.
shellies/shellyswitch-<deviceid>/roller/0/pos reports the current position in percent
shellies/shellyswitch-<deviceid>/roller/0/command/pos accepts a number between 0 and 100, which is target position in percent.
-
- Posts: 216
- Joined: Saturday 10 November 2018 18:29
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Hungary
- Contact:
Re: Python Plugin: Shelly MQTT
Someday, when i have a little spare time, it can be upgraded but it will be a little tricky to me to calibrate, as i do not have any blind device or motor to calibrate it.nabru99 wrote: ↑Saturday 29 December 2018 6:41 New in v1.4.0: roller mode position control. For this to work, the device must first be successfully calibrated, so that the time it takes for closing and opening are known.
shellies/shellyswitch-<deviceid>/roller/0/pos reports the current position in percent
shellies/shellyswitch-<deviceid>/roller/0/command/pos accepts a number between 0 and 100, which is target position in percent.
-
- Posts: 216
- Joined: Saturday 10 November 2018 18:29
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Hungary
- Contact:
Re: Python Plugin: Shelly MQTT
I am updated the plugin, but i am not sure, that it is working correctly, as i am unable to calibrate Shelly2 without a real device. Waiting for feedbacks.
-
- Posts: 16
- Joined: Monday 06 November 2017 9:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Python Plugin: Shelly MQTT
EDITED:
Domoticz finds new device- BLINDS PERCENTAGE this is OK
When percentage is used it shoud be:
nValue 0 and sValue 0 ==>> Closed
nValue 2 and sValue 2-99 ==>> partially opened
nValue 1 and sValue 100 ==>> Opened
Status with ShellyMQTT:
0% status is OPEN
100% status is OPEN
Slider is fully working - position is correct.
So only status is wrong.
U
-
- Posts: 216
- Joined: Saturday 10 November 2018 18:29
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Hungary
- Contact:
Re: Python Plugin: Shelly MQTT
Thank you, I see. I do not know, that nvalue is used at blind percentage.nabru99 wrote: ↑Tuesday 01 January 2019 7:48 When percentage is used it shoud be:
nValue 0 and sValue 0 ==>> Closed
nValue 2 and sValue 2-99 ==>> partially opened
nValue 1 and sValue 100 ==>> Opened
Status with ShellyMQTT:
0% status is OPEN
100% status is OPEN
Slider is fully working - position is correct.
So only status is wrong.
U
I think i fixed, please test it.
-
- Posts: 16
- Joined: Monday 06 November 2017 9:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Python Plugin: Shelly MQTT
closed is 100% Workinglwolf wrote: ↑Tuesday 01 January 2019 11:22Thank you, I see. I do not know, that nvalue is used at blind percentage.nabru99 wrote: ↑Tuesday 01 January 2019 7:48 When percentage is used it shoud be:
nValue 0 and sValue 0 ==>> Closed
nValue 2 and sValue 2-99 ==>> partially opened
nValue 1 and sValue 100 ==>> Opened
Status with ShellyMQTT:
0% status is OPEN
100% status is OPEN
Slider is fully working - position is correct.
So only status is wrong.
U
I think i fixed, please test it.
position 1-99% Working
open 0% Not working relay not triggered
i also teste reverse :
100 open
0 closed
also not working...
-
- Posts: 216
- Joined: Saturday 10 November 2018 18:29
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Hungary
- Contact:
Re: Python Plugin: Shelly MQTT
Please be a little more specific, what is not working.
When you issue "stop" command at the "VENETIAN Blind" device the plugin forwards "stop", if "off" then "open", if "on" then "close" message to the original topic:
shellies/shellyswitch-<deviceid>/roller/0/command
If you issue SET LEVEL command to the "Blind Percentage" device than the plugin forwards the percentage to the new topic:
shellies/shellyswitch-<deviceid>/roller/0/command/pos
There are two icon at the percentage bar at left, this is what not working? I guess you thinking about it.
And the plugin has to execute "stop" after reaching 0%? What needs to be triggered at 0%? I think 0 means closed, and Shelly doing the other things at the background.
Who is online
Users browsing this forum: No registered users and 1 guest