Problem with translation MQTT transmision by Node-red

Everything about esp8266 and more.

Moderator: leecollings

Post Reply
rkarolek
Posts: 33
Joined: Friday 31 August 2018 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Problem with translation MQTT transmision by Node-red

Post by rkarolek »

hello
i have problem with transalate my MQTT device's to domoticz by node red.
my device publish - "dom/salon/gniazdko/temperature 33.13"
i translate it by node red to - "domoticz/in {"command":"udevice","idx":252,"svalue":33.13}"
but its not works at all :(
in domoticz log i can see
"2020-02-23 20:55:17.625 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":252,"svalue":33.13}
2020-02-23 20:55:17.625 Error: MQTT: Invalid data received!"

what im doing wrong??

Please help
User avatar
McMelloW
Posts: 430
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Problem with translation MQTT transmision by Node-red

Post by McMelloW »

Greetings McMelloW
rkarolek
Posts: 33
Joined: Friday 31 August 2018 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problem with translation MQTT transmision by Node-red

Post by rkarolek »

already read this topics, i followed step by step and as i said i translate my device to domoticz format, but.... its not works
so i think i do any stupid mistake and why i cant solve it :(
User avatar
FireWizard
Posts: 1762
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Problem with translation MQTT transmision by Node-red

Post by FireWizard »

Hi,

Change the command to: {"command":"udevice","idx":252,"svalue":"33.13"}

Mind the position of " ". The value, you want to send to Domoticz (svalue) has to be a string.

Regards
rkarolek
Posts: 33
Joined: Friday 31 August 2018 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problem with translation MQTT transmision by Node-red

Post by rkarolek »

works!
tyvm!
rkarolek
Posts: 33
Joined: Friday 31 August 2018 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problem with translation MQTT transmision by Node-red

Post by rkarolek »

new problem :(
translate temperature works well, so i try add switch controll too
now my transalte function looks like:

Code: Select all

switch (msg.topic) {

    case "dom/salon/gniazdko/temperature":
    msg.payload = {"command":"udevice","idx":252,"nvalue":0,"svalue":msg.payload};
    break;
    
    case "dom/salon/gniazdko/gniazdko/state":
    msg.payload = {"command":"switchlight","idx":249,"switchcmd":msg.payload};
    break;

}
return msg;
switching command are translate to:
domoticz/in {"command":"switchlight","idx":249,"switchcmd":"on"}

but my switch in domoticz dont works :(
in domoticz log i can find such note:
2020-03-07 14:02:22.178 MQTT: Topic: domoticz/in, Message: {"command":"switchlight","idx":249,"switchcmd":"on"}
2020-03-07 14:02:22.179 Error: MQTT: Error sending switch command!
i cant understand why switch not works, where is mistake??

maybe problemis that in translate command are "on"/"off", but domoticz need "On"/"Off"??? if yes how i should change my function?

ty in advance for any hints
User avatar
FireWizard
Posts: 1762
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Problem with translation MQTT transmision by Node-red

Post by FireWizard »

Hi,

Please Note:

From the wiki: https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s
Turn a light/switch off

/json.htm?type=command&param=switchlight&idx=99&switchcmd=Off

idx = id of your device (in this example 99).
switchcmd = "On" or "Off" (case sensitive!)
So change: domoticz/in {"command":"switchlight","idx":249,"switchcmd":"on"}
to: domoticz/in {"command":"switchlight","idx":249,"switchcmd":"On"}

Regards
rkarolek
Posts: 33
Joined: Friday 31 August 2018 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problem with translation MQTT transmision by Node-red

Post by rkarolek »

how i can change "on" to "On"??
sry if it stupid question, but im really new in this :(

EDIT
i change my function

Code: Select all

    case "dom/salon/gniazdko/gniazdko/state":
    if (msg.payload == "on")
    {
        msg.payload = {"command":"switchlight","idx":251,"switchcmd":"On"};
    }
    else
    {
        msg.payload = {"command":"switchlight","idx":251,"switchcmd":"Off"};
    }    
    break;   
it works, but maybe it should be done in better way?
User avatar
FireWizard
Posts: 1762
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Problem with translation MQTT transmision by Node-red

Post by FireWizard »

Hi,

The way you do it, is one possibility.

I assume that your payload is either "on" or "off" and you have to change that to "On" or "Off".

You can follow your first approach:

Code: Select all

switch (msg.topic) {

    case "dom/salon/gniazdko/temperature":
    msg.payload = {"command":"udevice","idx":252,"nvalue":0,"svalue":msg.payload};
    break;
    
    case "dom/salon/gniazdko/gniazdko/state":
    msg.payload = {"command":"switchlight","idx":249,"switchcmd":msg.payload};
    break;

}
return msg;
and change that to:

Code: Select all

switch (msg.topic) {

    case "dom/salon/gniazdko/temperature":
    msg.payload = {"command":"udevice","idx":252,"nvalue":0,"svalue":msg.payload};
    break;
    
    case "dom/salon/gniazdko/gniazdko/state":
    msg.payload = {"command":"switchlight","idx":249,"switchcmd":(msg.payload.charAt(0).toUpperCase() + msg.payload.slice(1))};
    break;

}
return msg;

Some explanation:
I took the first character of the payload (either "on" or "off"). The first character starts at 0 and therefore charAt(0) and only this character is converted to Upper case. And then I added, with the + sign, the remaining of the payload, starting from the second character (1)

So this function converts the first character of every string starting with a lowercase alphabet character to an uppercase character.

Try it,

Regards
rkarolek
Posts: 33
Joined: Friday 31 August 2018 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problem with translation MQTT transmision by Node-red

Post by rkarolek »

my version is simply,
your solution loks much much smart, and elegant, and propably idiot resistant :)

tyvm for help
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests