Skip to content

Generated random values on Windows and Local Events

In this tutorial an Input Sensor Attribute will be created, which instead of reading from an actual Sensor, will generate its own random value between 0 and 9.

The Output Sensor Attribute will have the purpose of writing a value into a local .txt file. These values provided to the Output Sensor Attribute will be by rules that are defined in so called 'Events'.

The following situation should be handled:

  • If the value from the Input Attribute is above 5, set the Output Attribute to 'True'. (It will write the value 'True' into the .txt file)

  • If the value from the Input Attribute is below 5, set the Output Attribute to 'False'. (It will write the value 'True' into the .txt file)

Great, let's get started!

Open the 'Sensors' view.

Screenshot

Add a new Sensor with the name 'RandomValue' and Type 'Random' or similar.

Screenshot

Click 'Add' to save the new Sensor Group.

Screenshot

Click 'Configure'.

Screenshot

No attributes have been configured yet.

Screenshot

Create a new Attribute. Fill in the values:

  • Name: rand
  • Type: integer
  • Direction: input (from sensor to device)
  • Interval: 5 sec

Screenshot

The attribute has been created successfully.

Screenshot

Click the '< >' button to configure the Sensor Attribute Script.

Screenshot

To start editing, click the 'Edit' button.

Screenshot

Edit mode will appear and the script may be added manually or from a template.

Screenshot

Select the template 'randomGenerator (Test)'.

Screenshot

The script will be added to the script body.

Screenshot

Click 'Validate' to validate the script.

Screenshot

After successful validation, click 'Save' to save the changes. Then click 'Back to Attribute List'.

Screenshot

In the overview, the Script State will now show as 'valid'.

Screenshot

Toggle the button in the Action area to activate the Sensor Attribute.

The collection of data will start at this point.

Screenshot

The Attribute State has now changed to active.

Screenshot

In the 'Add Attribute' section, create a new Attribute with the following details:

  • Name: resultToText
  • Type: boolean
  • Direction: output (from device to sensor)
  • Interval: Event-driven (cannot be changed for output direction)

Screenshot

Click the 'Add' to save the new attribute.

Screenshot

In the overview, click the '< >'(Script) button.

Screenshot

In the bottom left corner, click 'Edit' to enable editing of the script.

Screenshot

The script can now be edited, as the 'Validate' button has appeared.

Screenshot

Enter the following detail:

  • Input Parameter: True

From the 'Templates' dropdown in the top-right corner, select the 'writeToFile (Test)' template.

Screenshot

Click the 'Validate' button.

Screenshot

Save the changes by clicking the 'Save' button and then click 'Back to Attribute List' to return to the overview.

Screenshot

The script state for the attribute 'resultToText' is now valid.

Screenshot

Click on the switch to activate the 'resultToText' attribute.

Screenshot

Great, both Attributes are now valid and active!

Screenshot

In the Menu, click 'Events'.

Then, click the 'Add Events' button.

Screenshot

For this scenario, we will need to eventually create two events. The first Event will handle the situation if the random generated number by the input Attribute is above 5, then save the value 'true' to the test.txt file.

Screenshot

Let's fill out the details for the first event scenario as follows:

Event Source
  • Sensor: RandomValue (Random)
  • Attribute: rand (integer)
  • Attribute Average: Real-Time
  • Event Condition: greater than
  • Event Value: 5
Event Action
  • Sensor: RandomValue (Random)
  • Attribute: resultToText
  • Event Trigger Value: True
Event Parameters
  • Name: greaterThan5

Finally, click the 'Add' button to save the event.

Screenshot

In the Event List overview, click 'Add Event' to create the second event.

Screenshot

This second will handle the situation if the random generated number by the input Attribute is below 5, then save the value 'false' to the test.txt file.

Screenshot

Let's fill out the details for the first event scenario as follows:

Event Source
  • Sensor: RandomValue (Random)
  • Attribute: rand (integer)
  • Attribute Average: Real-Time
  • Event Condition: less than
  • Event Value: 5
Event Action
  • Sensor: RandomValue (Random)
  • Attribute: resultToText
  • Event Trigger Value: False
Event Parameters
  • Name: lessThan5

Screenshot

Finally, click the 'Add' button to save the event.

Screenshot

Both Events are now created and will be listed in the overview.

Activate both Events by clicking on the switches.

Screenshot

Now that the Events are active, the Edge Client will start writing the results of the evaluations from the Input Attribute to the Output Attribute. In this case, if the value from the input attribute is greater than 5, write the value 'True' in the test.txt file, if it is below 5, overwrite the value with the value 'False'.

Screenshot

Let us check the current value of the Input Attribute.

Click 'Sensors' in the Menu, then for the input Attribute, click the 'Overview' button. The Input Attribute will be shown with its latest value.

Use the refresh button in the top-right corner to check the latest value.

Remember, the value is always updated after every 5 seconds.

Screenshot

In File Explorer on Windows, navigate to the folder with the downloaded files for HyperConnect and locate the 'test.txt' file.

Open 'test.txt' in Notepad or similar program.

Screenshot

Because the read value was 2, which is less than 5, the second event was fulfilled successfully and the value 'false' was written in the test.txt file.

Screenshot

Back to the overview, click the 'Refresh' button in the top-right corner to see the new value read from the input attribute.

The value was 6, so the first event must have been fulfilled.

Screenshot

Correctly, if you re-open the test.txt file, the value was set to 'true'.

Screenshot

Connect a Remote Controller

Note: To install a Remote Controller on a mobile phone, please follow the instructions here:

Note: To connect the Remote Controller with the Edge Client, please follow the instruction:

On the Edge Client, make sure the connection is 'Active'.

Screenshot

On the Remote Controller, make sure the device is 'Online'.

Screenshot

On the Remote Controller, click the 'Sensors' button.

Screenshot

The sensor data from the Edge Client will be automatically displayed on the sensor overview.

Screenshot

On the Remote Controller, click the 'History' button to see the graph of readings.

Screenshot

The graph of readings will be displayed and updates automatically.

Screenshot

Awesome, you did it! This is a good example of how data input streams can be monitored automatically and that the rules can be predefined for any outcome.

Did you notice the that Input Attribute when it was exactly 5 was not handled in this tutorial?

Give it a try and create a third event which sets the boolean value 'true' when the Input Attribute is 'equal to' 5.

Note: 'greater than or equal' and 'less than or equal' options are not available by default to avoid any overlapping in the Rules Engine.

Good luck and feel free to ask in the Forum if you face any issues!