Rules Emulator

Out of curiosity -

Has there ever been any thought of creating a sandbox or rules emulator where you could test your rules before adding them into your production environment?

I sure would love the ability to test my rules and make sure they are pulling the right data back without having to add them into my online/production system.

I’d like to test my IF statements and see if they are indeed pulling what I think they will. If I could run those statements and see what they return in that same window my debugging time will vastly improve.

Just a late night thought.

1 Like


There are many ways to test your rules. I see some people running a separate OpenHAB environment with some of their bindings being disabled.

For me, that is a bit of overkill.

If I want to experiment, I work with:

  • A dedicated item/rules-file (test.items / test.rules);
  • Add “loginfo” at strategic places in my rules, so I can check what values my variables/items get in what circumstances.
  • In cases where my testing is not allowed to have a real-world impact (e.g. checking if an alarm is triggered), I temporarily comment/remove the binding information in the .items file.
  • I also work with a dummy-trigger. A switch item called “trigger test rule”, that I have also included in my test.sitemap. This allows me to trigger a rule without waiting for real-world conditions to be in the right circumstances;

Not sure if all of this is best practice, but it works for me.

Just run a local installation of OH on your desktop or notebook. That is my test environment.

Unfortunately I thing by the time you have emulated everything needed (event bus, persistence, etc) you would end up with something as be and complex as OH itself. So one may as well run a test oh instance.

I personally don’t trust home automation on general enough to put anything all that important on my OH so I just test on the line production system. If I break something it’s no big deal.

I appreciate all of the suggestions - but I still think it would be great if there were some type of interactive window/terminal where I could query states and other items and see what OH would return.

For example, if I have a rule that is based on an items state I could check to make sure I am pulling the state correctly

if (CoffeeStatus.state.toString == "RefillWater")

It would be great if I could querry:


And see what OH is returning…

That way I’m not needing to add logging and bounce back and forth between rule files, log files. etc.

You mean like the Karaf Console?

True. But I think that would cost precious times of the OpenHAB geniuses that are currently working on other OH stuff.

I would just use a rule:

rule "test"

    Item  TEST_Trigger changed from OFF to ON
	logInfo("Test rule","Test rule triggered")
	logInfo("Test rule","Coffeestatus = " + CoffeeStatus.state.toString)

I have one basic test rule, and keep changing it now and then, depending on what I want to check.

Also, all item state changes are loved in the events.log so you can see your items changing states there. No need for rules.

And one thing I do is keep an admin/debug sitemap that has all my items on it if I want to check the current state of anything.

So can I querry the console with


And have it return it’s state?

I looked at the link you provided but didn’t see any reference to checking state

Try “smarthome:status CoffeeStatus”. I don’t think you need .state.toString in the console. Type help into the console and it will list out all the commands. You can send commands to items, updates, and much more.

Sorry one more edit: has all the documentation on runtime commands.

smarthome:status shows the current status of an item

That should probably be reworded as it’s state. But this is the commands you are looking for. The relevant section:

Hello Guys

At first: You all are so right.
It is depending on your needs.

The easiest way of a ‘quick and dirty’ in test are test files, and test items.

If your scenario is a little bit more complex, you can install a dev environment.

A very nearly version of all would be to clone and or snapshot your productive installation…

IT all depends on on your needs, skills and resources.

I’ve been thinking about setting up a dev system with custom *.items files. In these custom items files I will then configure the items using the MQTT binding. That way I can test and debug my rules and see the results without actually triggering scenes, moving shutters up/down, lights turning on/off, triggering scenes, etc.