# UK (Met Office) Pollen forecast

**URL:** <https://discourse.nodered.org/t/uk-met-office-pollen-forecast/61507>\
**Category:** Share Your Projects\
**Tags:** node-red-dashboard\
**Created:** [19 April 2022 16:54 UTC](https://discourse.nodered.org/t/uk-met-office-pollen-forecast/61507 "2022-04-19T16:54:04Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [19 April 2022 16:54 UTC](https://discourse.nodered.org/t/uk-met-office-pollen-forecast/61507/1 "2022-04-19T16:54:04Z")

</div>

I have just posted this in the flows section

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/2/92987cd4a1727d7e5a894ecf43949ef4dbde8b45.png)

[https://flows.nodered.org/flow/c14fb7c020a0243a742d987defea85d5](https://flows.nodered.org/flow/c14fb7c020a0243a742d987defea85d5)

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [20 April 2022 20:27 UTC](https://discourse.nodered.org/t/uk-met-office-pollen-forecast/61507/2 "2022-04-20T20:27:49Z")

</div>

Pollen index should be;

```auto
pollen[index] = { day: (dayNames[(new Date().getDay() + index) % 7]), level: msg.payload[index] }

```

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [21 April 2022 00:36 UTC](https://discourse.nodered.org/t/uk-met-office-pollen-forecast/61507/3 "2022-04-21T00:36:17Z")

</div>

I just noticed it was going past the end of the array, and came here to fix it along with a couple of other tweaks hoping nobody would notice 😉

But you beat me to it!

At least I know someone looked at it Thanks 😃

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [22 April 2022 08:46 UTC](https://discourse.nodered.org/t/uk-met-office-pollen-forecast/61507/4 "2022-04-22T08:46:25Z")

</div>

On the pollen type branch of the flow you have a switch: msg.payload has key "length".

Can you explain what this is intended to filter out? For me it blocks the valid list of pollen types.

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [22 April 2022 15:10 UTC](https://discourse.nodered.org/t/uk-met-office-pollen-forecast/61507/5 "2022-04-22T15:10:59Z")

</div>

Sometimes there is no data for this, in that case the string nodes output an object like this -

**payload: object**

**s: ""**  
**orig: ""**  
**length: 0**

Since I didn't want this to display I added the switch node setup like this

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/4/b439433768b8ed6db8a04b3d46efafd084f5092c.png)

However this passes every message to output 1 even without that key. I don't understand what I'm doing wrong here with the has key option ?

Any ideas why this doesn't work as I expected ?

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [22 April 2022 15:14 UTC](https://discourse.nodered.org/t/uk-met-office-pollen-forecast/61507/6 "2022-04-22T15:14:18Z")

</div>

I have changed the logic to test for length value of 0 so it works now, but would still like to know why switch setup above didn't work ?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [22 April 2022 15:52 UTC](https://discourse.nodered.org/t/uk-met-office-pollen-forecast/61507/7 "2022-04-22T15:52:44Z")

</div>

Thnks for sharing this.

Yes it's a puzzle. I have not seen an invalid payload so far but this is a valid one at this stage in the flow: "Tree pollen currently includes ash, oak, plane and birch. Spores: Pleospora."  
And that does, apparently, have a key "length" !

I don't think your usage instructions are quite right:

> Visit the web site and select your region, note the region code in the address and modify the inject node and pollen type html node to match.

Since the HTTP Request node ignores msg.payload, the region code in inject is irrelevant. We have to change the code in both Pollen type and Level HTML nodes.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [22 April 2022 16:06 UTC](https://discourse.nodered.org/t/uk-met-office-pollen-forecast/61507/8 "2022-04-22T16:06:49Z")

</div>

I've put the region code ( as suggested by @jbudd ) in the HTML nodes... Pollen type and Level and the flow works fine now - it gives the same results (icons) as the Met Office website.

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [22 April 2022 16:43 UTC](https://discourse.nodered.org/t/uk-met-office-pollen-forecast/61507/9 "2022-04-22T16:43:09Z")

</div>

I will have a think about how I can make that a bit easier then 😉

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [22 April 2022 23:00 UTC](https://discourse.nodered.org/t/uk-met-office-pollen-forecast/61507/10 "2022-04-22T23:00:29Z")

</div>

OK updated due to popular request 😉

Region is now just added into the inject node.

---

<div class="post-metadata">

**Author:** ![Patrick\_UK](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Patrick\_UK](https://discourse.nodered.org/u/Patrick_UK)\
**Post date:** [26 April 2022 07:43 UTC](https://discourse.nodered.org/t/uk-met-office-pollen-forecast/61507/11 "2022-04-26T07:43:15Z")

</div>

Thanks for sharing, nice little addition to my daily forecast notification 🙂

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [26 April 2022 23:14 UTC](https://discourse.nodered.org/t/uk-met-office-pollen-forecast/61507/12 "2022-04-26T23:14:25Z")

</div>

Glad it is of interest - be sure to rate in the flows section 🤣

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [7 June 2022 02:29 UTC](https://discourse.nodered.org/t/uk-met-office-pollen-forecast/61507/13 "2022-06-07T02:29:52Z")

</div>

This has been updated to include the VH pollen level 😉
