How-to use thing state to disable a rule?

  • Platform information:
  • openHAB version: 3.4.0
  • Issue of the topic: is it possible to run a rule only if a thing is online


I have rule triggered with cron event. Is it possible to add a thing state as online in addition to the cron ?

This is an example:

rule "AWtrix app temp update"
	Time cron "0 0/10 9-20 ? * * *"
	logInfo("Awtrix app temp", " Updating...")

I’m looking for a way to it like this:

	Time cron "0 0/10 9-20 ? * * *" 
       AND thingXXX online

there is docs to explain how to deal with a state change, but not with “just the state”

Thanks for your help

Yes you can do this but:

  1. Not the way you are trying to
  2. Not in Rules DSL

I don’t think there is an easy way to get the Thing’s status inside a rule in Rules DSL like you can in other languages (including Blockly) and there definitely isn’t a way to disable a rule from Rules DSL like other languages.

If you stick with Rules DSL, you’ll have to create another rule that triggers when the Thing changes status and update an Item. Then I’m this rule have an if statement that checks that Item.

In any of the other languages you can add an if statement that checks the status of the Thing directly.

In the UI, if statement would go in the “but only if” part of the rule.

With the other languages you also have the option and actually disabling the rule, but like with the Item approach, you’ll need another rule that triggers on state changes of the Thing and enables/disables the rule accordingly. But with this approach in the UI, you wouldn’t even need any code at all.