Setting and triggering variables

With change node, it is possible to save messages that are coming out of the nodes and reuse them.

Use of variable

The context object - stores data inside a single node,

The flow object - stores data for a sing flow tab,

The global object - stores data for the whole logic.

This article will cover knowledge about flow and global objects.

A node used to set the message as a variable is a change node.

It can both, set a flow.variable to msg.payload (1) and
set a msg.payload to flow.variable (2).

(1) To set a variable flow.var_01 as a value of msg.payload:

The value of the variable (var_01) will be overwritten and the value of the original message will be passed on without modification.

For example, if the message with the value “100” will come into a node, it will be saved as a value of a variable.

(2) To change the incoming message into a variable, the “Set” rule has to be used in the other way

Now the output of the change node will be the value which is stored as a variable (var_01).
Every incoming message will be changed into a value of a variable.

Checking the value of variables

The value of the flow is shown in the “context” tab.

[{"id":"406a3ac6.1ce274","type":"change","z":"cbbad29d.a61b88","name":"","rules":[{"t":"set","p":"var_01","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":1140,"wires":[["7c2d8de3.4ff474"]]},{"id":"34653ef5.68f36a","type":"inject","z":"cbbad29d.a61b88","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":530,"y":1120,"wires":[["406a3ac6.1ce274"]]},{"id":"7c2d8de3.4ff474","type":"debug","z":"cbbad29d.a61b88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1030,"y":1140,"wires":[]},{"id":"1860d79d.53c378","type":"inject","z":"cbbad29d.a61b88","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"100","payloadType":"num","x":530,"y":1180,"wires":[["406a3ac6.1ce274"]]}]

Any variable name can be set, the important thing is that the flow creator is aware of what it is used for. Variable name has to be distinguish for a specific usage.

Use cases

HCL

In logic when the presence detection has to trigger a value from the Intensity Scheduler (ES_CCT node).

https://glamox.atlassian.net/l/cp/djTKua8c

Daylight harvesting blocker

Turning ON daylight harvesting at a scheduled time.

 

 

[{"id":"5c7bcadb.64ccf4","type":"light-scheduler","z":"28129e44.b4e00e","settings":"994a1915.7cbd08","events":"[{\"start\":{\"dow\":2,\"mod\":570},\"end\":{\"dow\":2,\"mod\":1020}},{\"start\":{\"dow\":1,\"mod\":570},\"end\":{\"dow\":1,\"mod\":1020}},{\"start\":{\"dow\":3,\"mod\":570},\"end\":{\"dow\":3,\"mod\":1020}},{\"start\":{\"dow\":5,\"mod\":570},\"end\":{\"dow\":5,\"mod\":1020}},{\"start\":{\"dow\":6,\"mod\":570},\"end\":{\"dow\":6,\"mod\":1020}},{\"start\":{\"dow\":0,\"mod\":570},\"end\":{\"dow\":0,\"mod\":1020}},{\"start\":{\"dow\":4,\"mod\":570},\"end\":{\"dow\":4,\"mod\":1020}}]","topic":"","name":"Activate Daylight from 9:30 to 17:00","onPayload":"true","onPayloadType":"bool","offPayload":"false","offPayloadType":"bool","onlyWhenDark":false,"scheduleRndMax":"","sunElevationThreshold":6,"sunShowElevationInStatus":false,"outputfreq":"output.statechange.startup","x":680,"y":880,"wires":[["d87ab1ab.75b18"]]},{"id":"c1614fc9.eb24b","type":"inject","z":"28129e44.b4e00e","name":"enable","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"true","payloadType":"bool","x":900,"y":840,"wires":[["d87ab1ab.75b18"]]},{"id":"ccbceea3.7f8d2","type":"inject","z":"28129e44.b4e00e","name":"disable","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"","topic":"","payload":"false","payloadType":"bool","x":910.1874351501465,"y":917.9999599456787,"wires":[["d87ab1ab.75b18"]]},{"id":"d87ab1ab.75b18","type":"change","z":"28129e44.b4e00e","name":"Daylight Blocker","rules":[{"t":"set","p":"daylight","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1134,"y":876,"wires":[[]]},{"id":"8e822734.fa62a8","type":"comment","z":"28129e44.b4e00e","name":"Daylight Harvesting ","info":"in this node the taget for 70 % and 60% is set in the message payload\n\n\n\n{ \"target\": 270, \"tolerance\": 3 } ","x":630,"y":820,"wires":[]},{"id":"f84e2d5d.74d3","type":"switch","z":"28129e44.b4e00e","name":"Daylight is true","property":"daylight","propertyType":"global","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":1520,"y":1040,"wires":[["606ebce8.a71c64"]]},{"id":"7c42da15.a19364","type":"vertex action","z":"28129e44.b4e00e","name":"Zone 1","typeButton":"directv","bPayload":{"action":"setbrightnesslog","group":null,"param":0,"priority":"254"},"bState":false,"defaultpriority":true,"x":1330,"y":1040,"wires":[["f84e2d5d.74d3"]]},{"id":"764e41e5.0f9b2","type":"change","z":"28129e44.b4e00e","name":"Send 10% (170)","rules":[{"t":"set","p":"payload","pt":"msg","to":"170","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1100,"y":1060,"wires":[["7c42da15.a19364"]]},{"id":"e15bf3d6.cd7e8","type":"switch","z":"28129e44.b4e00e","name":"If below 10% (170)","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"170","vt":"num"},{"t":"lt","v":"170","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":1110,"y":1020,"wires":[["7c42da15.a19364"],["764e41e5.0f9b2"]]},{"id":"59bf400d.47056","type":"dali2devs","z":"28129e44.b4e00e","name":"S1 - Light","uid":"CEFF083F00790400","dali2dev":"1","instanceType":4,"dali2t1":"900","dali2t2":"30","mode":"","x":600,"y":1040,"wires":[["1880cc3c.586674"]]},{"id":"606ebce8.a71c64","type":"vertex cluster","z":"28129e44.b4e00e","rate":90,"x":1760,"y":1040,"wires":[]},{"id":"1880cc3c.586674","type":"vertex daylightHarvesting","z":"28129e44.b4e00e","name":"Daylight Harvesting","primarygroup":"","target":"500","tolerance":15,"P":0.25,"I":0.03,"D":0,"min":0,"max":100,"x":850,"y":1040,"wires":[["e15bf3d6.cd7e8"]]},{"id":"994a1915.7cbd08","type":"light-scheduler-settings","name":"aalborg","latitude":"57.02515165179153","longitude":"9.9455264189402"}]