@@ -1560,22 +1560,35 @@ static void evaluateAlarms(uint8_t idx) {
15601560 // For digital sensors, currentInches is either ACTIVATED_VALUE (1.0) or NOT_ACTIVATED_VALUE (0.0)
15611561 bool isActivated = (state.currentInches > DIGITAL_SWITCH_THRESHOLD);
15621562 bool shouldAlarm = false ;
1563+ bool triggerOnActivated = true ; // Track what condition triggers the alarm
15631564
15641565 // Determine if we should alarm based on trigger configuration
15651566 if (cfg.digitalTrigger [0 ] != ' \0 ' ) {
15661567 if (strcmp (cfg.digitalTrigger , " activated" ) == 0 ) {
15671568 shouldAlarm = isActivated; // Alarm when switch is activated
1569+ triggerOnActivated = true ;
15681570 } else if (strcmp (cfg.digitalTrigger , " not_activated" ) == 0 ) {
15691571 shouldAlarm = !isActivated; // Alarm when switch is NOT activated
1572+ triggerOnActivated = false ;
15701573 }
15711574 } else {
15721575 // Legacy behavior: use highAlarm/lowAlarm thresholds
1573- // highAlarm >= threshold means trigger when activated
1574- // lowAlarm <= threshold means trigger when not activated
1575- if (cfg.highAlarmThreshold >= DIGITAL_SWITCH_THRESHOLD) {
1576- shouldAlarm = isActivated; // Trigger when switch is activated
1577- } else if (cfg.lowAlarmThreshold <= DIGITAL_SWITCH_THRESHOLD) {
1578- shouldAlarm = !isActivated; // Trigger when switch is NOT activated
1576+ // Only one of these should be configured for a digital sensor
1577+ // highAlarm = 1 means trigger when activated
1578+ // lowAlarm = 0 means trigger when not activated
1579+ bool hasHighAlarm = (cfg.highAlarmThreshold >= DIGITAL_SWITCH_THRESHOLD);
1580+ bool hasLowAlarm = (cfg.lowAlarmThreshold <= DIGITAL_SWITCH_THRESHOLD && cfg.lowAlarmThreshold >= 0 );
1581+
1582+ if (hasHighAlarm && !hasLowAlarm) {
1583+ shouldAlarm = isActivated;
1584+ triggerOnActivated = true ;
1585+ } else if (hasLowAlarm && !hasHighAlarm) {
1586+ shouldAlarm = !isActivated;
1587+ triggerOnActivated = false ;
1588+ } else if (hasHighAlarm) {
1589+ // Default to high alarm behavior if both are set
1590+ shouldAlarm = isActivated;
1591+ triggerOnActivated = true ;
15791592 }
15801593 }
15811594
@@ -1586,8 +1599,8 @@ static void evaluateAlarms(uint8_t idx) {
15861599 if (state.highAlarmDebounceCount >= ALARM_DEBOUNCE_COUNT) {
15871600 state.highAlarmLatched = true ;
15881601 state.highAlarmDebounceCount = 0 ;
1589- // Send alarm with descriptive type for float switch
1590- const char *alarmType = isActivated ? " triggered" : " not_triggered" ;
1602+ // Send alarm with descriptive type based on configured trigger condition
1603+ const char *alarmType = triggerOnActivated ? " triggered" : " not_triggered" ;
15911604 sendAlarm (idx, alarmType, state.currentInches );
15921605 }
15931606 } else if (!shouldAlarm && state.highAlarmLatched ) {
0 commit comments