Applies to: Node-RED for SNAP PAC; Node-RED for groov.

Although you’d typically use PAC Control to perform a task like this, this example demonstrates how to use a switch node to perform an action based on conditions.

It’s also fun to try this example, because you can watch the results via live streaming video. (Click here for the link.)

Conditions Flow

In this flow:

This flow reads and writes to points in a strategy running on a demo Opto 22 SNAP-PAC-R1 controller.

Flow 1 Flow 2

Flow 3

Steps

  1. Open a browser to https://restful.groov.com/#15 so you can see the lamp.

    Login credentials are:

    Username: rest

    Password: rest

    Lamp in the Opto 22 headquarters in Temecula, California USA

  2. In the Node-RED editor, import this flow:

    
    [{"id":"9329284a.a945d8","type":"inject","z":"c8afbdc3.53484","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":126,"y":46,"wires":[["17a8e46d.63d23c"]]},{"id":"17a8e46d.63d23c","type":"pac-read","z":"c8afbdc3.53484","device":"2835e976.d07ea6","dataType":"ana-input","tagName":"Lamp_Temperature","tableStartIndex":"","tableLength":"","value":"","valueType":"msg.payload","topic":"","topicType":"none","name":"read lamp temp","x":130,"y":104.44442749023438,"wires":[["e37cb7c7.144868"]]},{"id":"590532aa.7acabc","type":"pac-write","z":"c8afbdc3.53484","device":"2835e976.d07ea6","dataType":"dig-output","tagName":"Lamp_output","tableStartIndex":"","value":"TRUE","valueType":"value","name":"Turn lamp ON","x":767.22216796875,"y":214.7777099609375,"wires":[[]]},{"id":"77cd5c72.e9c954","type":"pac-write","z":"c8afbdc3.53484","device":"2835e976.d07ea6","dataType":"dig-output","tagName":"Lamp_output","tableStartIndex":"","value":"FALSE","valueType":"value","name":"Turn lamp OFF","x":766.444580078125,"y":140.77780151367188,"wires":[[]]},{"id":"39d3a7c5.040c88","type":"pac-read","z":"c8afbdc3.53484","device":"2835e976.d07ea6","dataType":"dig-output","tagName":"Lamp_output","tableStartIndex":"","tableLength":"","value":"","valueType":"msg.payload","topic":"","topicType":"none","name":"(> 90) read lamp status","x":360.99993896484375,"y":140.77777099609375,"wires":[["a140480c.114488"]]},{"id":"e37cb7c7.144868","type":"switch","z":"c8afbdc3.53484","name":" > 90 or < 85 ?","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"90","vt":"num"},{"t":"lt","v":"85","vt":"num"}],"checkall":"true","outputs":2,"x":131.11111450195312,"y":177.33335876464844,"wires":[["39d3a7c5.040c88"],["5e776e8f.c906a"]]},{"id":"5e776e8f.c906a","type":"pac-read","z":"c8afbdc3.53484","device":"2835e976.d07ea6","dataType":"dig-output","tagName":"Lamp_output","tableStartIndex":"","tableLength":"","value":"","valueType":"msg.payload","topic":"","topicType":"none","name":"(< 85) read lamp status ","x":359.1111145019531,"y":215,"wires":[["6f4799f.995e768"]]},{"id":"6f4799f.995e768","type":"switch","z":"c8afbdc3.53484","name":"Is lamp OFF ?","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"1","vt":"num"}],"checkall":"false","outputs":1,"x":575.77783203125,"y":214.88885498046875,"wires":[["590532aa.7acabc"]]},{"id":"a140480c.114488","type":"switch","z":"c8afbdc3.53484","name":"Is lamp ON ?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","outputs":1,"x":567.22216796875,"y":140.888916015625,"wires":[["77cd5c72.e9c954"]]},{"id":"2835e976.d07ea6","type":"pac-device","z":"","address":"restpac.groov.com","protocol":"http"}]
    
    
  3. Deploy, and then click the Inject button to start the flow.

    Observe the lamp.

    Keep monitoring the temperature and running the flow until you’ve had enough fun.