Simulate, debug, test rules

Dear openhab community,

the more I play around with openhab and the more devices I integrate, the happier I get about this great opensource software! Thanks again for this great piece of immense work!!!

Quick question:
I integrated today a rule to trigger an outdoor switch as soon as dusk starts.
How can I trigger the even for this astro binding for instance to debug and troubleshoot the rule when I am implementing it? Is there any guide, anything I oversaw on how to debug and test rules and things that one freshly implements?

Thanks, Best

No there’s no such guide.
You should 1) enable debugging for rules to see if there’s syntax errors (reported in openhab.log if so),
2) insert logDebug() lines in your rules to see if processing reaches them
3) you can use smarthome:send item state from Karaf console to artificially create events to trigger your rules you want to test. You can also add more astro things or trigger channels through Karaf, see Rule not firing - sun setting (thanks @Dim for the pointer).

1 Like

To test rules I add a testSwitch item that I have defined in a special testing.items

Switch testSwitch

Then I have this switch on the sitemap and HABpanel to trigger the rule

Hi @mstormi,

the rule I would like to test triggers for an event called from a channel:

Channel 'astro:sun:local:civilDawn#event' triggered END 
then ...

thanks to your link, I triggered it manually and it worked. But I don´t know why it didn´t work today when the event should have been sent. How can I debug to see wether this even was even sent by the channel, maybe that´s the problem?

That is great if you need to debug the content of the rule but not the trigger condition itself… you could even define a time to trigger the rule, that´s what I normally do…

You can add a logInfo statement to your rule
Also, the Astro binding logs by default to events.log the ChannelTriggeredEvent (START & END)

Hmm it said in the item that civilDusk should have started at 16:38 but I did not find any event log from 16:38 to 16:39 containing this astro binding. Is there any other way to see why this thing isn`t triggering correctly?

do you get a log entry in events.log if you trigger it manually?
I may be wrong about the default log behavior (it’s actually a smarthome event, not a binding event)

Hi Dim,

when I triggered it manually it worked but it seemed that the event was not triggered automatically.

By chance I spotted that where I copied it from ’ ’ these were used to call up the channel name. I found that it should be " " and now it works.

Why did the correcting function inside visual studio did not detect it? These things are sooo hard to spot, really…

strange… if you use (normal apostrophe)
it screams:

if you use ' (typewriter apostrophe) it doesn’t scream :slight_smile:

both are wrong of course :slight_smile:

Ps: How to use code fences to avoid these kind of problems when posting in this forum

1 Like

Thanks Dim!

1 Like