Python Plugin: Shelly MQTT

Python and python framework

Moderator: leecollings

CronoS
Posts: 135
Joined: Wednesday 15 July 2015 23:40
Target OS: -
Domoticz version:
Contact:

Re: Python Plugin: Shelly MQTT

Post by CronoS »

lwolf wrote: Friday 11 August 2023 17:46 [
Shelly Teacher waits for Gen2 devices "+/online" announcements, than it tries to figure out what is this device, and then sends the config template to the proper MQTT "homeassistant/" path. If you enable retain settings and make sure, that persistent storage is enabled and works on your MQTT broker, these settings will be saved... otherwise the config template needs to be sent again.
https://pagefault.blog/2020/02/05/how-t ... tt-broker/

RGB mode is not working, as Domoticz only has a partial implementation, i guess it only supports zigbee2mqtt and zwave MQTT messages, and has no template support at all.
https://github.com/enesbcs/shellyteacher4domo/issues/7

RGBW2 white only support added at commit https://github.com/enesbcs/shellyteache ... 947c2952a3 for testing.
Installed it; works great with my Shelly Plus device. I haven't tried the kwh plug yet; but I have 3 shellies in use primarely for measering kwh, so hopefully somebody can work allong with you to implement this in Domoticz MQTT.. A Shelly is easy to use and it is not expensive, so I think it is still important that it is supported by domoticz..

If I look at the Shelly.cloud website; Domoticz is the only iot platform that is not supported by Shelly anymore.. I think this because of the Gen2 devices. . With ShellyTeacher I think it is a big step in the right direction to get a support back from Shelly and maybe it is possible that with the 2024.1 the shellyteacher is standard part of the Domoticz ecosystem ;) That would be a great, haha :)
Xavier82
Posts: 178
Joined: Tuesday 07 June 2016 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Netherlands
Contact:

Re: Python Plugin: Shelly MQTT

Post by Xavier82 »

lwolf wrote: Friday 11 August 2023 17:50
Xavier82 wrote: Wednesday 09 August 2023 13:22 But when I go to the device tab I can only see the device "Roller 0" and "Roller Pos" but not devices are being created for the voltage, power, energy or temperature.
In the "mqtt_templates_gen2.txt" file I can see that these values are identified.
..
Xavier82 wrote: Wednesday 09 August 2023 13:22

Code: Select all

2023-08-09 11:56:28.974 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXXX/homeassistant Relay 0 (unique_id: shellyplus2pm-XXXX-0)
2023-08-09 11:56:29.075 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXXX/homeassistant Input 0 (unique_id: shellyplus2pm-XXXX-0-input)
2023-08-09 11:56:29.580 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXXX-1/homeassistant Relay 1 (unique_id: shellyplus2pm-XXXX-1)
2023-08-09 11:56:29.681 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXXX-1-input/homeassistant Input 1 (unique_id: shellyplus2pm-XXXX-1-input)
These are very funny lines... i hope you are not changed your shelly2pm MQTT base path to "homeassistant/", i have never seen a Relay before which is named as "homeassistant." :D
So I Updated today shellyteacher4domo.
In Domoticz my setup of hardware is "MQTT Auto Discovery Client Gateway with LAN interface".
Auto discovery prefix is "domoticz"

Based on the "how to use in Wiki:
"Edit settings.py file with a plain text editor, and set MQTT server IP address. If discovery prefix is leaved as default 'homeassistant' on the Domoticz MQTT AD hardware, than other settings will fine."

So in the settings.example.ini file yhe "discovery_prefix" is set to "domoticz" (same as in domoticz)

But now something strange...
In the settings.py file i read:

Code: Select all

data['discovery_prefix'] = 'homeassistant' # autodiscovery prefix for Domoticz
So what shoud I enter? leave it this way as "homeassistant" or change it to "domoticz"

On my shelly Plus 2pm I have the following setup for MQTT:
Enable MQTT network = checked
Connection type = No SSL
MQTT PREFIX = shellyplus2pm-XXXXXX
Enable "MQTT Control = checked
Enable RPC over MQTT = checked
RPC status notifications over MQTT = checked
Generic status update over MQTT = checked
server = IP-address of RPI with port 1883 where Mosquitto is installed
Client ID = shellyplus2pm-XXXXXX
Username = MQTT username
Password = MQTT password

With these settings Domoticz only created devices like input, relay and roller and position (last one not working)
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 »

Xavier82 wrote: Monday 14 August 2023 14:02 So I Updated today shellyteacher4domo.
In Domoticz my setup of hardware is "MQTT Auto Discovery Client Gateway with LAN interface".
Auto discovery prefix is "domoticz"

So in the settings.example.ini file yhe "discovery_prefix" is set to "domoticz" (same as in domoticz)
settings.example.ini is an example only... when you press "Save settings" button on the GUI it will save actual settings into settings.ini.
Xavier82 wrote: Monday 14 August 2023 14:02 But now something strange...
In the settings.py file i read:

Code: Select all

data['discovery_prefix'] = 'homeassistant' # autodiscovery prefix for Domoticz
So what shoud I enter? leave it this way as "homeassistant" or change it to "domoticz"

Yes, if you are not using standard discovery prefix, you should change the teacher settings.

But if you are using the new GUI version the settings.py is just for backward compatibility and .INI values will be used if .INI file exists.
This warning is already included in the settings.py file "If .ini file exists it will overwrite the default values below!"
If you are not using the GUI version, you can modify default settings.py with an editor and delete any .INI file.
Xavier82 wrote: Monday 14 August 2023 14:02 With these settings Domoticz only created devices like input, relay and roller and position (last one not working)
Yes as Domoticz MQTT AD has no real template support, 2pm needs a fix on the device itself. Fortunately Gen2 devices has scripting support.

As i mentioned on the Github, Domoticz will not actually create discovered MQTT devices, until the first value arrives from the MQTT path, which is advertised to the /config topic! You can debug it with MQTT Explorer.
Xavier82
Posts: 178
Joined: Tuesday 07 June 2016 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Netherlands
Contact:

Re: Python Plugin: Shelly MQTT

Post by Xavier82 »

lwolf wrote: Tuesday 15 August 2023 19:25
Xavier82 wrote: Monday 14 August 2023 14:02 So I Updated today shellyteacher4domo.
In Domoticz my setup of hardware is "MQTT Auto Discovery Client Gateway with LAN interface".
Auto discovery prefix is "domoticz"

So in the settings.example.ini file yhe "discovery_prefix" is set to "domoticz" (same as in domoticz)
settings.example.ini is an example only... when you press "Save settings" button on the GUI it will save actual settings into settings.ini.
Xavier82 wrote: Monday 14 August 2023 14:02 But now something strange...
In the settings.py file i read:

Code: Select all

data['discovery_prefix'] = 'homeassistant' # autodiscovery prefix for Domoticz
So what shoud I enter? leave it this way as "homeassistant" or change it to "domoticz"

Yes, if you are not using standard discovery prefix, you should change the teacher settings.

But if you are using the new GUI version the settings.py is just for backward compatibility and .INI values will be used if .INI file exists.
This warning is already included in the settings.py file "If .ini file exists it will overwrite the default values below!"
If you are not using the GUI version, you can modify default settings.py with an editor and delete any .INI file.
Xavier82 wrote: Monday 14 August 2023 14:02 With these settings Domoticz only created devices like input, relay and roller and position (last one not working)
Yes as Domoticz MQTT AD has no real template support, 2pm needs a fix on the device itself. Fortunately Gen2 devices has scripting support.

As i mentioned on the Github, Domoticz will not actually create discovered MQTT devices, until the first value arrives from the MQTT path, which is advertised to the /config topic! You can debug it with MQTT Explorer.
thanks for your reaction..

Ehmm ok, lets take this apart..
You are talking about GUI, which GUI, GUI of Shellyteacher4domo? How do I get there/this?
I use putty and/or winscp.
In the folder on my Rpi4b of shellyteacher4domo I have a file called "settings.py" and a file "settings_example.ini".
I renamed the file "settings_example.ini" to "old_settings_example.ini".

In the settings.py file I have entered the mqtt IP and port and the mqtt username and password, the discovery prefix is set to homeassitant.
testrun = False
retain = True
gen1 = True
gen2 = True
debug = False

Other lines have not been modified.

So from there what next to do to get things working?
As mentioned 6 devices are created:
Roller Pos
Roller 0
Input 1
Input 0
Relay 1
Relay 0

Non of these devices function, with other words clicking/activating them in Domoticz doesn't do anything the Shelly Plus2PM does not react.
The Shelly Plus2PM is setup as cover (blinds) device, not just as switch.

There are no devices created for energy/power/etc.
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 »

Xavier82 wrote: Wednesday 16 August 2023 20:04 You are talking about GUI, which GUI, GUI of Shellyteacher4domo? How do I get there/this?
Yes, there are a Linux and a Windows release in the release section on github (this information is included in the README):

https://github.com/enesbcs/shellyteacher4domo/tags

It can be run on any machine on the network, its not necesarry to run it on the server... (please update templates.txt manually in case you are downloading the binaries)
Xavier82 wrote: Wednesday 16 August 2023 20:04 I use putty and/or winscp.
GUI will not work through Putty. It needs working graphical desktop on Linux. But as i wrote, the teacher also able to run on a simple Windows PC. GUI is based on TKinter and automatically fallbacks to console mode, when there are no available graphical desktop available.
Xavier82 wrote: Wednesday 16 August 2023 20:04 So from there what next to do to get things working?
As mentioned 6 devices are created:
Roller Pos
Roller 0
Input 1
Input 0
Relay 1
Relay 0

Non of these devices function, with other words clicking/activating them in Domoticz doesn't do anything the Shelly Plus2PM does not react.
The Shelly Plus2PM is setup as cover (blinds) device, not just as switch.

There are no devices created for energy/power/etc.
https://github.com/enesbcs/shellyteache ... 1682742051
Xavier82
Posts: 178
Joined: Tuesday 07 June 2016 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Netherlands
Contact:

Re: Python Plugin: Shelly MQTT

Post by Xavier82 »

thanks for the info lwolf!
Xavier82
Posts: 178
Joined: Tuesday 07 June 2016 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Netherlands
Contact:

Re: Python Plugin: Shelly MQTT

Post by Xavier82 »

For all who are looking for a solution to get ShellyPlus2PM in cover mode to get to work:

With great thanks for support and creator of ShellyTeacher4Domo to enesbcs (Alexander Nagy)!

With this script code (works on ShellyPlus2PM firmware version 1.0.0) which needs to be added to ShellyPlus2PM script section you are able to control the ShellyPlus2PM in cover mode based in the slider (percentage).

Code: Select all

let CONFIG = {
  shelly_id: null,
};

Shelly.call("Shelly.GetDeviceInfo", {}, function (result) {
  if (result && result.id) {
    CONFIG.shelly_id = result.id;
    MQTT.subscribe(
      buildMQTTStateCmdTopics("rpc"),
      DecodeDomoticzFaultyJSON
    );
  } else {
    console.log("Failed to get Shelly device info:", result);
  }
});

function buildMQTTStateCmdTopics(topic) {
  let _t = topic || "";
  return CONFIG.shelly_id + "/" + _t;
}

/**
 * @param {string} topic
 * @param {string} message
 */
function DecodeDomoticzFaultyJSON(topic, message) {
  try {
    let trimmedMessage = message.trim();
    if (trimmedMessage) {
      let req = JSON.parse(trimmedMessage);
      for (let r in req) {
        if (r.indexOf("GoToPosition") !== -1) {  // Check if "GoToPosition" is present in the key
          SetCoverPosition(req[r]);
          break;
        }
      }
    }
  } catch (error) {
    console.log("Error parsing JSON:", error);
  }
}

function SetCoverPosition(position) {
  Shelly.call("Cover.GoToPosition", {
    id: 0,
    pos: position,
  });
}
To get it all to work I use Domoticz hardware "MQTT Auto Discovery Client Gateway with LAN interface".
I use ShellyTeacher4Domo for MQTT device announcements.
harrykausl
Posts: 177
Joined: Sunday 13 November 2016 10:43
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Germany
Contact:

Re: Python Plugin: Shelly MQTT

Post by harrykausl »

I use the shelly mqtt plugin for several shelly 1 switches, workes fine. Now i bought a Shelly Plug S and don't get the devices created in domoticz. The mqtt settings in the device look different to the settings of the Shelly Switches. I deactivated cloud, activated mqtt with the server settings, but it doesn't work. Can anyone post the mqtt settings of a working shelly plug s, thanks!
CronoS
Posts: 135
Joined: Wednesday 15 July 2015 23:40
Target OS: -
Domoticz version:
Contact:

Re: Python Plugin: Shelly MQTT

Post by CronoS »

harrykausl wrote: Friday 25 August 2023 11:33 I use the shelly mqtt plugin for several shelly 1 switches, workes fine. Now i bought a Shelly Plug S and don't get the devices created in domoticz. The mqtt settings in the device look different to the settings of the Shelly Switches. I deactivated cloud, activated mqtt with the server settings, but it doesn't work. Can anyone post the mqtt settings of a working shelly plug s, thanks!
Is it the Shelly Plus Plug S or the Shelly Plug S. The first one is a Gen2 device, the second one should work K with the old plugin .
harrykausl
Posts: 177
Joined: Sunday 13 November 2016 10:43
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Germany
Contact:

Re: Python Plugin: Shelly MQTT

Post by harrykausl »

It is a plus plug s, so it wońt work. I have to switch to shellyteacher4 demo and mqtt autodiscover. Thanks,
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: Python Plugin: Shelly MQTT

Post by ssk17051980 »

Hello,

need big big help

i use Shelly MQTT plugin to monitor shelly 3 EM.

so far I think everything is ok. He created a few idxs for me and I understood some of them. I wrote on each IDX what I think it represents. I don't know how to make an IDX that shows my daily consumption and a monthly IDX, in a time interval. Can someone get me out of the fog?
Attachments
shelly 3 EM.jpg
shelly 3 EM.jpg (140.44 KiB) Viewed 2892 times
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 »

ssk17051980 wrote: Tuesday 29 August 2023 20:23 Hello,

need big big help

i use Shelly MQTT plugin to monitor shelly 3 EM.

so far I think everything is ok. He created a few idxs for me and I understood some of them. I wrote on each IDX what I think it represents. I don't know how to make an IDX that shows my daily consumption and a monthly IDX, in a time interval. Can someone get me out of the fog?
As this has nothing to do with the plugin you better start a new topic for this question or find an existing one like this : viewtopic.php?p=206152#p206152
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: Python Plugin: Shelly MQTT

Post by ssk17051980 »

I don't know the meaning of all the idx.
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 »

ssk17051980 wrote: Tuesday 29 August 2023 21:43 I don't know the meaning of all the idx.
If you read Shelly Docs you will have some clue what total, total energy and total returned mean:
https://shelly-api-docs.shelly.cloud/ge ... y-3em-mqtt
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 »

ssk17051980 wrote: Tuesday 29 August 2023 21:43 I don't know the meaning of all the idx.
Better ask that question in the other topic for scripting....
But IDX is the ID of the domoticz device. First column in menu Setup - Devices
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: Python Plugin: Shelly MQTT

Post by ssk17051980 »

waltervl wrote: Wednesday 30 August 2023 13:21
ssk17051980 wrote: Tuesday 29 August 2023 21:43 I don't know the meaning of all the idx.
Better ask that question in the other topic for scripting....
But IDX is the ID of the domoticz device. First column in menu Setup - Devices
i know what is the idx.
the problem is that i do not know my monthly consumption or at a certain time of the month
yara009
Posts: 6
Joined: Sunday 17 January 2021 19:08
Target OS: Linux
Domoticz version:
Contact:

Re: Python Plugin: Shelly MQTT

Post by yara009 »

Problem solved!

Since v1.4.3: on MQTT connect, Shellies will publish:
... ... If these are not set after a firmware upgrade -- perform a factory reset of the device. The LWT topic is retained on user configuration (if the Retain flag is set). However, we do not recommend using retained MQTT messages.


-----------


I have problem with ShellyTeacher 4 Domoticz and Shelly Pro4PM.
In my opinion, the problem is not firewall or OS related (i tried Linux and Windows versions).
Thank you for helping me.
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 »

jacobsentertainment wrote: Sunday 26 March 2023 16:26 Hi all,

Is there some support in this plugin for an shelly trv? Or is this still work in progress?
Domoticz 2023 beta 15515 and newer versions has the capability to process TRV incoming data, if you use the latest ShellyTeacher4Domo 2023.09.01
User avatar
jacobsentertainment
Posts: 211
Joined: Thursday 01 October 2020 1:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021-1
Location: Not @ home
Contact:

Re: Python Plugin: Shelly MQTT

Post by jacobsentertainment »

Thanks for the reply.

I tried to install it, I get the gui on my pi screen and it finds the trv and some other items, but that's it! that where it all comes to a hold, I tried to accept new devices in domoticz settings etc but nothing appears in the device list.

I'm a noob when it comes to all these code lines and finding the issue, but finding an easy to understand step by step plan is hard in the domoticz world. (or it's me :oops: )

So I switched back to the old shelly mqtt and use the trv's trough http commands.


How can i see if my domoticz version is the beta or the stable?
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 »

jacobsentertainment wrote: Tuesday 19 September 2023 17:41 How can i see if my domoticz version is the beta or the stable?
In menu Setup - About, compile date 2023-07-21
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest