Msg.length is returning an empty object as a result?

Hey all,

I am new to Node-Red and am running it in Home Assistant. I am also new to HTML with very little previous programming knowledge(some Basic/Visual Basic/Access/C++). Yes that says Basic.

I am pulling an https request from OpenWeatherMap.org that is returning an array of objects(i think?). Is there a way to iterate through all the elements of all the objects and round all numbers to no decimals?

I tried:

var x = 0;
var len =  {payload: msg.payload.length };

while (x < len) {
	if (typeof msg.payload[X]	!== 'string'){
		msg.payload[x] = Number(a.toFixed(0))
	}
x++
}

which did not work.

I then tried to set msg.payload.len to the length function with:

msg.payload.len = {payload: msg.payload.length };

and I get this:

image

As you can see I have .len shown as an object under msg.payload and it shows empty in the debug window. I have tried with and without the () after .length.

Any help appreciated. All of my searches give me nothing except that {payload: msg.payload.length} should work. I tried msg.length as well.

George

Looks like a object of objects.

msg.payload.len = {payload: Object.keys(msg.payload).length };

To be sure an example of the return object from the api request would help.

I am playing with the node openweathermap myself.

It may be a good idea to get that node and use it to parse/create a message for the place you want to get the weather.

Though, if you want to do it that way, I would open all the messages and point to the exact data you want to see/use.

Wow thanks for the quick response.

That does return the total number of the objects in the .payload. It return 16 which is the first level of objects, but how do would I make it look inside each object also?

Here is the list from debug:

I would like to not only like to have "day1" counted, but also the items listed under "day1."

Any Suggestions?

I did not realize there was a node for OpenWeatherMap. Do you have the location for the repository?

Thanks,

George

Yes if you supply an example of the object, there are 6 different objects the api can return, depending on the request.

A screenshot does no work i can not copy or paste the info.

Copy the value and post the result between backticks.
i.e.
```
value
```

Just go to the library and enter openweathermap.

You will need to register and get a key, but that isn't a big deal.
I'm security conscious and it wasn't a problem for me.

open pallette and search "openweathermap"

You are getting a multi-day response.

Not a big deal.

Each day will be structured the same. Just the data will be slightly different in where it is.

In you example is would be something like:
msg.day1......
And you would have the sunrise and sunset times.
Then you would have temp which would have a sub-set of day min max night and eve.... etc.
Then the feels_like with it's sub set.

Day 2 would be only a case of:
msg.day2.......

(Well, you need to click on the install tab rather than the default nodes tab.)

Ok I did this. I had to install npm in order to install the node. When I installed it seems to have gone off without a hitch, but the nodes were not added to my node-red window?

Here was the response from the install

I restarted HASS after the install and closed and reloaded the web gui, still no new nodes...

Any Ideas?

oh I see now. sorry new to all this. I figured it out

Thanks for the help

I think you need to be in ~/.node-red to install the node.

And you could have done it from within node-red. Menu, palette manager, install and type the name.

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