Logic Blocks
When setting up automation, you may need to decide whether to perform an action based on the combination of several conditions. In this case, you should use logic blocks, including: And, Or, Xor, Equal, Greater Than, Greater Than Equal, Less Than, Less Than Equal, Not Equal, and Not.
And
Introduction
The "And" logic block only outputs true when all input conditions are true at the same time. This will trigger the next action. For example, only when "the door is open" and "someone is detected in the room" are both true, will the light turn on. The "And" block can combine up to 4 conditions by default, making your automation more accurate and flexible.
Attribute Description
- Input nodes: The left side of "Input A, B, C, D" should each be connected to boolean type data. 4 inputs are supported by default.
- Output node: The right side of the "Output" node connects to another node that can store boolean data.
Example
Let’s take the example "Turn on the light when someone enters the room."
Here are the steps:
- On the left side of the canvas, add "Door sensor - Switch status" (boolean) and "Human presence sensor - Presence status" (boolean) as input points.
- In the middle of the canvas, add an And block.
- Connect the output of "Door sensor - Switch status" to "Input A" on the And block. This represents whether the door is open.
- Connect the output of "Human presence sensor - Presence status" to "Input B" on the And block. This shows whether anyone is in the room.
- On the right side of the canvas, add "Light - Switch status" as the output point.
- Connect the output of the And block to the input of "Light - Switch status".
- After this setup, only when both "door is open (true)" and "a person is detected in the room (true)", the output of the And block will be
true. This will automatically turn on the light.
Or
Introduction
The "Or" logic block outputs true if any of the input conditions are true. This triggers the following action. For example, if "the door is open" or "someone is detected", the light will turn on if either condition is met. The "Or" block can handle 4 input conditions by default, which is suitable for automation scenarios that need to be triggered as long as one of several conditions is true.
Attribute Description
- Input nodes: The left side of "Input A, B, C, D" should each be connected to Boolean data. Four inputs are supported by default.
- Output node: The right side of the "Output" node should also be connected to a node that can hold Boolean data.
Example
Let’s take the example "Turn on the light when someone enters the room or the door is opened."
Here are the steps:
- On the left side of the canvas, add "Door sensor - Switch status" (Boolean) and "Human presence sensor - Presence status" (Boolean) as input points.
- In the middle of the canvas, add an Or logic block.
- Connect the output of "Door sensor - Switch status" to "Input A" on the Or block. This shows whether the door is open.
- Connect the output of "Human presence sensor - Presence status" to "Input B" on the Or block. This shows whether anyone is in the room.
- On the right side of the canvas, add "Light - Switch status" as the output point.
- Connect the output of the Or logic block to the input of "Light - Switch status".
- With this configuration, as long as either "the door is opened (true)" or "someone is detected (true)", the output of the Or block will be
trueand the lights will turn on automatically.
Xor
Introduction
The "Xor" logic block is used to handle situations where there are two or more inputs. When there is an odd number of inputs that are true, the output will be true.
For example, if only 1 or 3 inputs are true, the result is true. If the number of true inputs is even (including zero), the output will be false.
Compared to the "Or" operation, Xor is focused more on mutual exclusion. It is often used to prevent repeated triggering, to make toggling states, or in scenarios where actions happen only if an odd number of conditions are true.
Attribute Description
- Input nodes: The left side of "Input A, B, C, D" should each connect to Boolean data. 4 inputs are supported by default.
- Output node: The right side of the "Output" also connects to a node that stores Boolean data.
Example
Let's look at a case of controlling one light with multiple switches (such as two-way or multi-way control):
- On the left side of the canvas, add "Switch A - Switch state" (Boolean) and "Switch B - Switch state" (Boolean) as input points.
- In the middle of the canvas, add an Xor logic block.
- Connect the output of "Switch A - Switch state" to "Input A" of the Xor block, and connect the output of "Switch B - Switch state" to "Input B" of the Xor block.
- On the right side of the canvas, add "Light - Switch state" as the output point.
- Connect the output of the Xor logic block to the input of "Light - Switch state".
- When the states of the two switches are different (for example, A is on, B is off, or A is off, B is on), the light will be on. When the two switches have the same state (both on or both off), the light will be off.
Using the Xor logic block, you can easily achieve two-way or multi-way control for scenarios like stairway lighting. Switching any of the controls will correctly change the state of the light, and you will not get repeated or unwanted triggers.
Equal
Introduction
The "Equal" logic block compares the values of "Input A" and "Input B" to check if they are the same. If the values of both inputs are exactly equal, the output is true. Otherwise, the output is false. This block supports different types of inputs, making it suitable for checking whether the current state of a device matches the expected value. Only when the values are equal will it output true to trigger further automation actions.
Attribute Description
- Input nodes: Both "Input A" and "Input B" on the left can connect to numeric, Boolean, or enumerated data. If the input is Boolean or an enum, Aqara Studio will automatically convert them to numbers before comparing:
- Boolean:
falseis converted to 0.0, andtrueis converted to 1.0. - Enum: compared based on the number corresponding to the enum value (such as 1.0, 2.0, etc).
- Boolean:
- Output node: The right side of "Output" returns a Boolean result to show whether the two values are equal.
Besides connecting external data, you can also double-click the input or output to manually enter the values you want to compare. This makes debugging quick and flexible.
Example
Take the example, "When the door lock status equals 'Unlocked', turn on the light":
- On the left, add "Door lock - Switch status" (Enum type, for example, 0.0 means locked, 1.0 means unlocked) as an input point.
- In the middle, add an Equal logic block.
- Connect the output of "Door lock - Switch status" to "Input A" of the Equal block.
- For "Input B" of the Equal block, directly set the expected value (for example, 1.0, which means unlocked).
- On the right, add "Light - Switch status" as an output point.
- Connect the output of the Equal block to the input of "Light - Switch status".
- With this configuration, only when the door lock status is equal to 1 (unlocked) will the Equal block output
true, which turns on the light automatically. This creates a smart entry light experience.
This method is also suitable for numeric and Boolean automation scenarios. For example, you can trigger devices when a temperature equals the target value, or when a Boolean input matches its target state.
Not Equal
Introduction
The "Not Equal" logic block is used to compare the values of "Input A" and "Input B" to check if they are different. If the values are not the same, the output will be true. Otherwise, the output is false.
This block supports different data types and is useful when you want to check if a device state is not equal to a specific target. The output will only be true when the two values are different, allowing you to trigger further automation actions.
Attribute Description
The attribute settings are the same as those for the Equal logic block.
Greater Than
Introduction
The "Greater Than" logic block compares the values of "Input A" and "Input B" to check if A is greater than B. If the value of "Input A" is greater than "Input B", the output will be true. Otherwise, it will be false.
This block supports various data types. It is often used to check if a device or data value exceeds a preset threshold. Only when the value is greater, will the output be true and trigger follow-up automations.
Attribute Description
The attribute settings are the same as those for the Equal logic block.
Greater Than Equal
Introduction
The "Greater Than Equal" logic block compares "Input A" and "Input B" to see if A is greater than or equal to B. If "Input A" is greater than or equal to "Input B", the output will be true. Otherwise, it will be false.
This block is useful when you need to trigger an automation if the value meets or exceeds a threshold.
Attribute Description
The attribute settings are the same as those for the Equal logic block.
Less Than
Introduction
The "Less Than" logic block compares "Input A" and "Input B" to determine if A is less than B. If "Input A" is less than "Input B", the output will be true. Otherwise, it will be false.
You can use this block to check if a value is below a certain target before triggering the next action.
Attribute Description
The attribute settings are the same as those for the Equal logic block.
Less Than Equal
Introduction
The "Less Than Equal" logic block compares "Input A" and "Input B" to see if A is less than or equal to B. If "Input A" is less than or equal to "Input B", the output is true. Otherwise, it is false.
Use this block when you want actions to happen only if the value is equal to or below a target.
Attribute Description
The attribute settings are the same as those for the Equal logic block.
Not
Introduction
When you want to use the opposite (inverse) value of a Boolean state to control something else, you should use the "Not" logic block. This block will invert the input Boolean value and send it to the target. For example:
- If the switch state is true → output is false, and the light is off.
- If the switch state is false → output is true, and the light turns on.
Attribute Description
- Input node: The left side "Input" should be connected to Boolean data.
- Output node: The right side "Output" should be connected to a node that can store Boolean data.
Example
Here is an example of using one switch to control a light in the opposite way:
- On the left side of the canvas, add "Switch - Switch State" (Boolean) as the input point.
- In the middle of the canvas, add a Not logic block.
- Connect the output of "Switch - Switch State" to the input of the Not logic block.
- On the right side, add "Light - Switch State" as the output point.
- Connect the output of the Not logic block to the input of "Light - Switch State".
Result: When the switch is "on" (true), the Not block changes it to "off" (false), so the light turns off. When the switch is "off" (false), the Not block changes it to "on" (true), so the light turns on. This lets you control the light in the opposite way using a single switch.