# Help with "openweathermap" node

**URL:** <https://discourse.nodered.org/t/help-with-openweathermap-node/35042>\
**Category:** General\
**Created:** [29 October 2020 21:08 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042 "2020-10-29T21:08:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 October 2020 21:08 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/1 "2020-10-29T21:08:17Z")

</div>

I am playing with this node and have found a bump in my desire.

The node puts out a nice message with a lot of data. Not a problem.

It has things like "Sunrise" and "Sunset" times as numbers. Again: Fair enough.  
What I am failing to find/see is the "now" timestamp in the same format as the sunrise/set times.

Why?

Well, to be adventurous I am wanting to change the icons (where possible) between day and night.

I was going to do complicated stuff but then noticed the sunrise/set times in the message.  
But! No "now".

Am I missing any elephants?

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [29 October 2020 21:15 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/2 "2020-10-29T21:15:59Z")

</div>

> [@Trying\_to\_learn](#):
>
> What I am failing to find/see is the "now" timestamp in the same format as the sunrise/set times.

What is the format of the sunrise/set times, can you post an example.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 October 2020 21:19 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/3 "2020-10-29T21:19:00Z")

</div>

Sorry.

Sunrise: `1603998077`

One of those _magic_ numbers.

I'm now looking for a _now_ value in the message which I can use to compare.

eg code:

```auto
if ((now > sunrise) && (now < sunset))
{
   // it is daytime
}
else
// it is night time

```

But that will need a _now_ part of the message, which I am not able to resolve - if it exists at all.

This is the entire output - example:

```auto
{"_msgid":"b6f65f3.c6627a","payload":{"id":804,"weather":"Clouds","detail":"overcast clouds","icon":"04d","tempk":282.15,"tempc":9,"temp_maxc":9,"temp_minc":9,"humidity":100,"pressure":1011,"maxtemp":282.15,"mintemp":282.15,"windspeed":2.6,"winddirection":30,"location":"Cooma","sunrise":1603998077,"sunset":1604046769,"clouds":90,"description":"The weather in Cooma at coordinates: -36.23, 149.13 is Clouds (overcast clouds)."},"topic":"","_event":"node:f9c0e98d.a5a3c","icon":"<i class=\"fa fa-refresh fa-spin\"></i>","background":"#333333","font":"red","location":{"lon":149.13,"lat":-36.23,"city":"Cooma","country":"AU"},"data":{"coord":{"lon":149.13,"lat":-36.23},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"base":"stations","main":{"temp":282.15,"feels_like":280.11,"temp_min":282.15,"temp_max":282.15,"pressure":1011,"humidity":100},"visibility":2000,"wind":{"speed":2.6,"deg":30},"clouds":{"all":90},"dt":1604006093,"sys":{"type":1,"id":9520,"country":"AU","sunrise":1603998077,"sunset":1604046769},"timezone":39600,"id":2170577,"name":"Cooma","cod":200},"time":"2020-10-29T21:14:53.000Z","title":"Current Weather Information","description":"Current weather information at coordinates: -36.23, 149.13"}

```

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [29 October 2020 21:23 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/4 "2020-10-29T21:23:54Z")

</div>

> [@Trying\_to\_learn](#):
>
> 1603998077

Well that timestamp is in seconds, so if you are comparing it with a timestamp from for example `simpletime` (which is in milliseconds), then multiply it by 1000, so it becomes `1603998077000`

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 October 2020 21:25 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/5 "2020-10-29T21:25:46Z")

</div>

well, ok. That's good to know.

What is (now) confusing me is there is a `clouds.dt` field which I suspect is _now_.

But I am at a loss which node will convert it to a human readable value to confirm this.

Because if that is true - is the _now_ time, I can use those three numbers.

I get the message (eg: the one I posted) and put it through the `moment` node and I see the time now - local format.

But I am not getting anywhere when I try to convert the `sunrise` and `sunset` numbers to a human readable time format. And I know it should be easy peasy.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [29 October 2020 21:31 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/7 "2020-10-29T21:31:43Z")

</div>

> [@Trying\_to\_learn](#):
>
> there is a `clouds.dt` field

I can't see a `clouds.dt` field in the data that you posted...

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 October 2020 21:35 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/8 "2020-10-29T21:35:50Z")

</div>

`data.dt` sorry.

(This is not going to be a good day)

But when I put it through the `moment` node I only get the number I injected back out.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [29 October 2020 21:38 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/9 "2020-10-29T21:38:52Z")

</div>

> [@Trying\_to\_learn](#):
>
> `data.dt` sorry.

I can't see that either!

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 October 2020 21:42 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/10 "2020-10-29T21:42:00Z")

</div>

Hmmmm......

![Screenshot from 2020-10-30 08-34-35](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/7/1774a82d697c38191ac1e980778de9637b65acb6.png)

I click on the top `copy` icon and I hope to get the entire message.

![Screenshot from 2020-10-30 08-42-22](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/a/ba38970eeb401ac3a0c71d624336896765991ff4.png)

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [29 October 2020 21:48 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/11 "2020-10-29T21:48:02Z")

</div>

Yes, it appears to be a recent timestamp, again, in seconds.  
Have you checked the [openweathermap api docs](https://openweathermap.org/api), to see what that timestamp relates to, ie - observation time, etc

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 October 2020 21:50 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/12 "2020-10-29T21:50:56Z")

</div>

I think it is the expiration time: 23:55.

I'll go away and read them now. I was just looking at the message/s being sent out and looking for the values.

You are right, I probably should have read the docs first. But I guess I was only at a reconecence level of getting this done.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [29 October 2020 21:54 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/13 "2020-10-29T21:54:31Z")

</div>

> [@Trying\_to\_learn](#):
>
> there is a `clouds.dt`

The timestamp of the request is

```auto
   payload.data.dt

```

I believe.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 October 2020 21:55 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/14 "2020-10-29T21:55:11Z")

</div>

So why is it I only get `data.dt` when I copy the path? and not `payload.data.dt`

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [29 October 2020 21:57 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/15 "2020-10-29T21:57:06Z")

</div>

Because i copied it from you example, which was set in msg.payload/

The field is "Time of data calculation"

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 October 2020 21:58 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/16 "2020-10-29T21:58:28Z")

</div>

(That wasn't meant against you. It was a sort of rhetorical question)

I just copied the path and pasted it in the field of the `moment` node.

I'm working on it now.

It doesn't work.

```auto
Input property, msg.payload.data.dt, does NOT exist. Output has been set to NOW.

```

so it is `msg.data.dt`.

Don't worry. I'll keep trying.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [29 October 2020 22:01 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/17 "2020-10-29T22:01:00Z")

</div>

I would of thought that they provide the sunrise for the lat and long location using UTC

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 October 2020 22:02 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/18 "2020-10-29T22:02:59Z")

</div>

Just found it.

`data.dt` is the time of publishing. So it isn't now. It is `23:33:28` (repeatedly.)

So I am still looking for a `now` timestamp in the message - if it exists.  
Otherwise I guess I will have to create one on the message sent.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [29 October 2020 22:19 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/19 "2020-10-29T22:19:53Z")

</div>

The sunrise timestamp is a UTC time stamp. Just return your time in UTC

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 October 2020 23:40 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/20 "2020-10-29T23:40:55Z")

</div>

I think I got it working. Or at least: It seems to be.

Before the node I put a `change` node and set `msg.now` as `timestamp`.

Out of the node I have this:

Example.

```auto
[{"id":"5cdd808a.0d6db8","type":"switch","z":"10fde8b5.a8a82f","name":"","property":"now","propertyType":"msg","rules":[{"t":"lt","v":"payload.sunrise","vt":"msg"},{"t":"gt","v":"payload.sunset","vt":"msg"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":1420,"y":750,"wires":[["c125972d.f52058"],["c125972d.f52058"],["8eb3fc7c.41e288"]]},{"id":"c125972d.f52058","type":"change","z":"10fde8b5.a8a82f","name":"Darksky cloudy (night)","rules":[{"t":"set","p":"payload","pt":"msg","to":"<i class=\"wi-darksky-partly-cloudy-night\"></i>","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1620,"y":730,"wires":[[]]},{"id":"8eb3fc7c.41e288","type":"change","z":"10fde8b5.a8a82f","name":"Darksky cloudy","rules":[{"t":"set","p":"payload","pt":"msg","to":"<i class=\"wi wi-darksky-cloudy\"></i>","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1600,"y":770,"wires":[[]]}]

```

The `switch` node is repeated for all the different _types_ of output so I have a day and night icon used.

Thanks to all who _participated_.  
Sorry folks. As I have said many time: I sometimes need to discuss it with others so I can see things better.

That's not to say the help wasn't useful. It showed me a couple of mistakes I always seem to make.

So, now all is good for now.

(I can paste a bigger version of the code if you want.)  
Or a screen shot.

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [30 October 2020 06:34 UTC](https://discourse.nodered.org/t/help-with-openweathermap-node/35042/21 "2020-10-30T06:34:12Z")

</div>

> [@Trying\_to\_learn](#):
>
> As I have said many time: I sometimes need to discuss it with others so I can see things better.

Maybe you should consider buying [a rubber duck](https://en.wikipedia.org/wiki/Rubber_duck_debugging) (or something similar).

[Next page](https://discourse.nodered.org/t/help-with-openweathermap-node/35042.md?page=2)
