Update matcher_compare.js
This commit is contained in:
parent
25fc9cfda5
commit
21eb6a2744
1 changed files with 9 additions and 18 deletions
|
|
@ -5,51 +5,43 @@ export default {
|
||||||
name: "Compare Numbers Matcher",
|
name: "Compare Numbers Matcher",
|
||||||
colour: 224,
|
colour: 224,
|
||||||
inputsInline: true,
|
inputsInline: true,
|
||||||
description: "Numerically compare the new Feed value with another number.",
|
description: "Create smart triggers based on numerical sensor data and thresholds. Perfect for temperature alerts ('notify when above 80°F'), battery monitoring ('warn when below 20%'), humidity control ('turn on fan when over 60%'), or any sensor-based automation that depends on numerical comparisons.",
|
||||||
|
|
||||||
connections: { mode: 'value', output: 'matcher' },
|
connections: { mode: 'value', output: 'matcher' },
|
||||||
|
|
||||||
template: "%OP %B",
|
template: "%OP %B",
|
||||||
|
|
||||||
fields: {
|
fields: {
|
||||||
OP: {
|
OP: {
|
||||||
description: "Select a comparison to perform",
|
description: "Choose how to compare your feed's numerical data:",
|
||||||
options: [
|
options: [
|
||||||
['=', 'EQ', "True if the two numbers are equal"],
|
['=', 'EQ', "Exactly equal: Triggers when feed value equals your number (e.g., button state = 1, exact temperature reading = 72.5°F). Best for digital switches and precise measurements."],
|
||||||
['\u2260', 'NEQ', "True if the two numbers are not equal"],
|
['\u2260', 'NEQ', "Not equal: Triggers when feed value is anything other than your number (e.g., not zero, sensor reading changed from baseline). Useful for detecting changes or non-specific states."],
|
||||||
['\u200F<', 'LT', "True if the Feed value is less than number B"],
|
['\u200F<', 'LT', "Less than: Triggers when feed value drops below your threshold (e.g., temperature < 60°F for heating alerts, battery < 15% for low power warnings)."],
|
||||||
['\u200F\u2264', 'LTE', "True if the Feed value is less than or equal to number B"],
|
['\u200F\u2264', 'LTE', "Less than or equal: Triggers when feed value is at or below threshold (e.g., humidity ≤ 30% for dry air alerts, speed ≤ 0 for stopped condition)."],
|
||||||
['\u200F>', 'GT', "True if the Feed value is greater than number B"],
|
['\u200F>', 'GT', "Greater than: Triggers when feed value exceeds your threshold (e.g., temperature > 85°F for cooling alerts, motion count > 10 for high activity)."],
|
||||||
['\u200F\u2265', 'GTE', "True if the Feed value is greater than or equal to number B"],
|
['\u200F\u2265', 'GTE', "Greater than or equal: Triggers when feed value meets or exceeds threshold (e.g., pressure ≥ 1000 hPa for weather tracking, light level ≥ 500 for daylight detection)."],
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
inputs: {
|
inputs: {
|
||||||
B: {
|
B: {
|
||||||
description: "The value to compare with the Feed value.",
|
description: "Set your comparison threshold or target value. Examples: 80 for temperature alerts, 20 for battery percentage warnings, 1000 for pressure readings, or any numerical value that's meaningful for your sensor data.",
|
||||||
check: "expression",
|
check: "expression",
|
||||||
shadow: 'io_math_number'
|
shadow: 'io_math_number'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
generators: {
|
generators: {
|
||||||
json: (block, generator) => {
|
json: (block, generator) => {
|
||||||
const
|
const
|
||||||
comparator = block.getFieldValue('OP'),
|
comparator = block.getFieldValue('OP'),
|
||||||
rightExp = generator.valueToCode(block, 'B', 0) || 'null',
|
rightExp = generator.valueToCode(block, 'B', 0) || 'null',
|
||||||
|
|
||||||
blockPayload = JSON.stringify({
|
blockPayload = JSON.stringify({
|
||||||
matcherCompare: {
|
matcherCompare: {
|
||||||
comparator: comparator?.toLowerCase() || null,
|
comparator: comparator?.toLowerCase() || null,
|
||||||
right: JSON.parse(rightExp),
|
right: JSON.parse(rightExp),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return [ blockPayload, 0 ]
|
return [ blockPayload, 0 ]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
regenerators: {
|
regenerators: {
|
||||||
json: (blockObject, helpers) => {
|
json: (blockObject, helpers) => {
|
||||||
const
|
const
|
||||||
|
|
@ -60,7 +52,6 @@ export default {
|
||||||
inputs = {
|
inputs = {
|
||||||
B: helpers.expressionToBlock(right, { shadow: 'io_math_number' }),
|
B: helpers.expressionToBlock(right, { shadow: 'io_math_number' }),
|
||||||
}
|
}
|
||||||
|
|
||||||
return { type: 'matcher_compare', fields, inputs }
|
return { type: 'matcher_compare', fields, inputs }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue