Alarm on graphical dashboard

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.

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

Thanks for your time.

Flow:
flows.json (33.9 KB)

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

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

1 Like

Sorry for that.

FLOW:

[{"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}]

Julio,

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

1 Like

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).

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).

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)

1 Like

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.

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.

1 Like

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:

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

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’

1 Like

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