# Can NR be set to trigger on changes in global scope context values?

**URL:** <https://discourse.nodered.org/t/can-nr-be-set-to-trigger-on-changes-in-global-scope-context-values/33826>\
**Category:** General\
**Created:** [6 October 2020 10:25 UTC](https://discourse.nodered.org/t/can-nr-be-set-to-trigger-on-changes-in-global-scope-context-values/33826 "2020-10-06T10:25:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Boja](https://avatars.discourse-cdn.com/v4/letter/b/3be4f8/32.png) [@Boja](https://discourse.nodered.org/u/Boja)\
**Post date:** [6 October 2020 10:25 UTC](https://discourse.nodered.org/t/can-nr-be-set-to-trigger-on-changes-in-global-scope-context-values/33826/1 "2020-10-06T10:25:03Z")

</div>

A State Node triggers when state changes on the referenced Entity.

Can a state change on a Global context variable, be set to trigger something in a similar way ?

Hassio running on a Raspberry Pi.

/Boja

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [6 October 2020 10:38 UTC](https://discourse.nodered.org/t/can-nr-be-set-to-trigger-on-changes-in-global-scope-context-values/33826/2 "2020-10-06T10:38:39Z")

</div>

Have you tried it? Did you run into an issue? What node are you referencing? (full name please)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [6 October 2020 10:44 UTC](https://discourse.nodered.org/t/can-nr-be-set-to-trigger-on-changes-in-global-scope-context-values/33826/3 "2020-10-06T10:44:47Z")

</div>

Hi @Boja

no, it is not possible to trigger an event when a context value changes.

---

<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:** [6 October 2020 10:59 UTC](https://discourse.nodered.org/t/can-nr-be-set-to-trigger-on-changes-in-global-scope-context-values/33826/4 "2020-10-06T10:59:08Z")

</div>

Are you using MQTT? If so then rather than using a context variable use mqtt, then when a new value appears you will receive a message.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [6 October 2020 11:03 UTC](https://discourse.nodered.org/t/can-nr-be-set-to-trigger-on-changes-in-global-scope-context-values/33826/5 "2020-10-06T11:03:09Z")

</div>

could you use the `watch` node to watch the .node-red/context/ flow or global json file? of course if you have more than one variable you would have to read it and test it against a saved copy of the value

---

<div class="post-metadata">

**Author:** ![Boja](https://avatars.discourse-cdn.com/v4/letter/b/3be4f8/32.png) [@Boja](https://discourse.nodered.org/u/Boja)\
**Post date:** [7 October 2020 13:17 UTC](https://discourse.nodered.org/t/can-nr-be-set-to-trigger-on-changes-in-global-scope-context-values/33826/6 "2020-10-07T13:17:13Z")

</div>

No. Currently I handle changes by use of an input\_number that is updated by all function nodes, whenever they change something in the setup, and have added a server-state-change node that sends messages to all effected Nodes. In relatively simple setups, I of couse just let functions send messages directly to affected nodes.

Not very elegant maybe, but I just needed to know if a different mechanism was available.

Being able to get data out of "node-red/context/ flow or global json file" as you mentioned zenofmud is completely new to me, but sounds like something I have to look at.

Thanks to all for the info.

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [8 October 2020 04:51 UTC](https://discourse.nodered.org/t/can-nr-be-set-to-trigger-on-changes-in-global-scope-context-values/33826/7 "2020-10-08T04:51:31Z")

</div>

Why not a loop that checks the given variable or whatever and if has changed since last poll? You would just need to keep the previous valve or do some type of check sum of the variable value to know when it has changed on each poll.

Calculating crc32 for example is fast and easy, and would catch just any valve change.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 December 2020 04:51 UTC](https://discourse.nodered.org/t/can-nr-be-set-to-trigger-on-changes-in-global-scope-context-values/33826/8 "2020-12-07T04:51:32Z")

</div>

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