Get Started
Part 4

Logic

This part covers logic and its building blocks: control groups, controls, condition groups, action groups, conditions, and actions.

Logic

Logic is the workspace where all algorithm blocks are created.

  • Algorithm blocks contained in a logic execute at each execution cycle of that logic.
  • Multiple logics can be created within a single project.
  • When multiple logics exist, each logic runs simultaneously regardless of order.

Add a logic with + in the left menu. Each logic has the following settings.

The Add Logic dialog with Enabled, Name, Execution Cycle, and Reverse Execution fields
The Add Logic dialog. The default execution cycle is 50 milliseconds.

Enabled

Sets whether the logic is used. Disabled logics do not execute.

Name

Enter the display name. Any name can be used.

Execution Cycle

Sets the execution cycle of the logic. The blocks in the logic execute at the specified cycle; choose a value appropriate for your hardware and control objective. Shorter cycles give faster response but higher CPU usage. The minimum is 1 millisecond, and 50 to 100 milliseconds is suitable for general use.

For example, if the execution cycle is 50 milliseconds and all blocks take 5 milliseconds to run, the system waits for the remaining 45 milliseconds before executing the blocks again.

Note Each logic runs on its own thread, so the actual cycle can be longer than the value you set. The gap grows with weaker hardware and higher CPU load, and under normal conditions it stays within 0 to 3 milliseconds. Grablo is not suited to control that needs timing accurate to under a millisecond.

Reverse Execution

Reverses the execution order of child blocks. When off, blocks execute top to bottom; when on, bottom to top.

Edit, Duplicate, Delete

Manage logics with the Edit, Duplicate, and Delete buttons in the left menu. Deleted logics are moved to the trash and removed automatically after 30 days (Part 3).

Caution Logics execute independently, but variables are shared by the whole project. If two logics write to the same variable, the later write overwrites the earlier one. Keep a single logic as the writer for each variable and let other logics only read it.

Block Selection Mode / Clipboard

Select multiple blocks (controls, conditions, actions, etc.) at once to duplicate, delete, copy, cut, and paste them in bulk. Click the checkbox icon in the top-right corner to enter selection mode, click blocks to select them, and use the action buttons in the header. Pasting works within the same logic and across different logics.

ShortcutAction
Ctrl+CCopy
Ctrl+XCut
Ctrl+VPaste
DeleteDelete
EscExit selection mode

Control Group

A control group bundles multiple controls into one group and configures how they execute. Control groups can only be added directly under a logic, either with + Add in the upper right or with the + button shown above or below existing blocks.

Priority Mode

Determines which control executes when multiple controls in the group satisfy their conditions at the same time.

  • None: No priority is applied. Each control executes in its order within the group when its condition is met.
  • By Priority: Among controls whose conditions are met, the one with the highest priority executes. Lower numbers mean higher priority; if a higher-priority condition is met while another control is running, the running control is stopped immediately and the higher-priority control executes.
  • First Only: The control whose condition was met first executes. After it completes, if its condition is no longer met, the next control that met its condition executes.
  • Last Only: The control whose condition was met last takes precedence, and any currently running control is stopped immediately.

Common Settings and Management

Enabled, Name, and Reverse Execution behave the same as for logic. Move blocks by drag and drop, and edit, duplicate, or delete them from the right-click menu. Deleting a group also deletes all blocks it contains.

Control

A control is the basic execution unit of algorithm blocks, consisting of a condition area and an action area. When the condition area is met, the actions execute in order, and after all actions complete, the condition area is evaluated again. When one logic holds several controls, they run in order from the top, and once the last one finishes execution returns to the first.

The condition area can contain conditions and condition groups; the action area can contain actions, action groups, and controls. Nested structures are supported, so you can build configurations that branch into different actions depending on the situation after a condition is met.

Example of controls nested inside a control
Nested controls. When a person is detected (outer control), different actions run depending on the posture evaluation (inner controls).

Condition Operator

The operator that combines multiple conditions or condition groups in the condition area.

  • AND: Actions execute only when every condition and condition group in the condition area is met.
  • OR: Actions execute when at least one condition or condition group is met.

Condition Option

An option applied to how the condition area is evaluated.

  • None: The condition is met when true and not met when false.
  • Invert: The condition is met when false and not met when true.
  • Rising Edge: Met only at the moment the condition changes from false to true. Example: the moment a push button is pressed.
  • Falling Edge: Met only at the moment the condition changes from true to false. Example: the moment a pressed push button is released.
  • Hold Time: Met once when the condition stays true for the specified hold time. The hold time resets to zero when the condition is met or becomes false during the hold period. Example: holding a push button for 3 seconds.
  • Count: The count increases by one each time the condition changes from false to true, and the condition is met once when the count reaches the specified value. The count resets to zero when met, or when the timeout expires. Example: pressing a push button 3 times.

With Count selected, you also set the count, the timeout, and the Timeout Mode. Interval Time requires the interval between the moments the condition becomes true to stay within the timeout (e.g. pressing 3 times with intervals shorter than 1 second). Total Time requires the total time from the first true moment until the full count to stay within the timeout (e.g. 3 presses within 5 seconds of the first press).

Note Sensor readings can flip between true and false in a short time. Without an option, the actions may run repeatedly each time; the Hold Time option is a recommended way to stabilize the evaluation.

Priority

Enter the priority to apply when the control belongs to a control group whose priority mode is By Priority. Leave it empty if not applicable.

Common Settings and Management

Enabled, Name, and Reverse Execution behave the same as for logic. Move controls by drag and drop, and edit, duplicate, or delete them from the right-click menu. Deleting a control also deletes all blocks it contains.

Condition Group

A condition group bundles multiple conditions or condition groups and calculates whether the combined result is met. Condition groups can be nested, enabling complex logical expressions.

The Operator (AND / OR) and Option work the same way as the control's condition operator and condition option, and the option applies to the combined result of the group. For example, a rule such as "all three conditions stay true for 3 seconds" is built by applying the Hold Time option to the condition group rather than to each condition.

Action Group

An action group bundles multiple actions and sets how the group repeats: by count, range, condition, or duration. Action groups can contain actions, action groups, and controls, and support nesting.

Repeat Options

  • By Count: Repeats the group the specified number of times.
  • By Range: Repeats from the start value to the end value, incrementing by the step. The current index is stored in the selected index variable, which must be of numeric type.
  • While Condition is Met: Repeats while the repeat condition is true. The repeat condition is written with block coding and must return a digital value. It is checked at the start of each iteration, so an iteration in progress runs to completion even if the value becomes false.
  • For Duration: Repeats for the specified time. Expiration is also checked at the start of each iteration, so an iteration in progress runs to completion even if time runs out.

Depending on the selected repeat option, the Repeat Count, Index Variable, From, To, Step, Repeat Condition, and Repeat Duration fields are displayed. Enabled, Name, Reverse Execution, and the move/edit/duplicate/delete operations are the same as for other blocks.

Condition

Add a condition inside a control or condition group, or with the + button shown above or below blocks in the condition area. Each condition has an enable state, a name, a type, and an option; the option works the same as the control's condition option.

Add condition dialog
The add-condition dialog. Selecting a type reveals that type's settings.

Condition Types

GroupTypeDescription
LogicAlwaysAlways met. Use this when an action should always run.
OnceMet only once at startup, then never again. Useful for one-time initialization such as setting default variable values.
CompareCompares a variable's value against a specified value. The most commonly used type.
Date/TimeScheduleMet on specified dates. Repeat intervals can be set by day, week, month, or year (weekly intervals also take the days of the week), and the end option is No End, End Date, or Repeat Count.
Time RangeMet only during specified time ranges within a day. Multiple ranges can be configured.
PeriodicMet for one cycle (one logic execution cycle) at regular intervals. Use this for actions that run periodically.
StateWatch ConditionReferences whether another condition, condition group, or control is met. Useful for reusing existing conditions.
Watch ActionUses the execution state of another action, action group, control, or control group (Not Started, Running, Complete, Error) as a condition.
On ChangeMet for one cycle whenever a variable's value changes. Tolerance and Sampling Period tune what counts as a change.
Misc.Custom ConditionWrite the condition yourself with block coding. The blocks must return a digital value.
Note When using On Change with a numeric variable, set a Tolerance as well. With a tolerance of 0, even the smallest change satisfies the condition, so a noisy sensor reading can trigger it on every scan. For example, with a reference value of 1 and a tolerance of 0.5, the condition is met when the value drops below 0.5 or rises above 1.5, and that value becomes the new reference. Sampling Period is how often the value is checked; the default is one second, and 0 checks on every scan.

Action

Add an action inside a control or action group, or with the + button shown above or below blocks in the action area. Each action has an enable state, a name, and a type, and the detail settings depend on the type. Most action types use resources registered in advance in the Settings menu (Part 6).

Added actions are edited, duplicated, and deleted from the block's menu, and reordered by drag and drop. Conditions can only be moved within the condition area, and actions only within the action area.

Add action dialog
The add-action dialog (Delay type shown). The settings below change with the type.

Action Types

GroupTypeDescription
HardwareI/O Device ControlControls various I/O devices such as LEDs, sensors, LCDs, and motors.
SystemSet VariableWrites a value to a variable. Write Mode also performs inversion, arithmetic, and string appending.
Shell CommandExecutes terminal commands. Can run system commands or launch external programs.
Read/Write FileReads from or writes to files. Supports text and binary formats.
File SystemCreates, deletes, moves, or copies files and directories.
DelayWaits for a specified duration. Normal mode works in milliseconds and Precision mode in microseconds (0 to 999μs).
TimerControls a timer with five commands: Start, Stop, Reset, Set Time, and Get Time. Useful for measuring elapsed time or implementing timeouts.
DataCollectionAdds, removes, or retrieves data from collections. Supports list and map types.
DatabaseStores or retrieves data from databases. Supports SQL, Firebase, and more.
StatisticsCalculates real-time statistics such as average, max, min, and sum from collected data.
Data LoggingRecords current variable values to the specified data logging channel.
MediaPlay MediaPlays, pauses, or stops audio/video files or URLs.
Display ImageDisplays an image on screen. Specify a file path or URL.
SynthesizerPlays notes on a virtual instrument. Set pitch and duration, or play MIDI files.
CameraCaptures images or starts/stops video web streaming from the camera.
Audio AnalysisAnalyzes audio frequencies and amplitudes in real time using FFT (Fast Fourier Transform).
Record AudioRecords audio from the microphone.
Transform AudioAdjusts the tempo and pitch of audio files.
AIAI AnalysisPerforms AI analysis on video or audio. See the AI Analysis section below.
LLM AI QuerySends a text query with optional attachments to the LLM AI provider and stores the response in a variable.
Text-to-Speech (TTS)Converts text to speech using AI. Supports built-in local models and online AI services.
Speech-to-Text (STT)Converts speech to text using AI. Supports built-in local models and online AI services.
IoTTelegram MessageSends or receives messages via a Telegram bot.
Send EmailSends emails via SMTP.
Push NotificationSends a push notification to the user's mobile app.
Zigbee Device ControlReads sensor values or controls actuators of Zigbee devices. Supports 3,400+ devices via Zigbee2MQTT (an open-source bridge that connects Zigbee devices over MQTT).
Home Assistant IntegrationControls Home Assistant sensors, switches, and lights, or exposes Grablo variables to Home Assistant.
CommunicationMQTT CommunicationPublishes (sends) or subscribes to (receives) messages using MQTT, the standard IoT messaging protocol.
Modbus CommunicationExchanges data with PLCs and other industrial equipment using the Modbus protocol.
OPC UA CommunicationCommunicates with industrial equipment using the OPC UA protocol.
HTTP CommunicationSends and receives HTTP requests to web servers or REST APIs.
User Defined CommunicationImplements custom protocols over serial, TCP, UDP, WebSocket, Bluetooth, or shared memory.
ControlPID ControlPerforms feedback control with the PID algorithm, for precise control of temperature, motor speed, and more.
Misc.Custom ActionWrite the action yourself with block coding.

Wait Until Finished

The Play Media, Synthesizer, Text to Speech, and Audio Transform actions have a Wait Until Finished setting. When it is on, the action stays in the running state until playback ends, so the next action does not start. When it is off, the action completes as soon as playback starts and the next action runs immediately. Turn it off when other actions must proceed during playback.

Status Variables

Some actions report their current state as a number. Use the returned value with Compare conditions.

ActionStatus values
Play Media0 initial / 1 playing / 2 paused / 3 stopped / 4 playback complete / 5 error
Synthesizer0 initial / 1 playing / 2 paused / 3 stopped / 4 playback complete
Speech to Text0 idle / 1 listening / 2 processing / 3 complete / 4 error

AI Analysis

The AI Analysis action runs an analyzer registered in SettingsAI Analyzer with the analysis type you select. Once running, the results are written to variables continuously, so automation is built by combining them with Compare conditions. All analysis is performed on the controller; video is never sent to the cloud.

Commands

A single analyzer can hold several analyses. Registering and starting them is done with the following commands.

  • Add Analysis: Adds an analysis to the analyzer and binds the variables that receive its results.
  • Clear All Analyses: Removes every analysis registered on that analyzer.
  • Start Analysis and Stop Analysis: Shown for audio analyzers only; they start and stop audio capture and analysis.
Caution Video analysis does not begin with Add Analysis alone. The camera must be started from ActionCamera. Audio analysis needs Start Analysis after Add Analysis; if it is missing, the result variables stay empty indefinitely.

Common Settings

SettingDescription
Confidence (%)Only detections at or above this value are used. Raising it keeps only certain results; lowering it misses fewer. The default depends on the model: 50 for object detection, 70 for face detection.
Detection areaDrag on the camera preview to limit the analyzed area. Without one, the whole frame is analyzed.
Select ByDecides which detection is written to the variables when several are found: Highest Confidence, By Confidence Index (0-based), Largest Size, or Closest From Ref. Point. Color tracking offers Largest, Closest, and By Index.
Reference PointThe reference coordinates used when Select By is set to the closest detection.

Analysis Types

Twenty video analysis types and two audio analysis types are supported.

TypeDescription
Object DetectionDetects 80 object classes such as people and vehicles in real time.
Face DetectionDetects faces, including emotion recognition and age/gender estimation.
Face RecognitionCompares detected faces against enrolled faces to identify who they are.
Pose EstimationReturns 17 body joint coordinates per person.
Hand TrackingReturns 21 hand joint coordinates, including gesture recognition.
Action RecognitionRecognizes around 400 activity categories such as walking, running, and sitting.
Hand Gesture RecognitionRecognizes 25 hand gestures such as swipes and thumbs-up.
Color TrackingTracks objects of a specified color in real time.
Line TrackingProvides the floor line's offset and angle for line-follower robots.
Line Crossing CounterCounts people entering and exiting across a virtual line drawn on screen.
Fire DetectionDetects flames in real time.
QR / BarcodeDetects and decodes QR codes and multiple barcode formats.
OCR (Text Recognition)Reads multilingual text, including Korean and English, in real time.
License Plate RecognitionDetects and reads vehicle license plates. Supports Korean and Latin plates.
Teachable Machine ClassificationUses image classification models trained with Google Teachable Machine.
Edge Impulse Classification / Object Detection / Anomaly DetectionUses vision models trained with Edge Impulse, including normal/abnormal classification.
Custom ClassificationUses a classification model trained directly on the controller, without external services.
Custom Anomaly DetectionLearns only normal samples and detects deviations from them. No defect samples are required.
Sound ClassificationClassifies microphone input into 521 categories such as speech, alarms, and glass breaking (audio).
Edge Impulse Classification (Audio)Uses audio classification models trained with Edge Impulse.

Results are continuously written to the variables bound to the output fields of the AI Analysis action. Bind a digital variable such as Person Detected or a numeric detection count, and combine it with a Compare Value condition.

Training Custom Models

Targets not covered by the built-in models can be trained in two ways. Teachable Machine and Edge Impulse models are trained in those external services and uploaded as model files. Custom Classification and Custom Anomaly Detection are trained directly on the controller, with sample collection and training driven by the AI Analysis action's Command field.

  • Custom Classification commands: Add Sample, Delete Sample, Train, Class List, Class Count, Sample Count, Sample List, Delete Class, Delete All, plus the read commands Read State, State Match?, and Read All States.
  • Custom Anomaly Detection commands: Add Good Sample, Delete Good Sample, Train, Good Sample Count, Good Sample List, Delete All, plus the read commands Read Score and Is Anomalous?.
Recommended setup Separate the training logic from the evaluation logic. The training logic runs Add Sample and Train from dashboard push buttons, while the evaluation logic runs Read State (or Read Score) continuously to update the result variables.
Note Face recognition offers an anti-spoofing option that blocks impersonation with photos or screens (SettingsAI Analyzer). Enabling it slightly reduces recognition speed.