Influence the path in the flow. on/off/auto

Hello,

I have this flow. It switches a socket on and off based on the power consumption.
I would now like to implement a possibility with the help of which I can operate this socket permanently off, permanently on or in automatic mode (as at the moment) via an mqtt message.
For example, if I send the message “auto”, then the flow should run as before, with “off” the socket should definitely remain off and with “on” it should be switched on accordingly.
How can I do this? I'm not very good at programming. Maybe someone can show me an example or - if necessary - a script.

Thank you very much

Flow:

[
    {
        "id": "7b3908c5.c15588",
        "type": "tab",
        "label": "Huawei on/off",
        "disabled": false,
        "info": ""
    },
    {
        "id": "80866fdc06e127fe",
        "type": "mqtt in",
        "z": "7b3908c5.c15588",
        "name": "electricity meter",
        "topic": "evcc/site/gridPower",
        "qos": "0",
        "datatype": "json",
        "broker": "f839540e.7b7858",
        "nl": false,
        "rap": false,
        "inputs": 0,
        "x": 200,
        "y": 280,
        "wires": [
            [
                "0f1e33ad983e4cb2"
            ]
        ]
    },
    {
        "id": "f57d7408525a979f",
        "type": "mqtt out",
        "z": "7b3908c5.c15588",
        "name": "on",
        "topic": "cmnd/tas02/Power",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "f839540e.7b7858",
        "x": 1190,
        "y": 180,
        "wires": []
    },
    {
        "id": "c66c54b6929cb23f",
        "type": "debug",
        "z": "7b3908c5.c15588",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1210,
        "y": 300,
        "wires": []
    },
    {
        "id": "0f1e33ad983e4cb2",
        "type": "rbe",
        "z": "7b3908c5.c15588",
        "name": "define value change",
        "func": "deadband",
        "gap": "300",
        "start": "",
        "inout": "out",
        "septopics": false,
        "property": "payload",
        "topi": "topic",
        "x": 440,
        "y": 280,
        "wires": [
            [
                "ad86aeb9a9907ae6",
                "e75866d60570482a"
            ]
        ]
    },
    {
        "id": "ad86aeb9a9907ae6",
        "type": "switch",
        "z": "7b3908c5.c15588",
        "name": "payload <= -800",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "lte",
                "v": "-800",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 660,
        "y": 240,
        "wires": [
            [
                "c66c54b6929cb23f",
                "a184949a27cd7bc5"
            ]
        ]
    },
    {
        "id": "e75866d60570482a",
        "type": "switch",
        "z": "7b3908c5.c15588",
        "name": "payload >= 300",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "gte",
                "v": "300",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 660,
        "y": 340,
        "wires": [
            [
                "c66c54b6929cb23f",
                "8e193c8e87b44819"
            ]
        ]
    },
    {
        "id": "ce5f38eb6f387c05",
        "type": "mqtt out",
        "z": "7b3908c5.c15588",
        "name": "off",
        "topic": "cmnd/tas02/Power",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "f839540e.7b7858",
        "x": 1190,
        "y": 400,
        "wires": []
    },
    {
        "id": "a184949a27cd7bc5",
        "type": "change",
        "z": "7b3908c5.c15588",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "on",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 950,
        "y": 240,
        "wires": [
            [
                "f57d7408525a979f",
                "c66c54b6929cb23f"
            ]
        ]
    },
    {
        "id": "8e193c8e87b44819",
        "type": "change",
        "z": "7b3908c5.c15588",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "off",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 950,
        "y": 340,
        "wires": [
            [
                "ce5f38eb6f387c05",
                "c66c54b6929cb23f"
            ]
        ]
    },
    {
        "id": "a201873577991e29",
        "type": "mqtt in",
        "z": "7b3908c5.c15588",
        "name": "Mode",
        "topic": "akku/mode",
        "qos": "0",
        "datatype": "utf8",
        "broker": "f839540e.7b7858",
        "nl": false,
        "rap": false,
        "inputs": 0,
        "x": 190,
        "y": 360,
        "wires": [
            []
        ]
    },
    {
        "id": "f839540e.7b7858",
        "type": "mqtt-broker",
        "name": "",
        "broker": "192.168.178.44",
        "port": "1883",
        "clientid": "clientid",
        "autoConnect": true,
        "usetls": false,
        "compatmode": false,
        "protocolVersion": 4,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    }
]

You could add a MQTT-in with a topic 'system/status'. The payload would be 'auto' or 'off'. This would feed to a change node that saves the value in a flow variable 'systemstatus'

Next you add a switch node after the mqtt-in 'electric meter' node that checks if flow.systemstatus is auto. If it is, the message passes thru to the rest to the flow, if not nothing goes forward.

Here is the flow:

[{"id":"7b3908c5.c15588","type":"tab","label":"Huawei on/off","disabled":false,"info":""},{"id":"80866fdc06e127fe","type":"mqtt in","z":"7b3908c5.c15588","name":"electricity meter","topic":"evcc/site/gridPower","qos":"0","datatype":"json","broker":"f839540e.7b7858","nl":false,"rap":false,"inputs":0,"x":160,"y":280,"wires":[["b5b81883a98a47e8"]]},{"id":"f57d7408525a979f","type":"mqtt out","z":"7b3908c5.c15588","name":"on","topic":"cmnd/tas02/Power","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"f839540e.7b7858","x":1330,"y":180,"wires":[]},{"id":"c66c54b6929cb23f","type":"debug","z":"7b3908c5.c15588","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1350,"y":300,"wires":[]},{"id":"0f1e33ad983e4cb2","type":"rbe","z":"7b3908c5.c15588","name":"define value change","func":"deadband","gap":"300","start":"","inout":"out","septopics":false,"property":"payload","topi":"topic","x":640,"y":280,"wires":[["ad86aeb9a9907ae6","e75866d60570482a"]]},{"id":"ad86aeb9a9907ae6","type":"switch","z":"7b3908c5.c15588","name":"payload <= -800","property":"payload","propertyType":"msg","rules":[{"t":"lte","v":"-800","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":800,"y":240,"wires":[["c66c54b6929cb23f","a184949a27cd7bc5"]]},{"id":"e75866d60570482a","type":"switch","z":"7b3908c5.c15588","name":"payload >= 300","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"300","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":800,"y":340,"wires":[["c66c54b6929cb23f","8e193c8e87b44819"]]},{"id":"ce5f38eb6f387c05","type":"mqtt out","z":"7b3908c5.c15588","name":"off","topic":"cmnd/tas02/Power","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"f839540e.7b7858","x":1330,"y":400,"wires":[]},{"id":"a184949a27cd7bc5","type":"change","z":"7b3908c5.c15588","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1090,"y":240,"wires":[["f57d7408525a979f","c66c54b6929cb23f"]]},{"id":"8e193c8e87b44819","type":"change","z":"7b3908c5.c15588","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1090,"y":340,"wires":[["ce5f38eb6f387c05","c66c54b6929cb23f"]]},{"id":"a201873577991e29","type":"mqtt in","z":"7b3908c5.c15588","name":"Mode","topic":"akku/mode","qos":"0","datatype":"utf8","broker":"f839540e.7b7858","nl":false,"rap":false,"inputs":0,"x":190,"y":380,"wires":[[]]},{"id":"b5b81883a98a47e8","type":"switch","z":"7b3908c5.c15588","name":"check systemstatus","property":"systemstatus","propertyType":"flow","rules":[{"t":"eq","v":"auto","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":400,"y":280,"wires":[["0f1e33ad983e4cb2"]]},{"id":"601c4454b421fe12","type":"inject","z":"7b3908c5.c15588","name":"auto","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"auto","payloadType":"str","x":130,"y":40,"wires":[["2f76b10f2c1a9a6a"]]},{"id":"d0cd17250b2653fe","type":"inject","z":"7b3908c5.c15588","name":"off","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":130,"y":100,"wires":[["2f76b10f2c1a9a6a"]]},{"id":"2f76b10f2c1a9a6a","type":"mqtt out","z":"7b3908c5.c15588","name":"","topic":"system/status","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"f839540e.7b7858","x":440,"y":60,"wires":[]},{"id":"7e5ea8621a91ddd8","type":"mqtt in","z":"7b3908c5.c15588","name":"process `system/status` commands","topic":"system/status","qos":"2","datatype":"auto-detect","broker":"f839540e.7b7858","nl":false,"rap":true,"rh":0,"inputs":0,"x":220,"y":180,"wires":[["e33b50f712f0789d"]]},{"id":"e33b50f712f0789d","type":"change","z":"7b3908c5.c15588","name":"","rules":[{"t":"set","p":"systemstatus","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":180,"wires":[[]]},{"id":"f839540e.7b7858","type":"mqtt-broker","name":"","broker":"192.168.178.44","port":"1883","clientid":"clientid","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":4,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
1 Like

Much like @zenofmud except i removed duplicated nodes and simplified your flow to.

[{"id":"80866fdc06e127fe","type":"mqtt in","z":"7b3908c5.c15588","name":"electricity meter","topic":"evcc/site/gridPower","qos":"0","datatype":"json","broker":"f839540e.7b7858","nl":false,"rap":false,"inputs":0,"x":200,"y":280,"wires":[["8a454c70a563531c"]]},{"id":"8a454c70a563531c","type":"switch","z":"7b3908c5.c15588","name":"","property":"mode","propertyType":"flow","rules":[{"t":"eq","v":"auto","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":280,"wires":[["ad86aeb9a9907ae6"]]},{"id":"ad86aeb9a9907ae6","type":"switch","z":"7b3908c5.c15588","name":"payload <= -800","property":"payload","propertyType":"msg","rules":[{"t":"lte","v":"-800","vt":"num"},{"t":"gte","v":"300","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":560,"y":280,"wires":[["c66c54b6929cb23f","a184949a27cd7bc5"],["8e193c8e87b44819","c66c54b6929cb23f"]]},{"id":"c66c54b6929cb23f","type":"debug","z":"7b3908c5.c15588","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":160,"wires":[]},{"id":"a184949a27cd7bc5","type":"change","z":"7b3908c5.c15588","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":240,"wires":[["c66c54b6929cb23f","a9c0bc104f359c4e"]]},{"id":"8e193c8e87b44819","type":"change","z":"7b3908c5.c15588","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":300,"wires":[["c66c54b6929cb23f","a9c0bc104f359c4e"]]},{"id":"a9c0bc104f359c4e","type":"rbe","z":"7b3908c5.c15588","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":950,"y":280,"wires":[["ce5f38eb6f387c05"]]},{"id":"405c19f3def8483b","type":"switch","z":"7b3908c5.c15588","name":"","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"auto","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":550,"y":400,"wires":[["a9c0bc104f359c4e"]]},{"id":"ce5f38eb6f387c05","type":"mqtt out","z":"7b3908c5.c15588","name":"off or on","topic":"cmnd/tas02/Power","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"f839540e.7b7858","x":1100,"y":280,"wires":[]},{"id":"5f423b4e75d3cd2e","type":"change","z":"7b3908c5.c15588","name":"","rules":[{"t":"set","p":"mode","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":400,"wires":[["405c19f3def8483b"]]},{"id":"a201873577991e29","type":"mqtt in","z":"7b3908c5.c15588","name":"Mode","topic":"akku/mode","qos":"0","datatype":"utf8","broker":"f839540e.7b7858","nl":false,"rap":false,"inputs":0,"x":190,"y":400,"wires":[["5f423b4e75d3cd2e"]]},{"id":"f839540e.7b7858","type":"mqtt-broker","name":"","broker":"192.168.178.44","port":"1883","clientid":"clientid","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":4,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
1 Like

Thank you so much guys, that is just working! Great!