Is it possible to add Shelly 2PM GEN 3 to Domoticz?

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

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

Re: Is it possible to add Shelly 2PM GEN 3 to Domoticz?

Post by FireWizard »

Hello @Daro1003,
I don't know how to do it ;/ Can you upload a screenshot?
1. Open the "Change" node, called "Set Domoticz IDX", by double clicking.
Screenshot_Change_Annotated.png
Screenshot_Change_Annotated.png (38.66 KiB) Viewed 173 times
2. Click the +add button and another field will be added.
Screenshot_Change_Annotated2.png
Screenshot_Change_Annotated2.png (34.45 KiB) Viewed 173 times
3. Add the Domoticz IDX and the Shelly ClientID in the same way as the first item in the node.

Screenshot_Change_Annotated3.png
Screenshot_Change_Annotated3.png (35.03 KiB) Viewed 173 times
4, Deploy
5. Activate the "Inject" node.
I recommend to view some videos of Node-RED: https://www.youtube.com/watch?v=jMaHKQLXYhI

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

Re: Is it possible to add Shelly 2PM GEN 3 to Domoticz?

Post by FireWizard »

Hello @Daro1003,

You have probably thought, that I had forgotten you. This is not the case, but I have been considering how to make the implementation of a Temperature sensor as easy as possible.

You asked:
2. Temperature

YES
To make the configuration as simple as before, I had to swap the key and value.
Previously the key was the characters IDX followed by de Domoticz idx number, e.g. IDX1060.
The value was the Shelly ClientID

I swapped those 2, as shown in the next picture

Screenshot_Shelly 2PMG3-alt.png
Screenshot_Shelly 2PMG3-alt.png (46.94 KiB) Viewed 111 times
1. The Shelly Client ID has to be inserted after flow
2. The Domoticz idx for the Switch has to be inserted in an Object after "sidx". Example 12
3. The Domoticz idx of the Temperature sensor has to be inserted in the same Object after "tidx". Example 13

The contents of the "Function" nodes has also changed.

Do the following:

Create a (new) virtual sensor for the Temperature of the Shelly device. Insert the idx number after "tidx":

Do not forget to configure your own MQTT parameters.

A complete flow you will find below.
I suggest you copy this one in a separate tab and disable the old tab.

Code: Select all

[
    {
        "id": "327568dd155084e3",
        "type": "comment",
        "z": "cfcf4d6d274167af",
        "name": "Configuration",
        "info": "Insert the Shelly ClientID of the\nShelly device (e.g. shelly2pmg3-34cdb0774d4c) in the field\nflow.\n\nInsert the IDX of the Domoticz Switch in the JSON object\nfile in the field \"to the value\" after \"sidx\" and insert the IDX of\nthe Domoticz Temperature sensor after \"tidx\".\n\nExample, if the IDX of the Domoticz Switch is 12 and\nthe IDX of the Temperature sensor is 13:\n\n{\"sidx\": 12, \"tidx\": 13}",
        "x": 490,
        "y": 80,
        "wires": []
    },
    {
        "id": "13f99299d7be6bd2",
        "type": "inject",
        "z": "cfcf4d6d274167af",
        "name": "Inject Domoticz IDX",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "x": 260,
        "y": 140,
        "wires": [
            [
                "50d48d9364c4f0f8"
            ]
        ]
    },
    {
        "id": "50d48d9364c4f0f8",
        "type": "change",
        "z": "cfcf4d6d274167af",
        "name": "Set Domoticz IDX ",
        "rules": [
            {
                "t": "set",
                "p": "shelly2pmg3-34cdb0774d4c",
                "pt": "flow",
                "to": "{\"sidx\": 12, \"tidx\": 13}",
                "tot": "json"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 510,
        "y": 140,
        "wires": [
            []
        ]
    },
    {
        "id": "2a56e8a2ce739840",
        "type": "function",
        "z": "cfcf4d6d274167af",
        "name": "Control Domoticz Switch",
        "func": "let msg1 = {};\nlet msg2 = {};\n\nlet sidx = (flow.get(msg.topic.split(\"/\")[0])).sidx;\nlet tidx = (flow.get(msg.topic.split(\"/\")[0])).tidx;\n\n//Open (for Reversed Position)\nif (msg.payload.current_pos === 100) {\n    msg1.payload = { \"command\": \"udevice\", \"idx\": sidx, \"nvalue\": 1, \"svalue\": \"100\" }\n}\n\n//Closed (for Reversed Position)\nif (msg.payload.current_pos === 0) {\n    msg1.payload = { \"command\": \"udevice\", \"idx\": sidx, \"nvalue\": 0, \"svalue\": \"0\" }\n}\n\n//Percentage (for Reversed Position)\nif ((msg.payload.current_pos > 0) && (msg.payload.current_pos < 100)) {\n    msg1.payload = { \"command\": \"udevice\", \"idx\": sidx, \"nvalue\": 2, \"svalue\": msg.payload.current_pos.toString() }\n}\n\n//Temperature\nmsg2.payload = { \"command\": \"udevice\", \"idx\": tidx, \"nvalue\": 0, \"svalue\": msg.payload.temperature.tC.toString() }\n\nreturn [[msg1,msg2]];",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 530,
        "y": 480,
        "wires": [
            [
                "7ae122c721d614e4",
                "f6cf694ec8750a8b"
            ]
        ]
    },
    {
        "id": "7ae122c721d614e4",
        "type": "debug",
        "z": "cfcf4d6d274167af",
        "name": "debug 32",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 780,
        "y": 540,
        "wires": []
    },
    {
        "id": "63781efaa0e431d8",
        "type": "debug",
        "z": "cfcf4d6d274167af",
        "name": "debug 33",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 480,
        "y": 540,
        "wires": []
    },
    {
        "id": "f6cf694ec8750a8b",
        "type": "mqtt out",
        "z": "cfcf4d6d274167af",
        "name": "Domoticz In",
        "topic": "domoticz/in",
        "qos": "1",
        "retain": "false",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "38b35487299a036d",
        "x": 790,
        "y": 480,
        "wires": []
    },
    {
        "id": "80e1fbc254e2e697",
        "type": "mqtt in",
        "z": "cfcf4d6d274167af",
        "name": "Shelly Cover Status Out",
        "topic": "shelly2pmg3-34cdb0774d4c/status/cover:0",
        "qos": "1",
        "datatype": "auto-detect",
        "broker": "38b35487299a036d",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 260,
        "y": 480,
        "wires": [
            [
                "63781efaa0e431d8",
                "2a56e8a2ce739840"
            ]
        ]
    },
    {
        "id": "e6cb20d21c6d557c",
        "type": "comment",
        "z": "cfcf4d6d274167af",
        "name": "Shelly  ====> Domotcz Switch",
        "info": "",
        "x": 540,
        "y": 420,
        "wires": []
    },
    {
        "id": "725dfa2416f8df60",
        "type": "mqtt in",
        "z": "cfcf4d6d274167af",
        "name": "Domoticz Out",
        "topic": "domoticz/out",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "38b35487299a036d",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 290,
        "y": 300,
        "wires": [
            [
                "c216d4d18f94b29d"
            ]
        ]
    },
    {
        "id": "c216d4d18f94b29d",
        "type": "switch",
        "z": "cfcf4d6d274167af",
        "name": "Filter Domoticz switchType",
        "property": "payload.switchType",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "Blinds Percentage",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 540,
        "y": 300,
        "wires": [
            [
                "3e74c0a6e0804e4f",
                "315dae8f498b9c4d"
            ]
        ]
    },
    {
        "id": "3e74c0a6e0804e4f",
        "type": "function",
        "z": "cfcf4d6d274167af",
        "name": "Blinds + Percentage ",
        "func": "// Function Blinds and Percentage\n\nfor (let i = 0; i < flow.keys().length; i++) {\n\n        if (msg.payload.idx === (flow.get(flow.keys())[i]).sidx) {\n\nmsg.topic = flow.keys()[i] + \"/command/cover:0\";\n\n//Closed\nif (msg.payload.nvalue === 0) { msg.payload = \"close\" };\n\n//Open\nif (msg.payload.nvalue === 1) { msg.payload = \"open\" };\n\n//Percentage\nif (msg.payload.nvalue === 2) { msg.payload = \"pos,\" + msg.payload.Level.toString() };\n\n}\n\nreturn msg;\n}",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 820,
        "y": 300,
        "wires": [
            [
                "06e073c160456137",
                "3dde24433748f2c3"
            ]
        ]
    },
    {
        "id": "06e073c160456137",
        "type": "debug",
        "z": "cfcf4d6d274167af",
        "name": "debug 54",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1040,
        "y": 360,
        "wires": []
    },
    {
        "id": "3dde24433748f2c3",
        "type": "mqtt out",
        "z": "cfcf4d6d274167af",
        "name": "Shelly Cover Command Out",
        "topic": "",
        "qos": "1",
        "retain": "false",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "38b35487299a036d",
        "x": 1100,
        "y": 300,
        "wires": []
    },
    {
        "id": "315dae8f498b9c4d",
        "type": "debug",
        "z": "cfcf4d6d274167af",
        "name": "debug 55",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 780,
        "y": 360,
        "wires": []
    },
    {
        "id": "b1d50d4a3b22e08f",
        "type": "comment",
        "z": "cfcf4d6d274167af",
        "name": " Domotcz Switch ====> Shelly",
        "info": "",
        "x": 540,
        "y": 240,
        "wires": []
    },
    {
        "id": "38b35487299a036d",
        "type": "mqtt-broker",
        "name": "Raspberry Pi 1",
        "broker": "192.168.10.51",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]
Test it and let me know.

Regards
Last edited by FireWizard on Sunday 01 June 2025 11:23, edited 1 time in total.
Daro1003
Posts: 168
Joined: Monday 14 November 2022 12:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Poland
Contact:

Re: Is it possible to add Shelly 2PM GEN 3 to Domoticz?

Post by Daro1003 »

Everything is working properly.

The temperature of the shell GEN 3 is 45 degrees.
The temperature of the shell 2.5 is 60 degrees.

As you can see, something is probably fixed in GEN 3

Thank you for your great help.
User avatar
FireWizard
Posts: 1871
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Is it possible to add Shelly 2PM GEN 3 to Domoticz?

Post by FireWizard »

Hi @Daro1003,
Everything is working properly.
Then I suggest to close this thread,
If there is something else in the future, open a new thread and do not hesitate to ask.

You can easily expand your system with other Shelly 2PM Gen 3 devices, as follows:

1. Create a new virtual switch and a new virtual Temperature sensor. and note down their Domoticz indexes
2. in the Change node in Node Red, add another key/value pair.
3. Insert the ClientID of the Shelly 2PM Gen 3 after the flow
4. Insert the index of the Domoticz Switch and the index of the Domoticz Temperature sensor after the value as an object
as follows: {"sidx": 1234, "tidx": 5678}
5. Leave all other nodes unchanged.

Then it should work immediately

Regards
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest