Help with functions

i want to write a function to display heat index from temp and humidity from a sensor. I just don't know how to format the function to use the NWS equation any help? i can display the temp and humidity in the dashboard but i want to display the heat index as well. Ron

Hi and welcome to the group/forum.

What is this NWS equation?

You have a dashboard working and that is good.

What kind of messages do you get from the sensor?

Could you post the message so it is known?

hello the NWS equation is the formual to calcuate the temp and humidity to get a heat or feel like tempture

i get the temp and the humidity and is displayed as number it all works well and i see it on my gauges just fine but i also want to display the cal. heat value

Do you already have any JavaScript code to put in the function node?

If not, have you Googled for any?

I did. You will need to fiddle around with it to grab the sensor data and display as a msg instead of out to the console.

this is the forumal frome NWS;
HI = -42.379 + 2.04901523T + 10.14333127RH - .22475541TRH - .00683783TT - .05481717RHRH + .00122874TTRH + .00085282TRHRH - .00000199TTRHRH

HI is heat index
T is temp
HR is humidity

RH I mean

i see now you sent a link I will look at that now . thank you.

hi gunner I have looked at the code but still don't understand do I copy the code and put it into the function or what ?

If you are using a function node, it is basically you write the formula as it is.

You still haven't shown the message with the values so this is an example:

The message looks like this - to say:

msg = {"payload":"something","temperature":30,"humidity":30};

And what ever else.

In the function node:

var temperature = msg.temperature;
var humidity = msg.humidity;
var feels_like = -42.379 + 2.04901523T + 10.14333127RH - .22475541TRH - .00683783TT - .05481717RHRH + .00122874TTRH + .00085282TRHRH - .00000199TTRHRH
msg.payload = feels_like;
return msg;

Where the temperature and humidity are from the initial lines where you define them from the original incoming message.

Then the value you want is spat out as msg.payload.
You then send that to a chart node and it is mapped.

I will study this more but for tonight I must stop now thank you Ron.

this my function so far and I get the NaN error.

var T = msg.ftemp;
var H = msg.humidity;
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;

the equation works...

It is most likely msg.ftemp or msg.humidity are not numbers.

Try this...

var T = msg.ftemp;
var H = msg.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;

... then look in the debug window - whar to you see when the function runs?

7/22/2021, 3:06:15 PMnode: cff8bba.e10a848function : (warn)

array[3]

0: "T"

1: null

2: "undefined"

7/22/2021, 3:06:15 PMnode: cff8bba.e10a848function : (warn)

array[3]

0: "H"

1: null

2: "undefined"

So that's why you get NaN, the values are not numbers.

Put a debug node before the function (set to show complete message) - do you see the temperature and humidity values?

because I am a" NEW USER" the forum kicked me off last night,
said to wait 6 hours so Here is the error I get in the debug window.
I have two debugs set up 1 is the data I am putting in to the fuction.
2 is the function output. You can see I am gettig two temp reading
and two humidity readings, so the fourmal is the wrong result.
I know the function is not writen right or the data
I am sending is in the wrong format

type 7/23/2021, 12:37:32 PMnode: debug 1
sht30temp : msg : Object
{ topic: "sht30temp", payload: 84.45502, qos: 1, retain: false, _msgid: "96609882.5777a8" }
7/23/2021, 12:37:32 PMnode: cff8bba.e10a848
function : (warn)
[ "T", 84.45502, "number" ]
7/23/2021, 12:37:33 PMnode: cff8bba.e10a848
function : (warn)
[ "H", 84.45502, "number" ]
7/23/2021, 12:37:33 PMnode: debug 1
sht30temp : msg : Object
{ topic: "sht30temp", payload: 53.32265, qos: 1, retain: false, _msgid: "96609882.5777a8" }
7/23/2021, 12:37:33 PMnode: cff8bba.e10a848
function : (warn)
[ "T", 53.32265, "number" ]
7/23/2021, 12:37:33 PMnode: cff8bba.e10a848
function : (warn)
[ "H", 53.32265, "number" ]
7/23/2021, 12:37:33 PMnode: debug 2
sht30temp : msg : Object
{ topic: "sht30temp", payload: 97.1269255999811, qos: 1, retain: false, _msgid: "96609882.5777a8" }
7/23/2021, 12:37:33 PMnode: debug 2
sht30temp : msg : Object
{ topic: "sht30temp", payload: 92.8997858105952, qos: 1, retain: false, _msgid: "96609882.5777a8" }

I don't know how to send the flow for you to see it.

This is the function as of now.

var T = msg.payload;
var H = msg.payload;
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;

This is the flow I think?..

[{"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":120,"wires":[["501656f8.157128","f0c3b57f.b3e528"]]},{"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;\nvar H = msg.payload;\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,"x":360,"y":440,"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}]

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

How are you reading the sensor?

P.s. I had to edit your last post because you had your text as part of the code

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