Sending a value to an Event

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
dynamicdave
Normal user
Posts: 219
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Sending a value to an Event

#1 Post by dynamicdave » 28 Aug 2017, 18:43

Hi all,
I have an ESP8266 node fitted with a DHT11 temperature/humidity sensor that works fine publishing values to Node-Red via MQTT.

What I would like to do is send a value/parameter to an event to get the ESP8266 node to send either temperature or humidity.

I can't seem to get the following code in the "rules" section to decode the value/parameter.

on sendReadings do
if [%eventvalue%] = "TEMP"
Publish /node21/temperature,[dht11#temperature]
else if [%eventvalue%] = "HUMID"
Publish /node21/humidity,[dht11#humidity]
endif
end on

And this is what I have in a Function node that connects to MQTT output node.

msg.topic = "/wemos21/cmd";
msg.payload = "event,sendReadings=TEMP";
return msg;

I have another Function node that sends...

msg.topic = "/wemos21/cmd";
msg.payload = "event,sendReadings=HUMID";
return msg;

If anyone can spot what's wrong with my decoding I would be very grateful.

Kind regards from David.

Martinus

Re: Sending a value to an Event

#2 Post by Martinus » 28 Aug 2017, 19:49

The rules engine is very basic and does not compare with strings. Things like """ are not parsed and everything provided as value is converted to floats and then compared.
Also the "else if" is not supported.

But you can achieve this quite simple in this way:

Code: Select all

on sendReadings=1 do
    Publish /node21/temperature,[dht11#temperature]
endon
on sendReadings=2 do
    Publish /node21/humidity,[dht11#humidity]
endon
And then publish this:

Code: Select all

msg.topic = "/wemos21/cmd";
 msg.payload = "event,sendReadings=1";
 return msg;

or this:

Code: Select all

msg.topic = "/wemos21/cmd";
 msg.payload = "event,sendReadings=2";
 return msg;

User avatar
dynamicdave
Normal user
Posts: 219
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Sending a value to an Event

#3 Post by dynamicdave » 28 Aug 2017, 19:54

Hi Martinus,
Works like a dream - thanks for taking the time to point me in the right direction.

Thanks again from David

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 14 guests