Skip to content

Openhab Rules Not Triggering

DodaTech 3 min read

In this tutorial, you'll learn about openhab rules not triggering. We cover key concepts, practical examples, and best practices.

Hook

You write an openHAB rule: when the motion sensor changes to ON, turn on the light. You test the motion sensor β€” it reports ON in the log. But the light stays off. The rule simply does not trigger.

The Wrong Way

Deleting and recreating the same rule with the same logic produces the same result β€” the issue is in the trigger configuration, not the rule's existence.

// BAD: Recreating the same rule
rule "Motion Light v2"
when
    Item Motion_Sensor changed to ON
then
    Light_Switch.sendCommand(ON)
end
Rule created: Motion Light v2
Motion sensor changed to ON β€” rule did not fire

Same logic, same result.

The Right Way

Check the rule's trigger conditions and logs to find why it does not fire.

# 1. Enable debug logging for rules
# In karaf console:
log:set DEBUG org.openhab.core.automation
# 2. Check openhab.log during a trigger event
tail -f /var/log/openhab/openhab.log | grep -i "rule\|motion\|trigger"
2026-06-24 10:00:00.000 [INFO ] [.core.automation] - Rule 'Motion Light' triggered by 'Motion_Sensor'
2026-06-24 10:00:00.000 [INFO ] [.core.automation] - Rule 'Motion Light': condition evaluation FAILED

The condition is failing, not the trigger.

// Check conditions in the rule
rule "Motion Light"
when
    Item Motion_Sensor changed to ON
then
    if (TimeOfDay.state == "NIGHT" || Hallway_Light.state != ON) {
        Light_Switch.sendCommand(ON)
    }
end

The condition TimeOfDay.state == "NIGHT" might be evaluating to NULL because the TimeOfDay item is not configured.

# 3. Fix: Add a null check or simplify the condition
rule "Motion Light"
when
    Item Motion_Sensor changed to ON
then
    Light_Switch.sendCommand(ON)
end
# 4. Test the trigger manually
# In Main UI β†’ Rules β†’ Select rule β†’ Run Now
Rule executed: Light turned on

If "Run Now" works but the automatic trigger does not, the event bus is not delivering the update to the rule engine. Restart openHAB:

sudo systemctl restart openhab

Prevention

  • Test rules with the "Run Now" button immediately after creation.
  • Check rule condition logic for NULL states.
  • Use simple rules first, add conditions incrementally.
  • Enable debug logging for org.openhab.core.automation during development.
  • Use the Main UI rule editor's visual flow for complex logic.

Common Mistakes with rules not triggering

  1. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  2. Misunderstanding that String is [Char] with poor performance for large text operations
  3. Using foldl instead of foldl' causing stack overflow on large lists

These mistakes appear frequently in real-world OPENHAB code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

What is the difference between 'changed' and 'received update'?

changed triggers when the item transitions between states (OFF→ON). received update triggers on any state change, even if the same value is sent again. Use changed for event-like triggers and received update for periodic values.

Can I trigger a rule from another rule?

Yes β€” use ruleName.trigger(). in DSL rules or sendCommand to a virtual item that triggers a second rule. Use then blocks for sequential logic within a single rule.

Why does my rule work in the UI but not in a .rules file?

File-based rules use DSL syntax while UI rules use a different engine. Check that file rules are enabled in rulesengine.cfg and that your .rules file syntax is valid.


DodaTech β€” rules that react the moment something happens.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro