u
This commit is contained in:
@@ -470,7 +470,14 @@ function evaluateCondition(condition) {
|
||||
|
||||
case 'sensor': {
|
||||
const sensorValue = getSensorValue(channel);
|
||||
return compareValues(sensorValue, operator, value);
|
||||
let target = value;
|
||||
|
||||
if (value && typeof value === 'object' && value.type === 'dynamic') {
|
||||
const targetSensorVal = getSensorValue(value.channel) || 0;
|
||||
target = (targetSensorVal * (value.factor || 1)) + (value.offset || 0);
|
||||
}
|
||||
|
||||
return compareValues(sensorValue, operator, target);
|
||||
}
|
||||
|
||||
case 'output': {
|
||||
@@ -505,7 +512,17 @@ function runRules() {
|
||||
if (evaluateCondition(conditions)) {
|
||||
// Rule matches - set output (later rules override)
|
||||
if (action.channel && action.value !== undefined) {
|
||||
desiredOutputs[action.channel] = action.value;
|
||||
let finalValue = action.value;
|
||||
|
||||
// Handle calculated value
|
||||
if (action.value && typeof action.value === 'object' && action.value.type === 'calculated') {
|
||||
const valA = getSensorValue(action.value.sensorA) || 0;
|
||||
const valB = action.value.sensorB ? (getSensorValue(action.value.sensorB) || 0) : 0;
|
||||
const diff = valA - valB;
|
||||
finalValue = (diff * (action.value.factor || 1)) + (action.value.offset || 0);
|
||||
}
|
||||
|
||||
desiredOutputs[action.channel] = finalValue;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user