|
| 1 | +Compare two text values using different comparison operations. Perfect for conditional logic, filtering data, validating user input, or creating smart automation rules based on text content matching, differences, or substring detection. |
| 2 | + |
| 3 | +## What is Text Compare? |
| 4 | + |
| 5 | +The Text Compare block evaluates two text inputs using a specified comparison operator and returns true or false. This enables you to build conditional logic based on text content, whether checking for exact matches, detecting differences, or finding substrings within larger text. |
| 6 | + |
| 7 | +## How It Works |
| 8 | + |
| 9 | +The block performs three types of text comparison operations: |
| 10 | +- **Equals (=)** - Exact match comparison (case-sensitive) |
| 11 | +- **Not Equals (≠)** - Different text detection |
| 12 | +- **Includes** - Substring detection within text |
| 13 | + |
| 14 | +## Comparison Operators |
| 15 | + |
| 16 | +### Equals (=) - Exact Match |
| 17 | +Returns true when both text values are exactly the same, including case sensitivity. |
| 18 | + |
| 19 | +::: warning Case Sensitivity Alert |
| 20 | +Text comparison is case-sensitive! "Hello" is NOT equal to "hello" |
| 21 | +::: |
| 22 | + |
| 23 | +**Examples:** |
| 24 | +- "hello" = "hello" → **true** |
| 25 | +- "Hello" = "hello" → **false** (case-sensitive) |
| 26 | +- "test123" = "test123" → **true** |
| 27 | +- " test " = "test" → **false** (whitespace matters) |
| 28 | + |
| 29 | +**Common Uses:** |
| 30 | +- ✅ Check device status: `device_status = "online"` |
| 31 | +- ✅ Validate user role: `user_role = "admin"` |
| 32 | +- ✅ Confirm completion: `task_status = "completed"` |
| 33 | + |
| 34 | +### Not Equals (≠) - Different Values |
| 35 | +Returns true when text values are different in any way. |
| 36 | + |
| 37 | +**Examples:** |
| 38 | +- "hello" ≠ "world" → **true** |
| 39 | +- "same" ≠ "same" → **false** |
| 40 | +- "Test" ≠ "test" → **true** (case-sensitive) |
| 41 | + |
| 42 | +**Common Uses:** |
| 43 | +- ⚠️ Detect changes: `current_status ≠ previous_status` |
| 44 | +- 🚫 Block guest users: `username ≠ "guest"` |
| 45 | +- 📝 Validate required fields: `input_field ≠ ""` |
| 46 | + |
| 47 | +### Includes - Substring Detection |
| 48 | +Returns true when the left text contains the right text as a substring. |
| 49 | + |
| 50 | +::: tip Perfect for Keyword Searching |
| 51 | +Use includes to search for keywords within longer text like error messages, logs, or user input |
| 52 | +::: |
| 53 | + |
| 54 | +**Examples:** |
| 55 | +- "hello world" includes "world" → **true** |
| 56 | +- "temperature alert" includes "temp" → **true** |
| 57 | +- "test" includes "testing" → **false** (left must contain right) |
| 58 | + |
| 59 | +**Common Uses:** |
| 60 | +- 🔍 Find errors: `error_log includes "timeout"` |
| 61 | +- 📧 Email filtering: `email_address includes "@company.com"` |
| 62 | +- 🎯 Command parsing: `voice_command includes "lights"` |
| 63 | + |
| 64 | +## Practical Examples |
| 65 | + |
| 66 | +::: details 🏠 Smart Home Examples |
| 67 | + |
| 68 | +### Door & Security |
| 69 | +~~~javascript |
| 70 | +// Check if door is locked |
| 71 | +door_status = "locked" → Turn off porch light |
| 72 | + |
| 73 | +// Alert if door left open |
| 74 | +door_status ≠ "closed" → Send notification |
| 75 | + |
| 76 | +// Security monitoring |
| 77 | +security_log includes "breach" → Trigger alarm |
| 78 | +~~~ |
| 79 | + |
| 80 | +### Temperature & Climate |
| 81 | +~~~javascript |
| 82 | +// AC control |
| 83 | +room_temp = "hot" → Turn on air conditioning |
| 84 | + |
| 85 | +// Sensor errors |
| 86 | +temp_reading includes "error" → Send maintenance alert |
| 87 | + |
| 88 | +// Room occupancy |
| 89 | +bedroom_status ≠ "occupied" → Reduce heating |
| 90 | +~~~ |
| 91 | + |
| 92 | +::: |
| 93 | + |
| 94 | +::: details 🔧 System Monitoring Examples |
| 95 | + |
| 96 | +### Error Detection |
| 97 | +~~~javascript |
| 98 | +// System health |
| 99 | +system_status ≠ "healthy" → Send alert |
| 100 | +error_message includes "critical" → Immediate notification |
| 101 | + |
| 102 | +// Performance monitoring |
| 103 | +response_time includes "slow" → Log performance issue |
| 104 | +~~~ |
| 105 | + |
| 106 | +### Device Management |
| 107 | +~~~javascript |
| 108 | +// Connectivity checks |
| 109 | +device_ping ≠ "success" → Mark device offline |
| 110 | +connection_type = "ethernet" → Use high-speed settings |
| 111 | + |
| 112 | +// Battery monitoring |
| 113 | +battery_level includes "low" → Send low battery warning |
| 114 | +~~~ |
| 115 | + |
| 116 | +::: |
| 117 | + |
| 118 | +## Common Issues & Solutions |
| 119 | + |
| 120 | +::: details 🔤 Case Sensitivity Problems |
| 121 | + |
| 122 | +::: danger Most Common Issue |
| 123 | +"Online" ≠ "online" - Case matters in all comparisons! |
| 124 | +::: |
| 125 | + |
| 126 | +::: details ⚠️ Whitespace Issues |
| 127 | + |
| 128 | +**Hidden spaces cause comparison failures:** |
| 129 | + |
| 130 | +| What You See | Actual Value | Result | |
| 131 | +|--------------|--------------|--------| |
| 132 | +| "active" | "active " | Won't match "active" | |
| 133 | +| "online" | " online" | Won't match "online" | |
| 134 | + |
| 135 | +**Solutions:** |
| 136 | +- Be aware extra spaces break matches |
| 137 | +- Check for leading/trailing spaces in your data |
| 138 | +- Clean data at the source when possible |
| 139 | + |
| 140 | +::: |
| 141 | + |
| 142 | +::: details 🔢 Text vs Numbers |
| 143 | + |
| 144 | +::: warning Important |
| 145 | +This block compares TEXT, not numbers! "10" vs "9" gives unexpected results |
| 146 | +::: |
| 147 | + |
| 148 | +## Quick Reference |
| 149 | + |
| 150 | +### When to Use Each Operator |
| 151 | +| Operator | Use When | Example | |
| 152 | +|----------|----------|---------| |
| 153 | +| **Equals (=)** | Need exact match | `status = "online"` | |
| 154 | +| **Not Equals (≠)** | Need to detect difference | `role ≠ "guest"` | |
| 155 | +| **Includes** | Search within text | `message includes "error"` | |
| 156 | + |
| 157 | +### Related Blocks |
| 158 | +- **Number Compare** - For numeric comparisons (>, <, >=, <=) |
| 159 | +- **Logic AND/OR** - Combine multiple text comparisons |
| 160 | +- **IF/Then** - Use comparison results to control flow |
0 commit comments