Simulate, debug, test rules

rule
test
debug
Tags: #<Tag:0x00007fe066266350> #<Tag:0x00007fe066267d90> #<Tag:0x00007fe066267c28>

(Klim Bim) #1

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
Klim


(Markus Storm) #2

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).


(Vincent Regaud) #3

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
Simples!!


(Klim Bim) #4

Hi @mstormi,

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

when
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…


(Angelos) #5

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


(Klim Bim) #6

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?


(Angelos) #7

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)


(Klim Bim) #8

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…


(Angelos) #9

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

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

both are wrong of course :slight_smile:

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


(Klim Bim) #10

Thanks Dim!