Turning on / off relay using MQTT

195 views
Skip to first unread message

Ulf Holt

unread,
Jan 3, 2023, 2:37:22 AM1/3/23
to TasmotaUsers
I know I have made this work, but I'm getting old and keep forgetting stuff.

I have configured MQTT on Tasmota using Topic Aqua1

I have set up relay on GPIO5 and when I use node-red to send cmnd/Aqua1/Power, this will turn the relay on, but I cannot find a way to turn it off. cmnd/Aqua1/Power off returns command unknown. Any idea what I am doing wrong?

Best regards

Ulf

Philip Knowles

unread,
Jan 3, 2023, 2:53:11 AM1/3/23
to Ulf Holt, TasmotaUsers

Try power1 1 for on and power1 0 for off. It’s best to always enumerate the relay.

 

Sent from Mail for Windows

--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/6bfec602-3b3a-40b8-985b-bc7a6302a022n%40googlegroups.com.

 

billy jack

unread,
Jan 3, 2023, 3:44:26 AM1/3/23
to Philip Knowles, Ulf Holt, TasmotaUsers

I may have missed part of question. Make sure you know if your relay turns on with active high or an active low.

Most importantly.

Also check to see if your sending the message in a string, variable, number . ….. sometimes we miss the little thing that makes the difference.

Cheers.

 

 

Sent from Mail for Windows

 

billy jack

unread,
Jan 3, 2023, 3:49:55 AM1/3/23
to Philip Knowles, Ulf Holt, TasmotaUsers

Sorry better info here.

Look at the 2 pictures the one where msg is set to off make sure its in string “az”

Second make sure the message topic is set to your unit. So it should be cmnd/auqua1/POWER

 

Sent from Mail for Windows

 


Sent: Monday, January 2, 2023 11:53 PM
To: Ulf Holt; TasmotaUsers

Philip Knowles

unread,
Jan 3, 2023, 4:00:46 AM1/3/23
to billy jack, Ulf Holt, TasmotaUsers
Tasmota doesn't care if it's a string or number. If the payload in node-red is on or 1 for ON or off or 0 for OFF provided that you get the topic right it will work. As I said before it is better to use an enumerated power topic. I always use 0 and 1 because it's easier to do maths changes in rules to change the value.
The OP didn't appear to use a payload in the cmnd to turn on. He may be using msg.payload set earlier in the flow.
A console listing might help work out what's going on.


From: billy jack <billyj...@gmail.com>
Sent: Tuesday, January 3, 2023 8:44:17 AM
To: Philip Knowles <knowles...@gmail.com>; Ulf Holt <ulf....@gmail.com>; TasmotaUsers <sonof...@googlegroups.com>

ulf....@gmail.com

unread,
Jan 3, 2023, 5:17:37 AM1/3/23
to Philip Knowles, sonof...@googlegroups.com

I'm sure this is a syntax problem.

This will turn set the pin High:

This will give an error message:

 

I have tried using Power1 0 instead, still not working.

 

I have tried cmnd/Aqua1 in the Topic field and the Power1 0 in the text field, same problem.

 

Sorry for being stupid!

 

Best regards

 

Ulf

image001.png
image002.png

Philip Knowles

unread,
Jan 3, 2023, 5:42:09 AM1/3/23
to ulf....@gmail.com, sonof...@googlegroups.com

Try this (import into node-red. Change the MQTT information to suit yours.

    {

        "id": "c7a2a0dd595c376b",

        "type": "inject",

        "z": "15a1f47e5892aace",

        "name": "ON",

        "props": [

            {

                "p": "payload"

            },

            {

                "p": "topic",

                "vt": "str"

            }

        ],

        "repeat": "",

        "crontab": "",

        "once": false,

        "onceDelay": 0.1,

        "topic": "cmnd/Aqara/power",

        "payload": "1",

        "payloadType": "str",

        "x": 90,

        "y": 120,

        "wires": [

            [

                "884c18039c8bfaaa"

            ]

        ]

    },

    {

        "id": "487f81a2867e69cc",

        "type": "inject",

        "z": "15a1f47e5892aace",

        "name": "OFF",

        "props": [

            {

                "p": "payload"

            },

            {

                "p": "topic",

                "vt": "str"

            }

        ],

        "repeat": "",

        "crontab": "",

        "once": false,

        "onceDelay": 0.1,

        "topic": "cmnd/Aqara/power",

        "payload": "0",

        "payloadType": "str",

        "x": 90,

        "y": 180,

        "wires": [

            [

                "884c18039c8bfaaa"

            ]

        ]

    },

    {

        "id": "884c18039c8bfaaa",

        "type": "mqtt out",

        "z": "15a1f47e5892aace",

        "name": "Aqara",

        "topic": "",

        "qos": "",

        "retain": "",

        "respTopic": "",

        "contentType": "",

        "userProps": "",

        "correl": "",

        "expiry": "",

        "broker": "47f1dec978a181e1",

        "x": 340,

        "y": 160,

        "wires": []

    },

    {

        "id": "47f1dec978a181e1",

        "type": "mqtt-broker",

        "name": "YourMQTTBroker",

        "broker": "192.168.xxx.xxx",

        "port": "1883",

        "clientid": "",

        "autoConnect": true,

        "usetls": false,

        "protocolVersion": "4",

        "keepalive": "60",

        "cleansession": true,

        "birthTopic": "",

        "birthQos": "0",

        "birthPayload": "",

        "birthMsg": {},

        "closeTopic": "",

        "closeQos": "0",

        "closePayload": "",

        "closeMsg": {},

        "willTopic": "",

        "willQos": "0",

        "willPayload": "",

        "willMsg": {},

        "sessionExpiry": ""

    }

]

Sent from Mail for Windows

 

From: ulf....@gmail.com
Sent: 03 January 2023 10:17
To: Philip Knowles; sonof...@googlegroups.com
Subject: SV: Turning on / off relay using MQTT

 

I'm sure this is a syntax problem.

This will turn set the pin High:

This will give an error message:

 

I have tried using Power1 0 instead, still not working.

 

I have tried cmnd/Aqua1 in the Topic field and the Power1 0 in the text field, same problem.

 

Sorry for being stupid!

 

Best regards

 

Ulf

 

Fra: Philip Knowles <knowles...@gmail.com>
Sendt: tirsdag 3. januar 2023 10:01
Til: billy jack <billyj...@gmail.com>; Ulf Holt <ulf....@gmail.com>; TasmotaUsers <sonof...@googlegroups.com>
Emne: Re: Turning on / off relay using MQTT

 

Tasmota doesn't care if it's a string or number. If the payload in node-red is on or 1 for ON or off or 0 for OFF provided that you get the topic right it will work. As I said before it is better to use an enumerated power topic. I always use 0 and 1 because it's easier to do maths changes in rules to change the value.

The OP didn't appear to use a payload in the cmnd to turn on. He may be using msg.payload set earlier in the flow.

A console listing might help work out what's going on.

 

ulf....@gmail.com

unread,
Jan 3, 2023, 8:24:12 AM1/3/23
to Philip Knowles, sonof...@googlegroups.com

Thank you, Philip.

 

Import did not work (Not a Jason Array) but I saw what you were doing, so I just changed the Topic and the Text accordingly – worked like a dream. It's all in the small details:

 

And use 0 to turn off.

 

All the best from

image004.png
image005.png
image006.png
image007.png
Reply all
Reply to author
Forward
0 new messages