# \[SOLVED\] Ultimate guide to debugging rules?

**URL:** <https://community.openhab.org/t/solved-ultimate-guide-to-debugging-rules/50921>\
**Category:** Scripts & Rules\
**Created:** [September 6, 2018, 8:47am UTC](https://community.openhab.org/t/solved-ultimate-guide-to-debugging-rules/50921 "2018-09-06T08:47:27Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![vzorglub](https://community.openhab.org/user_avatar/community.openhab.org/vzorglub/32/17166_2.png) [@vzorglub](https://community.openhab.org/u/vzorglub)\
**Post date:** [September 6, 2018, 9:06am UTC](https://community.openhab.org/t/solved-ultimate-guide-to-debugging-rules/50921/2 "2018-09-06T09:06:50Z")

</div>

Ok,

First of all, please use the code fences when publishing code

> [@How to use code fences](https://community.openhab.org/t/how-to-use-code-fences/38383):
>
> We all have to type this content over and over and over. Here is a posting we can all point to when the topic comes up. Why use code fences? Because rules, sitemap, logs, and configs are all but unreadable when code fences are not used. When to use code fences? Whenever one is posting any sort of code, config, log, and any text where line wrapping, indentation, and using an equal spaced font makes the text more legible. How to use code fences? Use 3 backticks (```)... Or use \<code\>... …

You rules is:

```php
rule "Oppvask"
when
Item OppvaskProgramStatus changed
then
logDebug("Oppvask","Rule running!")
if (OppvaskProgramStatus is "Off") {
KjokkenPanel.postUpdate("Huset")
logDebug("Oppvask","HUSET chosen")
}
else {
KjokkenPanel.postupdate("HusOppvask")
logDebug("Oppvask","Oppvask chosen")
}
end

```

Which is untidy, use indents:  
To see message in the log use logInfo if your logging is not set to debug.  
Use `==`, `is` is NOT a keywork.  
Put a space after commas, it makes the code easier to read.  
The state of an item can be obtained with `.state`. Putting just the name of the item refers to the item object itself.  
Add a `logInfo` line to check the value of `OppvaskProgramStatus`.  
Add a check if the value is NULL and do nothing in that case.

```php
rule "Oppvask"
when
    Item OppvaskProgramStatus changed
then
    logInfo("Oppvask", "Rule running!")
    logInfo("Oppvask", "Status is: " + OppvaskProgramStatus.state.toString)
    if (OppvaskProgramStatus.state == NULL) return; //Do nothing if changed to NULL
    if (OppvaskProgramStatus.state == "Off") {
        KjokkenPanel.postUpdate("Huset")
        logInfo("Oppvask", "HUSET chosen")
    }
    else {
        KjokkenPanel.postUpdate("HusOppvask")
        logInfo("Oppvask", "Oppvask chosen")
    }
end

```

---

_[View the full topic](https://community.openhab.org/t/solved-ultimate-guide-to-debugging-rules/50921)._
