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.
Sending a value to an Event
Moderators: grovkillen, Stuntteam, TD-er
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: Sending a value to an Event
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:
And then publish this:
or this:
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
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;
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: Sending a value to an Event
Hi Martinus,
Works like a dream - thanks for taking the time to point me in the right direction.
Thanks again from David
Works like a dream - thanks for taking the time to point me in the right direction.
Thanks again from David
Who is online
Users browsing this forum: No registered users and 21 guests