MQTT (JASON) Rule Engine failure ?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Normal user
Posts: 8
Joined: 25 Jul 2021, 22:45

MQTT (JASON) Rule Engine failure ?

#1 Post by kohleIT » 30 Jul 2021, 20:03

Hello experts,
I try to get my measurement to NodeRed transferred via MQTT and JASON.
After some research I could get a hint here in the Forum So I created a rule that formats the “output” as Jason and sent it via MQTT to the Broker.
Basically, it works as long I use a Single Value.

My Target is to Transfer Temperature and Humidity in one JASON.

The Problem is following line:

Code: Select all

Publish %sysname%/Sensor_%unit%/Oben,{"Temperture":"[Oben#Temperature]","Humidity":"[Oben#Humidity]"}
The Problem in the "," between the 2 Values. ("[Oben#Temperature]","Humidity")
In MQTT Explorer i can observe that the 2nd part is missing(Humidity). pls have a look on the attached picture.


Code: Select all

on System#Boot do

On Rules#Timer=1 do
    Publish %sysname%/Sensor_%unit%/Oben,{"Temperture":"[Oben#Temperature]","Humidity":"[Oben#Humidity]"}
    Publish %sysname%/Sensor_%unit%/ObenT,{"ObenT":"[Oben#Temperature]"}
    Publish %sysname%/Sensor_%unit%/ObenH,{"ObenH":"[Oben#Humidity]"}


Code: Select all

EVENT: Rules#Timer=1,1
846382: ACT  : Publish xxx/Sensor_4/Oben,{'Temperture':'26.50','Humidity':'52.60'}
846388: Too many arguments: cmd=Publish Arg1=xxx/Sensor_4/Oben Arg2={'Temperture':'26.50' ExtraArg3='Humidity':'52.60'} lin
846388: Line: _Publish xxx/Sensor_4/Oben,{'Temperture':'26.50','Humidity':'52.60'}_
846388: Command not executed! See:
846405: Command unknown: Publish xxx/Sensor_4/Oben,{'Temperture':'26.50','Humidity':'52.60'}
846417: ACT  : Publish xxx/Sensor_4/ObenT,{'ObenT':'26.50'}
846441: ACT  : Publish xxx/Sensor_4/ObenH,{'ObenH':'52.60'}
846453: ACT  : timerSet,1,1

After implementing here the Log, I realized an hint in the Log:
Played a little bit around with different possibilities and I got it fixed by myself.
Put the whole publish command under “ ’ ”
Unbenannt4.PNG (11.95 KiB) Viewed 884 times

Core team member
Posts: 5373
Joined: 01 Sep 2017, 22:13
Location: the Netherlands

Re: MQTT (JASON) Rule Engine failure ?

#2 Post by TD-er » 30 Jul 2021, 21:14

JSON should use the double quotes. Otherwise it isn't valid JSON.

You could however wrap the publish command argument in other quotes.

For example if you need to use " in your argument, you can wrap the entire argument in single quotes as long as you don't need them.

Also a comma is typically considered an argument separator, so by wrapping the last argument in quotes you get by that problem.

See also this sticky topic for more info:

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests