Help with functions

It doesn’t look like your sensor is returning a temperature or at least a msg that identifies a reading as a temperature.

If you look at the debug #1 it shows the temp as 84.45502 and the humidity as 53.32265
What is wrong with that?

you also ask " P.p.s. It looks like your flow is issuing the exact same http request for some solar data. Can you explain that?"

Sorry I don't have anything about solar in the flow that I know of.

Oops my mistake, I imported your flow but looked at a flow I inserted while looking at another thread.

So the data is coming from an mqtt node. What is publishing the the data and how is it identifying that the msg is sending a temperature or a humidity?

Also, you are sending every msg to both the temperature and humidity gauges.

If you control the content/topics if the device sending the data you should change it to either put both temperature and humidity in the payload or send one msg with the topic indicating is is for the temperature and one for humidity with the topic indicating it is for the humidity. The. In the flow eithor have one mqtt-in node subscribing to the high level of the topic and a switch node to determine if it is for temp or humi and sending it to the correct flow, to row mqtt-in nodes, one just getting the temperature msgs and one getting the humidity msgs.

I am looking at the data from the two change node so yes that is why I see 2 times. If i look at the data from the sht30temp node the mqtt reciver I can't get it to display anything below is a debug of the output of the mqtt node

7/23/2021, 8:03:23 PMnode: ea9eef94.21b9fsht30temp : msg : Object

object

topic: "sht30temp"

payload: object

device: "SHT30#1"

fTemp: 92.49645

humidity: 40.41352

qos: 1

retain: false

_msgid: "e156e403.5326d8"

yes you are correct saying
"If you control the content/topics "
but I don't know how. Ronbu

Here is what is happening. A msg arrives from the mqtt-in node which is connected to two change nodes. This cause the msg to be cloned so now two msgs are passing thru the flows.

One change node causes msg.payload to be set to msg.payload.fTemp while the other causes msg.payload to be set to msg.payload.humidity. Each msg travels to the appropriate ui-guage but is also sent to a function node.

Here is where the issue happens. The two msgs arrive - at seperate times - at the function node. The function node process each msg separately.

there are two things you could do, (1) rejoin the two msgs before sending them to the function node or (2) also connect the mqtt-in node to the function node. You will have to change the first two lines of the code to reflect msg.payload.fTemp and msg.payload.humidity.

That should get you going.

WOW that sounds like it may work I will try both suggestions. I'll let you know. Thank you Ronbu.

I will have to study the join node as I have never used it before

I now get this error:

"Message missing msg.parts property - cannot join in 'auto' mode"

well I have tried both suggestion you have given me however I am having no luck as writing the function and the new (to me) join node , Would you please re-write my flow and the function so I would have a working flow so I can study it and understand how this works. I am at my wits end on this and want to give up but I want to learn, but getting no ware. Ronbu. I just want to learn......

not relevant

SOrry just saw this post.

You do not need the change nodes

As it is an object you can just reference each of the values with

msg.payload.ftemp
msg.payload.humidity

Make sure they are numbers and put them into your original function

var T = msg.payload.ftemp;
var H = msg.payload.humidity;
node.warn(["T",T, typeof T]);
node.warn(["H",H, typeof H]);
var HI = -42.379 + 2.04901523*T + 10.14333127*H - .22475541*T*H - .00683783*T*T - .05481717*H*H + .00122874*T*T*H + .00085282*T*H*H - .00000199*T*T*H*H;
msg.payload = HI;
return msg;

Craig

While @craigcurtin has the function correct, you do still need the change nodes to move the T and H readings to msg.payload because the gauges require the values to be in msg.payload.

Here is the complete flow

[{"id":"ddb60bf6.ecbe98","type":"tab","label":"sht30","disabled":false,"info":""},{"id":"795c8109.f4c5c","type":"mqtt in","z":"ddb60bf6.ecbe98","name":"","topic":"sht30temp","qos":"2","datatype":"json","broker":"f59c9fa3.bd9ea","x":60,"y":140,"wires":[["501656f8.157128","f0c3b57f.b3e528","cff8bba.e10a848"]]},{"id":"10504951.4a3f87","type":"mqtt out","z":"ddb60bf6.ecbe98","name":"","topic":"sht30temp","qos":"2","retain":"","broker":"f59c9fa3.bd9ea","x":330,"y":20,"wires":[]},{"id":"dc9feee4.0f951","type":"debug","z":"ddb60bf6.ecbe98","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":590,"y":140,"wires":[]},{"id":"1b4b9cde.7d67a3","type":"ui_gauge","z":"ddb60bf6.ecbe98","name":"","group":"b716789b.7d27d8","order":1,"width":6,"height":3,"gtype":"gage","title":"TEMPTURE","label":"#","format":"{{value}}","min":"50","max":"110","colors":["#00b500","#e6e600","#ca3838"],"seg1":"40","seg2":"80","x":570,"y":100,"wires":[]},{"id":"501656f8.157128","type":"change","z":"ddb60bf6.ecbe98","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.fTemp","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":120,"wires":[["dc9feee4.0f951","1b4b9cde.7d67a3","9cb137e.89d2ac8","442805a3.6c525c","cff8bba.e10a848"]]},{"id":"9d1def75.64854","type":"ui_gauge","z":"ddb60bf6.ecbe98","name":"","group":"b716789b.7d27d8","order":2,"width":6,"height":3,"gtype":"gage","title":"HUMIDITY","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"25","seg2":"50","x":550,"y":240,"wires":[]},{"id":"f0c3b57f.b3e528","type":"change","z":"ddb60bf6.ecbe98","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.humidity","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":200,"wires":[["9d1def75.64854","f463c05a.b86ca","b0f855b5.ea91b8","442805a3.6c525c","cff8bba.e10a848"]]},{"id":"f463c05a.b86ca","type":"debug","z":"ddb60bf6.ecbe98","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":560,"y":200,"wires":[]},{"id":"b0f855b5.ea91b8","type":"ui_chart","z":"ddb60bf6.ecbe98","name":"","group":"b716789b.7d27d8","order":15,"width":20,"height":7,"label":"chart","chartType":"line","legend":"false","xformat":"dd HH:mm","interpolate":"linear","nodata":"","dot":false,"ymin":"30","ymax":"100","removeOlder":"4","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":560,"y":300,"wires":[[]]},{"id":"9cb137e.89d2ac8","type":"ui_chart","z":"ddb60bf6.ecbe98","name":"","group":"b716789b.7d27d8","order":7,"width":20,"height":7,"label":"chart","chartType":"line","legend":"false","xformat":"dd HH:mm","interpolate":"linear","nodata":"","dot":false,"ymin":"30","ymax":"110","removeOlder":"4","removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":580,"y":60,"wires":[[]]},{"id":"57aa2c4a.898264","type":"ui_text","z":"ddb60bf6.ecbe98","group":"b716789b.7d27d8","order":8,"width":0,"height":0,"name":"heat index","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":550,"y":380,"wires":[]},{"id":"f92436d7.42e8d8","type":"debug","z":"ddb60bf6.ecbe98","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":560,"y":420,"wires":[]},{"id":"decf5436.247168","type":"ui_gauge","z":"ddb60bf6.ecbe98","name":"","group":"b716789b.7d27d8","order":3,"width":7,"height":3,"gtype":"gage","title":"gauge","label":"units","format":"{{value}}","min":0,"max":"130","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":570,"y":460,"wires":[]},{"id":"cff8bba.e10a848","type":"function","z":"ddb60bf6.ecbe98","name":"heat index fourmal","func":"var T = msg.payload.fTemp;\nvar H = msg.payload.humidity;\nnode.warn([\"T\",T, typeof T]);\nnode.warn([\"H\",H, typeof H]);\nvar HI = -42.379 + 2.04901523*T + 10.14333127*H - .22475541*T*H - .00683783*T*T - .05481717*H*H + .00122874*T*T*H + .00085282*T*H*H - .00000199*T*T*H*H;\nmsg.payload = HI;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":330,"y":400,"wires":[["57aa2c4a.898264","decf5436.247168","f92436d7.42e8d8"]]},{"id":"442805a3.6c525c","type":"debug","z":"ddb60bf6.ecbe98","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":540,"y":340,"wires":[]},{"id":"f59c9fa3.bd9ea","type":"mqtt-broker","z":"","name":"HOME","broker":"192.168.0.05:1880","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"b716789b.7d27d8","type":"ui_group","z":"ddb60bf6.ecbe98","name":"SHT30","tab":"6ed960d6.dc76e","order":10,"disp":true,"width":20,"collapse":false},{"id":"6ed960d6.dc76e","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
1 Like

Good morning;
Are you sure you sent the new flow in your post? It is the same flow I had sent you.It does not have the join node and still does not show the heat index. please check your post maybe I am not importing it in-correct. Ronbu.

The above was the post i wanted to send last night but again the forum locked out as I am a new user.....well thats a mute point now as I was working on the code my PI 3 B+ SD card crashed....and no I do not have a backup so I out of this for now....All my flows, Arduino code is gone... I have spent the day tring to recover the SD card but not having any luck. I am very, very sad.. Ronbu.

Need I say more Ron...

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.