Shelly Gen2 MQTT Help

With Shelly's you can disconnect the switch from the relay, so switching the switch does not need to toggle the relay., you can change state of relay separately.

Yes, but of course the danger with relying upon the switch state, is that it could easily become out of sync with the actual light state, if for example the OP used the shelly app or voice activation to change the light state.

If he changes the state of the relay then power to the light, which i think is a lifx will be turned of, so the lifx lamp will not work any way.

I would probably not use the relay and have the lifx fully powered. ( having it connected to relay does mean he can disable the lifx any time he wishes though).

I think the OP is using the switch to control the lifx lamp

Yes, I use the relay as effectively a master power.

My normal use is to use the switch which using node red to command the bulb to turn on/off (not powered on/off). I also use voice commands or other automation to turn on the bulb.

Yes, it can get out of sync with the switch but this is fine for my use

Is there an easy way if achieving this? Clearly my function node doesn't work

Check my example in post 14

Works perfectly, many thanks

Hi, I have another linked question now, sorry.
I want to control the relay state from node red. I can do this easily enough with the gen1 devices, but I have tried something similar to the above for the gen2 but it has not worked

any help really appreciated

cheers

[{"id":"07fd7e470e77672f","type":"tab","label":"Evening Scene","disabled":false,"info":"","env":[]},{"id":"0be5abfbd5f32acf","type":"ha-entity","z":"07fd7e470e77672f","name":"Evening_Scene","server":"1b6d2de3.6c8fc2","version":2,"debugenabled":false,"outputs":2,"entityType":"switch","config":[{"property":"name","value":"Evening Scene"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:weather-night"},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":160,"y":80,"wires":[[],[]]},{"id":"dfd6bffc968aab6d","type":"hue-group","z":"07fd7e470e77672f","name":"Kitchen","bridge":"5337ec1e7bfba1c4","groupid":"1","colornamer":true,"skipevents":false,"universalevents":false,"x":1200,"y":380,"wires":[[]]},{"id":"937a56ffb984ef44","type":"server-state-changed","z":"07fd7e470e77672f","name":"Evening Scene Selected","server":"1b6d2de3.6c8fc2","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.evening_scene","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"{\"on\":true}","valueType":"str"}],"x":490,"y":360,"wires":[["f3539dcf2f5ac756","abba1d8c7f7f4801","996ff6117c295bdc"],[]]},{"id":"a30b9755ae810cb0","type":"debug","z":"07fd7e470e77672f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1070,"y":760,"wires":[]},{"id":"207446196b766ecc","type":"mqtt out","z":"07fd7e470e77672f","name":"","topic":"shellies/shelly1-Studio/relay/0/command","qos":"2","retain":"false","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"2fd5bebaac766e96","x":1300,"y":320,"wires":[]},{"id":"f3539dcf2f5ac756","type":"change","z":"07fd7e470e77672f","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1000,"y":320,"wires":[["207446196b766ecc"]]},{"id":"abba1d8c7f7f4801","type":"change","z":"07fd7e470e77672f","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":380,"wires":[["41fa36b44e8daf35"]]},{"id":"41fa36b44e8daf35","type":"function","z":"07fd7e470e77672f","name":"","func":"if(msg.payload==\"on\")\n{\n    msg.payload={\"on\":true}\n}\n\nif(msg.payload==false)\n{\n    msg.payload={\"on\":false}\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1040,"y":380,"wires":[["dfd6bffc968aab6d"]]},{"id":"b2013fc11b2a5fbc","type":"mqtt out","z":"07fd7e470e77672f","name":"","topic":"Kitchen_Main params","qos":"2","retain":"false","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"2fd5bebaac766e96","x":1100,"y":520,"wires":[]},{"id":"996ff6117c295bdc","type":"change","z":"07fd7e470e77672f","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":":{\"id\":0,\"on\":false}}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":520,"wires":[["b2013fc11b2a5fbc","a30b9755ae810cb0"]]},{"id":"1b6d2de3.6c8fc2","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30},{"id":"5337ec1e7bfba1c4","type":"hue-bridge","name":"Philips hue","bridge":"192.168.86.250","key":"S1hfxJ2iHRObyTwfh2s7jUBRTbH5CaI2a5rsxXgb","interval":"3000","disableupdates":false},{"id":"2fd5bebaac766e96","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

The shelly gen2 uses rpc channel to switch the device, so the topic is totally different.

There is an example here which should be similar

and the shelly docs here

I have had a good look at that and it looks like what I need. I have tried to copy it and i get nothing.

[{"id":"f6ee0c7b.18c73","type":"inject","z":"07fd7e470e77672f","name":"on","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Kitchen_Main/rpc","payload":"{\"id\":123, \"src\":\"user_1\", \"method\":\"Switch.Set\", \"params\":{\"id\":0,\"on\":true}}","payloadType":"json","x":850,"y":600,"wires":[["b2013fc11b2a5fbc","a30b9755ae810cb0"]]}]

using mqtt explorer I can see the device (Kitchen_Main)

image

Try shellyplus1-a************/rpc as the topic. or a combination shellyplus1-a******/kitchen_Main/rpc

I have changed to this and still no joy

image

1 Like

How is the mqtt out node configured?

[{"id":"b2013fc11b2a5fbc","type":"mqtt out","z":"07fd7e470e77672f","name":"","topic":"Kitchen_Main params","qos":"2","retain":"false","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"2fd5bebaac766e96","x":1100,"y":520,"wires":[]},{"id":"2fd5bebaac766e96","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

Well there is an issue, why have you set the topic in the mqtt out? If you have set it in the msg topic.

P.S. I think you should mark this topic resolved and any future issues start a new topic as it will be hard for future users to find answers if you keep adding questions.

1 Like

ahh, i see now, sorry for that. I will mark as closed. Many thanks for help, all working now

try;

[
    {
        "id": "f3531e533928b6a7",
        "type": "mqtt in",
        "z": "68c5e3c3eff4dfe1",
        "name": "",
        "topic": "shellypro4pm-84cca87fb628/events/#",
        "qos": "2",
        "datatype": "auto",
        "broker": "d675b749.04b9c8",
        "nl": false,
        "rap": false,
        "rh": 0,
        "inputs": 0,
        "x": 350,
        "y": 100,
        "wires": [
            [
                "92f56d1533c4d138"
            ]
        ]
    },
    {
        "id": "92f56d1533c4d138",
        "type": "json",
        "z": "68c5e3c3eff4dfe1",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 870,
        "y": 100,
        "wires": [
            [
                "7ea807548bcdf27f",
                "4d664089e0e061d5",
                "ba76ac59e7c3ad26",
                "aaae150abf316ac3",
                "a74967b5f5449f35",
                "5d32e4102cd5386f",
                "ac1ea4a67cf6e630",
                "5e50c7807c879dcd",
                "65aec9dfa16b867b",
                "9571b76e12c7c709",
                "d90e03a5361de2d0",
                "fa90b4c4dbdc47b9",
                "c4a99c47459d8996",
                "eecb35d397df66fe",
                "04c62609515fe6bd",
                "1a321ef4781e080f"
            ]
        ]
    },
    {
        "id": "168561d3fc4fcd8d",
        "type": "link out",
        "z": "68c5e3c3eff4dfe1",
        "name": "out 0",
        "mode": "link",
        "links": [
            "02227c5d2a48142b",
            "226bd881a7a66b68"
        ],
        "x": 2070,
        "y": 100,
        "wires": [],
        "l": true
    },
    {
        "id": "8c9385582e2442aa",
        "type": "debug",
        "z": "68c5e3c3eff4dfe1",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1840,
        "y": 100,
        "wires": []
    },
    {
        "id": "fa90b4c4dbdc47b9",
        "type": "change",
        "z": "68c5e3c3eff4dfe1",
        "name": "0 out",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.params[\"switch:0\"].output",
                "tot": "msg",
                "dc": true
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1030,
        "y": 100,
        "wires": [
            [
                "c0a528dc183c8cac"
            ]
        ]
    },
    {
        "id": "c0a528dc183c8cac",
        "type": "switch",
        "z": "68c5e3c3eff4dfe1",
        "name": "Relais",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "true"
            },
            {
                "t": "false"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 1230,
        "y": 100,
        "wires": [
            [
                "b0cf35d2c8b55fc3"
            ],
            [
                "b0cf35d2c8b55fc3"
            ]
        ]
    },
    {
        "id": "b0cf35d2c8b55fc3",
        "type": "rbe",
        "z": "68c5e3c3eff4dfe1",
        "name": "",
        "func": "rbe",
        "gap": "",
        "start": "",
        "inout": "out",
        "septopics": true,
        "property": "payload",
        "topi": "topic",
        "x": 1430,
        "y": 100,
        "wires": [
            [
                "a7fa1b2b693a2940"
            ]
        ]
    },
    {
        "id": "c4a99c47459d8996",
        "type": "change",
        "z": "68c5e3c3eff4dfe1",
        "name": "0 volt",
        "rules": [
            {
                "t": "set",
                "p": "device",
                "pt": "msg",
                "to": "payload.params[\"switch:0\"].voltage",
                "tot": "msg",
                "dc": true
            },
            {
                "t": "delete",
                "p": "payload",
                "pt": "msg"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "device",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1030,
        "y": 160,
        "wires": [
            [
                "3813ba8cfe9e4ee0"
            ]
        ]
    },
    {
        "id": "4c537048ee90a982",
        "type": "debug",
        "z": "68c5e3c3eff4dfe1",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1840,
        "y": 160,
        "wires": []
    },
    {
        "id": "3813ba8cfe9e4ee0",
        "type": "switch",
        "z": "68c5e3c3eff4dfe1",
        "name": "voltage",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "btwn",
                "v": "0",
                "vt": "num",
                "v2": "1000",
                "v2t": "num"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 1240,
        "y": 160,
        "wires": [
            [
                "c453f8d4fe1ff9aa"
            ],
            []
        ]
    },
    {
        "id": "3220a64104b4ab68",
        "type": "debug",
        "z": "68c5e3c3eff4dfe1",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1840,
        "y": 220,
        "wires": []
    },
    {
        "id": "1b7392cab60c17bf",
        "type": "switch",
        "z": "68c5e3c3eff4dfe1",
        "name": "energie",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "btwn",
                "v": "0",
                "vt": "num",
                "v2": "3600",
                "v2t": "num"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 1240,
        "y": 220,
        "wires": [
            [
                "3220a64104b4ab68",
                "32b33a13e1918cee"
            ],
            []
        ]
    },
    {
        "id": "eecb35d397df66fe",
        "type": "change",
        "z": "68c5e3c3eff4dfe1",
        "name": "0 KVA",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.params[\"switch:1\"].output",
                "tot": "msg",
                "dc": true
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1030,
        "y": 220,
        "wires": [
            [
                "1b7392cab60c17bf"
            ]
        ]
    },
    {
        "id": "a7fa1b2b693a2940",
        "type": "change",
        "z": "68c5e3c3eff4dfe1",
        "name": "on/off",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "true",
                "fromt": "bool",
                "to": "on",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "false",
                "fromt": "bool",
                "to": "off",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1590,
        "y": 100,
        "wires": [
            [
                "8c9385582e2442aa",
                "168561d3fc4fcd8d"
            ]
        ]
    },
    {
        "id": "04c62609515fe6bd",
        "type": "change",
        "z": "68c5e3c3eff4dfe1",
        "name": "0 Input",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.params[\"input:0\"].state",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1030,
        "y": 280,
        "wires": [
            [
                "c75a45fe5d894fa5"
            ]
        ]
    },
    {
        "id": "6d205992a168df16",
        "type": "debug",
        "z": "68c5e3c3eff4dfe1",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1840,
        "y": 280,
        "wires": []
    },
    {
        "id": "c75a45fe5d894fa5",
        "type": "switch",
        "z": "68c5e3c3eff4dfe1",
        "name": "Input",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "true"
            },
            {
                "t": "false"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 1230,
        "y": 280,
        "wires": [
            [
                "2803baba78cdbbfe"
            ],
            [
                "2803baba78cdbbfe"
            ]
        ]
    },
    {
        "id": "2803baba78cdbbfe",
        "type": "rbe",
        "z": "68c5e3c3eff4dfe1",
        "name": "",
        "func": "rbe",
        "gap": "",
        "start": "",
        "inout": "out",
        "septopics": true,
        "property": "payload",
        "topi": "topic",
        "x": 1430,
        "y": 280,
        "wires": [
            [
                "fe2ecd3f54c83504"
            ]
        ]
    },
    {
        "id": "fe2ecd3f54c83504",
        "type": "change",
        "z": "68c5e3c3eff4dfe1",
        "name": "on/off",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "true",
                "fromt": "bool",
                "to": "on",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "false",
                "fromt": "bool",
                "to": "off",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1590,
        "y": 280,
        "wires": [
            [
                "6d205992a168df16",
                "bfef252b429cdd86"
            ]
        ]
    },
    {
        "id": "c453f8d4fe1ff9aa",
        "type": "rbe",
        "z": "68c5e3c3eff4dfe1",
        "name": "",
        "func": "rbe",
        "gap": "",
        "start": "",
        "inout": "out",
        "septopics": true,
        "property": "payload",
        "topi": "topic",
        "x": 1430,
        "y": 160,
        "wires": [
            [
                "4c537048ee90a982",
                "03955e6676e1dd85"
            ]
        ]
    },
    {
        "id": "03955e6676e1dd85",
        "type": "link out",
        "z": "68c5e3c3eff4dfe1",
        "name": "volt 0",
        "mode": "link",
        "links": [
            "2f56dc712f70b770"
        ],
        "x": 2070,
        "y": 160,
        "wires": [],
        "l": true
    },
    {
        "id": "32b33a13e1918cee",
        "type": "link out",
        "z": "68c5e3c3eff4dfe1",
        "name": "watt 0",
        "mode": "link",
        "links": [
            "4a322f1075347fc8"
        ],
        "x": 2070,
        "y": 220,
        "wires": [],
        "l": true
    },
    {
        "id": "bfef252b429cdd86",
        "type": "link out",
        "z": "68c5e3c3eff4dfe1",
        "name": "input 0",
        "mode": "link",
        "links": [
            "aab074ab7ee11fb3"
        ],
        "x": 2070,
        "y": 280,
        "wires": [],
        "l": true
    },
    {
        "id": "d675b749.04b9c8",
        "type": "mqtt-broker",
        "name": "Localhost",
        "broker": "localhost",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "3",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    }
]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.