# Alarm on graphical dashboard

**URL:** <https://discourse.nodered.org/t/alarm-on-graphical-dashboard/44643>\
**Category:** General\
**Created:** [24 April 2021 05:42 UTC](https://discourse.nodered.org/t/alarm-on-graphical-dashboard/44643 "2021-04-24T05:42:55Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrokenBeat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brokenbeat/32/40023_2.png) [@BrokenBeat](https://discourse.nodered.org/u/BrokenBeat)\
**Post date:** [24 April 2021 05:42 UTC](https://discourse.nodered.org/t/alarm-on-graphical-dashboard/44643/1 "2021-04-24T05:42:56Z")

</div>

I am working with a flow that graphs the stability of an Electric Generator, with the help of a dashboard chart.

I need to develop an alarm according to the coordinates of a point, that is, when a limit passes a red LED lights up to indicate that it is not stable and green when it is.

The XY coordinate that I am evaluating is given by P - Q, where P is the X coordinate and Q is the Y coordinate. P - Q are data already processed in the flow previously, that is, if I change the test data, PQ changes, but that it does not matter since we can give values to P and Q to see if the alarm works.

I already developed a function node where I put an "if" as the limit of the coordinates but it doesn't work properly.

 ![point](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/a/aaa564bc7af7f866c94c5c93a9d3a9d79968ba02.png)

I hope someone can help me make the node condition work well so that it turns red when the limit passes and green if it is not at the limit.

Thanks for your time

 ![Limite](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/af7d6c346d6dbca8b0bb8b99e1eef3d9e9569e23.png)

Thanks for your time.

Flow:  
[flows.json](https://discourse.nodered.org/uploads/short-url/j030gB2tlisFxkUL7fGonpPf6wr.json) (33.9 KB)

I attach the flow here, because it did not let me paste the code due to character limits.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [24 April 2021 06:21 UTC](https://discourse.nodered.org/t/alarm-on-graphical-dashboard/44643/2 "2021-04-24T06:21:18Z")

</div>

Try to reduce or make a smaller flow that is demonstrating your problem. Then share that flow

---

<div class="post-metadata">

**Author:** ![BrokenBeat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brokenbeat/32/40023_2.png) [@BrokenBeat](https://discourse.nodered.org/u/BrokenBeat)\
**Post date:** [24 April 2021 07:43 UTC](https://discourse.nodered.org/t/alarm-on-graphical-dashboard/44643/3 "2021-04-24T07:43:00Z")

</div>

Sorry for that.

FLOW:

```auto
[{"id":"88f2a7e0.cec9c8","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"838d1982.dff8b8","type":"function","z":"88f2a7e0.cec9c8","name":"Limits & Point","func":"var P = flow.get(\"P\");\nvar Q = flow.get(\"Q\");\nvar chart = [{\n \"series\":[\"Lim.Estator\",\"Lim.Rotor\",\"Lim.Ext.Estator\",\"G40\",\"Punto de operación\"],\n \n\"data\":[[{\"x\":182,\"y\":88},{\"x\":196,\"y\":50},{\"x\":202,\"y\":0},{\"x\":200,\"y\":-30},{\"x\":193,\"y\":-64}],[{\"x\":182,\"y\":88},{\"x\":146,\"y\":109},{\"x\":95,\"y\":130},{\"x\":50,\"y\":140},{\"x\":0,\"y\":144}],[{\"x\":193,\"y\":-64},{\"x\":150,\"y\":-86},{\"x\":90,\"y\":-101},{\"x\":30,\"y\":-100},{\"x\":0,\"y\":-98}],[{\"x\":0,\"y\":-85.31},{\"x\":195,\"y\":-55}],[{\"x\":P-2,\"y\":Q},{\"x\":P,\"y\":Q},{\"x\":P+2,\"y\":Q},{\"x\":P,\"y\":Q-3},{\"x\":P,\"y\":Q+3}]],\n \"labels\":[\"MW\"]\n}];\nmsg.payload = chart;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":420,"y":260,"wires":[["a55fbb5c.9aa188"]]},{"id":"a55fbb5c.9aa188","type":"ui_chart","z":"88f2a7e0.cec9c8","name":"","group":"8414e8d0.af4c08","order":4,"width":15,"height":15,"label":"CAPABILIDAD","chartType":"line","legend":"true","xformat":"x","interpolate":"bezier","nodata":"Online","dot":true,"ymin":"","ymax":"","removeOlder":"1","removeOlderPoints":"10000","removeOlderUnit":"604800","cutout":0,"useOneColor":false,"useUTC":true,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":620,"y":260,"wires":[[]]},{"id":"bcbfa335.1d65b","type":"inject","z":"88f2a7e0.cec9c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"0.1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":260,"wires":[["838d1982.dff8b8","4c72b287.737c0c"]]},{"id":"835e9f35.f9b86","type":"ui_led","z":"88f2a7e0.cec9c8","order":1,"group":"8414e8d0.af4c08","width":2,"height":2,"label":"Alarma","labelPlacement":"right","labelAlignment":"center","colorForValue":[{"color":"#ff0000","value":"true","valueType":"bool"},{"color":"#008000","value":"false","valueType":"bool"}],"allowColorForValueInMessage":false,"shape":"square","showGlow":true,"name":"Alarma","x":596,"y":320,"wires":[]},{"id":"4c72b287.737c0c","type":"function","z":"88f2a7e0.cec9c8","name":"Alarm","func":"var P = 158.022\nflow.set(\"P\", P);\nvar Q = 91.234\nflow.set(\"Q\", Q);\n\nif (Q>-85.31 || Q<-55 && P>=0 || P<195)\n {\n var alarma = true\n flow.set(\"alarma\", alarma);\n msg.payload = flow.get(\"alarma\");\n msg.topic = \"alarma\";\n return msg;\n }\n \n else \n\n{\n msg.payload = false\n return msg;\n}\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":390,"y":320,"wires":[["835e9f35.f9b86","ba8c6cf5.60399"]]},{"id":"ba8c6cf5.60399","type":"debug","z":"88f2a7e0.cec9c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":590,"y":360,"wires":[]},{"id":"8414e8d0.af4c08","type":"ui_group","name":"Group 1","tab":"9323362a.3b4338","order":1,"disp":true,"width":15,"collapse":false},{"id":"9323362a.3b4338","type":"ui_tab","name":"Tab 3","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

```

---

<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:** [24 April 2021 08:06 UTC](https://discourse.nodered.org/t/alarm-on-graphical-dashboard/44643/4 "2021-04-24T08:06:30Z")

</div>

Julio,

Can you write out an explanation of what the `if` statement is suppose to do.

---

<div class="post-metadata">

**Author:** ![BrokenBeat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brokenbeat/32/40023_2.png) [@BrokenBeat](https://discourse.nodered.org/u/BrokenBeat)\
**Post date:** [24 April 2021 08:17 UTC](https://discourse.nodered.org/t/alarm-on-graphical-dashboard/44643/5 "2021-04-24T08:17:05Z")

</div>

In the graph I have 4 lines of different colors, they are my limits, I also have an operation point (I enclose it in green in the photo).

 ![Limite](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/af7d6c346d6dbca8b0bb8b99e1eef3d9e9569e23.png)

It is assumed that with the If condition it evaluates my operating point (PQ), if my point is below the green line then the alarm will be activated (in the photo I indicate the two points, their coordinates and the alarm limit zone is scratched) .

the problem is that the if condition that it performs, activates the led without it being in the alarm zone. (active alarm = red color, deactivated alarm = green color).

---

<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:** [24 April 2021 08:23 UTC](https://discourse.nodered.org/t/alarm-on-graphical-dashboard/44643/6 "2021-04-24T08:23:07Z")

</div>

What I want you to do is put in words what the actual `if` statement does, like this  
`if (animal = ‘cat’)`  
“If the animal is a cat then do x”

I’m trying to get you to explain the if statement in words  
`if (Q>-85.31 || Q<-55 && P>=0 || P<195)`

---

<div class="post-metadata">

**Author:** ![BrokenBeat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brokenbeat/32/40023_2.png) [@BrokenBeat](https://discourse.nodered.org/u/BrokenBeat)\
**Post date:** [24 April 2021 08:35 UTC](https://discourse.nodered.org/t/alarm-on-graphical-dashboard/44643/7 "2021-04-24T08:35:59Z")

</div>

> if (Q\>-85.31 || Q\<-55 && P\>=0 || P\<195)

I placed the condition that way because it was my "reasonable" way of using the range that I need for the alarm, using the two coordinates (the two points) that make up my green color limit, in a few words I don't know how to place the range I need alarm (the area striped with red in the photo).

my operating point is made up of P-Q:  
P corresponds to my X axis  
Q corresponds to my Y axis

my alarm limit is made up of:  
point 1 = (X = 0, Y = -85.31)  
point 2 = (X = 195, Y = -55)  
Below that line my alarm begins, so for me it was feasible to put those coordinates as the alarm range, but it does not work, I do not know how to place the range I need in a condition.

I placed || and && because according to me it is my way of making a range, if P is greater than 0 or less than 195 BUT that also Q is below the limit line.

---

<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:** [24 April 2021 08:57 UTC](https://discourse.nodered.org/t/alarm-on-graphical-dashboard/44643/8 "2021-04-24T08:57:06Z")

</div>

> [@BrokenBeat](#):
>
> if (Q\>-85.31 || Q\<-55 && P\>=0 || P\<195)

Because you do not use parentheses to group the conditions, the result should be this:  
If ( (Q \> -85.31 || Q \< -55) && ( P \>= 0 || P \< 190) )  
So if  
Q is greater than -85.31 or less than -55  
AND  
P is greater than or equal to 0 or less than 190  
Then the the condition passes

Since you set P to 158.022 at the start of the function, P is greater than 0 and less than 190 so it will always evaluate to the true condition.

---

<div class="post-metadata">

**Author:** ![BrokenBeat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brokenbeat/32/40023_2.png) [@BrokenBeat](https://discourse.nodered.org/u/BrokenBeat)\
**Post date:** [24 April 2021 09:06 UTC](https://discourse.nodered.org/t/alarm-on-graphical-dashboard/44643/9 "2021-04-24T09:06:30Z")

</div>

But that is a problem because P will always be greater than 0 and less than 195, therefore the alarm will always be active, therefore it is incorrect.

Even so, it is also a problem to say that if Q \<-55 or \> -85.31 because the alarm will be activated in this zone:

 ![fail](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/e/be617adf515c14029239376855706cc5a3fe9dd0.png)

And it's not what I need, I really don't know how to set the range with the correct condition.

---

<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:** [24 April 2021 09:10 UTC](https://discourse.nodered.org/t/alarm-on-graphical-dashboard/44643/10 "2021-04-24T09:10:00Z")

</div>

What you need to do is lookup and understand how to determine if a point is below the slope of a line. There are lots or resources on the internet and videos on YouTube that you should look at. I seem to remember this from math classes that I took many, many, many years ago.

You will need to do some homework to figure out the equation to use.

Try using “how to determine is a point is below the slope of a line’

---

<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:** [23 June 2021 09:10 UTC](https://discourse.nodered.org/t/alarm-on-graphical-dashboard/44643/11 "2021-06-23T09:10:36Z")

</div>

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