# Weather variables - polling state node

**URL:** https://discourse.nodered.org/t/weather-variables-polling-state-node/14978
**Category:** General
**Created:** [31 August 2019 15:57 UTC](https://discourse.nodered.org/t/weather-variables-polling-state-node/14978 "2019-08-31T15:57:03Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![kitus](https://avatars.discourse-cdn.com/v4/letter/k/71c47a/32.png) [@kitus](https://discourse.nodered.org/u/kitus)
#### Post date: [31 August 2019 15:57 UTC](https://discourse.nodered.org/t/weather-variables-polling-state-node/14978/1 "2019-08-31T15:57:03Z")

</div>

Hello everyone,

I’m trying to refine my first automations with nodered. I am very new to NR ☹

My automations start with some weather variable meeting a certain condition (rain, wind). I initially thought that a state node would help me read and trigger off my flow but with no success. I then tried the poll state node and my automations did start to do things. This is very much how all of them are configured right now.

One of my automations is “untold the awning” and I would like for that to happen when sun azimuth reaches a certain value and, of course, it is not raining. I also have another automation doing the oposite: if it starts to rain or if the wind picks up, I want for my awning to be rolled back. And of course I don’t want to end up making a fool of myself having the awning unfolded yet the next minute rolled back, that’s why the first automation should only be triggered when the sun azimuth reaches a specific value and not \>=, which is how I have it configured right now. If I change the \>= to a more restrictive = (or IS), the condition is not met and my awning remains open ☹

I’m under the impression that the automation is not triggered because the variable I’m monitoring may never be the exact value I’ve defined as a triggering condition. I have a sensor defined on the azimuth and I’m plotting the values that I see and I believe the discrete value is somehow missed.

Not sure if I’m explaining myself well enough. Of course I could paste my configuration later on (now I’m on my mobile phone).

Thanks,

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [31 August 2019 16:27 UTC](https://discourse.nodered.org/t/weather-variables-polling-state-node/14978/2 "2019-08-31T16:27:18Z")

</div>

For something like sun position, it easy to calculate, there a couple of nodes that will do it for you based on a lat long.

It might be easier to start with one of them, go to [flows.nodered.org](http://flows.nodered.org) and do a search for “sun”

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [31 August 2019 16:38 UTC](https://discourse.nodered.org/t/weather-variables-polling-state-node/14978/3 "2019-08-31T16:38:23Z")

</div>

> [@kitus](#):
>
> I’m under the impression that the automation is not triggered because the variable I’m monitoring may never be the exact value I’ve defined as a triggering condition.

What test have you used and in what node?

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [31 August 2019 16:55 UTC](https://discourse.nodered.org/t/weather-variables-polling-state-node/14978/4 "2019-08-31T16:55:04Z")

</div>

This is a quite sophisticated node available to handle most of your requirements.

> **[node-red-contrib-blindcontroller](https://flows.nodered.org/node/node-red-contrib-blindcontroller)**
>
> A collection of Node-RED nodes that can be used to automate the control of household roller blinds based on the current position of the sun.

---

<div class="post-metadata">

### Author: ![kitus](https://avatars.discourse-cdn.com/v4/letter/k/71c47a/32.png) [@kitus](https://discourse.nodered.org/u/kitus)
#### Post date: [31 August 2019 20:32 UTC](https://discourse.nodered.org/t/weather-variables-polling-state-node/14978/5 "2019-08-31T20:32:57Z")

</div>

Hi!! This looks very cool, although it does not address 2 important aspects that are crucial for my awning:

1. Wind
2. Rain

I love how it monitors the sun to decide the blind position and that is something that I will definitely use (just need to figure out how it works). Do you happen to use this component?

On another note, I still would love to understand how to handle the variable monitoring for polling state nodes. If anybody can help me with that, I would be very thankful.

Many thanks!

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [31 August 2019 20:40 UTC](https://discourse.nodered.org/t/weather-variables-polling-state-node/14978/6 "2019-08-31T20:40:21Z")

</div>

I am not using it, I use the time-range node which also uses sun-position, but I do use wind and rain variables.

I have a function node that performs the checks: if wind \> 20m/s or rain then set a variable "allowed": no, if rain then allowed:no,else allowed:yes. Then I have a lux sensor in combination with the time-range node, if lux\>2750, in the time-range and allowed, then awning down. Connected to a trigger node which is set to 10 minutes (which is 2x the lux sensor reading cycle) and this could be either triggered or reset.

---

<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: [31 August 2019 20:44 UTC](https://discourse.nodered.org/t/weather-variables-polling-state-node/14978/7 "2019-08-31T20:44:27Z")

</div>

> [@kitus](#):
>
> I’m under the impression that the automation is not triggered because the variable I’m monitoring may never be the exact value I’ve defined as a triggering condition

Could you use a switch node to only output if the variable is between two values, or greater/less than a preset value?

![switch](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/251cd3bfec7dbc82ed0557ea328dcf1b2476c38a.jpeg)

---

<div class="post-metadata">

### Author: ![kitus](https://avatars.discourse-cdn.com/v4/letter/k/71c47a/32.png) [@kitus](https://discourse.nodered.org/u/kitus)
#### Post date: [31 August 2019 21:42 UTC](https://discourse.nodered.org/t/weather-variables-polling-state-node/14978/8 "2019-08-31T21:42:38Z")

</div>

Hello,

this is the node that I use to monitor the azimuth value. I would like to say “is” 150 instead of “\>=“ because of what I explained earlier. If I configure the node with “is”, in my experience I never manage to trigger the automation itself. I’ve tried with numbers and strings, to no avail.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/741e61fd6276736d0cb81b0e37ee1210fc24f2d4.png)

Thanks,

---

<div class="post-metadata">

### Author: ![kitus](https://avatars.discourse-cdn.com/v4/letter/k/71c47a/32.png) [@kitus](https://discourse.nodered.org/u/kitus)
#### Post date: [31 August 2019 21:44 UTC](https://discourse.nodered.org/t/weather-variables-polling-state-node/14978/9 "2019-08-31T21:44:06Z")

</div>

Hi @Paul-Reed,

That could very well be a solution, yes!! I will try that out tomorrow!!

Thanks!! 🙂

---

<div class="post-metadata">

### Author: ![kitus](https://avatars.discourse-cdn.com/v4/letter/k/71c47a/32.png) [@kitus](https://discourse.nodered.org/u/kitus)
#### Post date: [31 August 2019 21:45 UTC](https://discourse.nodered.org/t/weather-variables-polling-state-node/14978/10 "2019-08-31T21:45:40Z")

</div>

Cool. Thanks for answering back. Any chance you could share your flow here?

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [31 August 2019 22:11 UTC](https://discourse.nodered.org/t/weather-variables-polling-state-node/14978/11 "2019-08-31T22:11:13Z")

</div>

That demo also sets the value as a string (see the AZ) so you also need to check to see what the node before is sending.

Is is a string or a number?  
(if it was true or false there’s also boolean)

You can check this using the debug node, the page i the docs entitled “working with messages” is also well worth a read

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [31 August 2019 22:18 UTC](https://discourse.nodered.org/t/weather-variables-polling-state-node/14978/12 "2019-08-31T22:18:53Z")

</div>

Cannot really extract the flow, using different types of nodes and api's to gather data.

This is the basic gist of it:

```auto
[{"id":"e2aa459c.3118c","type":"inject","z":"500a30d2.4c843","name":"wind 6 m/s","topic":"","payload":"6","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":224,"wires":[["8a68a483.ab23f8"]]},{"id":"2ac65508.a1bbfa","type":"inject","z":"500a30d2.4c843","name":"rain 0 mm","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":280,"wires":[["fe3f58f6.6ddcf8"]]},{"id":"fe3f58f6.6ddcf8","type":"change","z":"500a30d2.4c843","name":"","rules":[{"t":"set","p":"rain","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":406,"y":280,"wires":[[]]},{"id":"8a68a483.ab23f8","type":"change","z":"500a30d2.4c843","name":"","rules":[{"t":"set","p":"wind","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":406,"y":224,"wires":[[]]},{"id":"82cf00f1.f167b","type":"inject","z":"500a30d2.4c843","name":"down","topic":"","payload":"down","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":392,"wires":[["2ac0341c.65b49c"]]},{"id":"2ac0341c.65b49c","type":"switch","z":"500a30d2.4c843","name":"rain ?","property":"rain","propertyType":"flow","rules":[{"t":"gt","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":392,"wires":[["8adcd7f9.71cb"],["4a764458.9111a4"]]},{"id":"4a764458.9111a4","type":"switch","z":"500a30d2.4c843","name":"wind > 18m/s ?","property":"wind","propertyType":"flow","rules":[{"t":"gte","v":"18","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":500,"y":420,"wires":[["8adcd7f9.71cb"],["eafad8fa.6416e8"]]},{"id":"eafad8fa.6416e8","type":"trigger","z":"500a30d2.4c843","op1":"","op2":"up","op1type":"pay","op2type":"str","duration":"10","extend":true,"units":"min","reset":"","bytopic":"all","name":"","x":714,"y":420,"wires":[["4c6ab8a0.c1e16"]]},{"id":"4c6ab8a0.c1e16","type":"debug","z":"500a30d2.4c843","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":910,"y":392,"wires":[]},{"id":"8adcd7f9.71cb","type":"change","z":"500a30d2.4c843","name":"up","rules":[{"t":"set","p":"payload","pt":"msg","to":"up","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":694,"y":364,"wires":[["4c6ab8a0.c1e16"]]}]

```

---

<div class="post-metadata">

### Author: ![kitus](https://avatars.discourse-cdn.com/v4/letter/k/71c47a/32.png) [@kitus](https://discourse.nodered.org/u/kitus)
#### Post date: [1 September 2019 07:56 UTC](https://discourse.nodered.org/t/weather-variables-polling-state-node/14978/13 "2019-09-01T07:56:19Z")

</div>

it is a string

 ![06](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/28d15c00a90adce5bc3624c032ef79b7724d5212.png)

On my suspicion above, check the following two snapshots:

![36](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f93fa57a8b486bdd3ed62a3177b80a94db7fbca2.png)

so it literally never is 150.00 but either 149.98 or 151.53. In other words, Noder Red "never sees the sun azimuth crossing the 150.00 mark", it is either below or above.

I'm going to try Paul's suggestion for a spin today and report back later on.

---

<div class="post-metadata">

### Author: ![kitus](https://avatars.discourse-cdn.com/v4/letter/k/71c47a/32.png) [@kitus](https://discourse.nodered.org/u/kitus)
#### Post date: [1 September 2019 07:57 UTC](https://discourse.nodered.org/t/weather-variables-polling-state-node/14978/14 "2019-09-01T07:57:43Z")

</div>

As a new user I can't seem to be allowed to add more than 2 images. This additional one goes hand in hand with the second one above.  
 ![02](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/58e4a0d63d2be540aef84a1ed54d12b7e249c277.png)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [1 September 2019 16:15 UTC](https://discourse.nodered.org/t/weather-variables-polling-state-node/14978/15 "2019-09-01T16:15:59Z")

</div>

Can you explain why you can't test for \>= again. I can't see above where you have explained that. The value will only be exactly 150 for an infinitesimally small time (well in practice, with floating point numbers, not quite infinitesimally small) so the chance of hitting it exactly is very small.
