# Got errors on my rule

**URL:** <https://community.openhab.org/t/got-errors-on-my-rule/121794>\
**Category:** Scripts & Rules\
**Created:** [May 3, 2021, 8:37am UTC](https://community.openhab.org/t/got-errors-on-my-rule/121794 "2021-05-03T08:37:43Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![ROS](https://community.openhab.org/letter_avatar_proxy/v4/letter/r/ebca7d/32.png) [@ROS](https://community.openhab.org/u/ROS)\
**Post date:** [May 3, 2021, 8:37am UTC](https://community.openhab.org/t/got-errors-on-my-rule/121794/1 "2021-05-03T08:37:43Z")

</div>

Hi!

I got errors on my rules. I have tried this on openhab2.5 and openhab3 on pi4.  
rule “Ute\_Temperatur\_Kompensasjon”

Here is the log:

2021-05-03 10:20:47.278 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘rule\_varmekasett’ failed: \_\_\_ rule \_\_\_ “Ute\_Temperatur\_Kompensasjon”

when  
Item energi\_EN\_UteTemperatur received up \_\_\_ date  
then  
var ten= 0.0  
var ute = (energi\_EN\_UteTemperatur.state as DecimalType).doubleValue  
var tto = ((21- ute) \* 0.5) .doubleValue  
var temp = 0.0

if (ute \>= 21) {  
temp = (5) .doubleValue  
}  
else if (ute \>= 11) {  
temp = (tto + 21) .doubleValue  
}  
else if (ute \>= 0) {  
ten = (11 - ute) .doubleValue  
tto = (ten \* 0.82) .doubleValue  
temp = (tto + 26) .doubleValue  
}  
else if(ute \< 0) {  
ten = (ute \* -1).doubleValue  
tto = (ten \* 0.2).doubleValue  
temp = (tto + 35) .doubleValue  
}   
if (temp \> 45) { temp = 45}  
postUpdate(temperature\_VK\_SP\_Inn, temp)  
end

1. The method or field rule is undefined; line 1, column 0, length 4
2. The method or field when is undefined; line 2, column 35, length 4
3. The method or field received is undefined; line 3, column 73, length 8
4. The method or field update is undefined; line 3, column 82, length 6
5. The method or field then is undefined; line 4, column 91, length 4
6. The method or field end is undefined; line 28, column 675, length 3
7. This expression is not allowed in this context, since it doesn’t cause any side effects.; line 1, column 5, length 29
8. This expression is not allowed in this context, since it doesn’t cause any side effects.; line 3, column 44, length 4
9. This expression is not allowed in this context, since it doesn’t cause any side effects.; line 3, column 49, length 23

I dont know where to start since I got the error on the first line.

I tried a simple rule from the documentation, and the same happened.

Rune

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [May 3, 2021, 9:19am UTC](https://community.openhab.org/t/got-errors-on-my-rule/121794/2 "2021-05-03T09:19:25Z")

</div>

Where are you placing this rule?

> [@ROS](#):
>
> I tried a simple rule from the documentation, and the same happened.

Troubleshoot the simple rule, instead of your complex one.

---

<div class="post-metadata">

**Author:** ![ROS](https://community.openhab.org/letter_avatar_proxy/v4/letter/r/ebca7d/32.png) [@ROS](https://community.openhab.org/u/ROS)\
**Post date:** [May 3, 2021, 10:51am UTC](https://community.openhab.org/t/got-errors-on-my-rule/121794/3 "2021-05-03T10:51:42Z")

</div>

Hi rossko57.

I am using the UI and make it under script.

ROS

---

<div class="post-metadata">

**Author:** ![ROS](https://community.openhab.org/letter_avatar_proxy/v4/letter/r/ebca7d/32.png) [@ROS](https://community.openhab.org/u/ROS)\
**Post date:** [May 3, 2021, 10:57am UTC](https://community.openhab.org/t/got-errors-on-my-rule/121794/4 "2021-05-03T10:57:37Z")

</div>

Here is one from the documentation

2021-05-03 12:55:28.928 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘test1’ failed: var Number counter  
rule “startup”  
when  
System stated  
then  
counter = 0  
end

1. The method or field rule is undefined; line 2, column 19, length 4
2. The method or field when is undefined; line 3, column 36, length 4
3. The method or field stated is undefined; line 4, column 52, length 6
4. The method or field then is undefined; line 5, column 61, length 4
5. The method or field end is undefined; line 7, column 82, length 3
6. This expression is not allowed in this context, since it doesn’t cause any side effects.; line 2, column 24, length 9
7. This expression is not allowed in this context, since it doesn’t cause any side effects.; line 4, column 45, length 6

and the same happens here.

ROS

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [May 3, 2021, 11:15am UTC](https://community.openhab.org/t/got-errors-on-my-rule/121794/5 "2021-05-03T11:15:13Z")

</div>

> [@ROS](#):
>
> I am using the UI and make it under script.

Don’t paste complete example rules meant for `xxx.rules` file format into the UI rules editor.  
See -

> [@Help needed with rule in Openhab3](https://community.openhab.org/t/help-needed-with-rule-in-openhab3/121780):
>
> Hi guys and gals, Is this me or could this be a bug? I’m having trouble getting this ‘virtual thermostat’ rule to work in OpenHab3. I have a small Infrared heating panel in my office, controled with a tradfri on/off switch. I also have a nodemcu that gives me the temperature over mqtt. Since i’m relatively new to Openhab, to get me going i searched and found a script on this forum and adapted it to my needs. I created all the necessary things and stuff in the sitemap but it just will not work.…

Only the part between, but not including, “then” and “end” belongs in a UI script section.

---

<div class="post-metadata">

**Author:** ![ROS](https://community.openhab.org/letter_avatar_proxy/v4/letter/r/ebca7d/32.png) [@ROS](https://community.openhab.org/u/ROS)\
**Post date:** [May 3, 2021, 1:35pm UTC](https://community.openhab.org/t/got-errors-on-my-rule/121794/6 "2021-05-03T13:35:59Z")

</div>

Hi rossko57.

That helped a lot 🙂

---

<div class="post-metadata">

**Author:** ![ROS](https://community.openhab.org/letter_avatar_proxy/v4/letter/r/ebca7d/32.png) [@ROS](https://community.openhab.org/u/ROS)\
**Post date:** [May 4, 2021, 2:16pm UTC](https://community.openhab.org/t/got-errors-on-my-rule/121794/7 "2021-05-04T14:16:07Z")

</div>

Hi.  
I stil got problems.  
2021-05-04 16:02:47.916 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘test’ failed: var ten = 0.0  
var ute = KNXDevice\_Energi\_EN\_UteTemperatur  
var tto = ((21.0 - ute) \* 0.5)  
Type mismatch: cannot convert from NumberItem to byte; line 3, column 77, length 3

How do I get the right number type?  
The KNX device give me the temperature and then I shall make som calculations.

I am running OH1 today, it have been running for 5 years without problem.  
I having a new Raspberry PI 4 for OH 3.

This is the rule in OH 1 that I try to run on OH 3:

rule “Ute Temperatur Kompensasjon”  
when  
Item energi\_EN\_UteTemperatur received update or System started  
then  
var double ten = 0  
var double ute = (energi\_EN\_UteTemperatur.state as DecimalType).doubleValue  
var double tto = ((21- ute) \* 0.5) .doubleValue  
var double temp = 0  
if (ute \>= 21) {  
temp = (5) .doubleValue  
}  
else if (ute \>= 11) {  
temp = (tto + 21) .doubleValue  
}  
else if (ute \>= 0) {  
ten = (11 - ute) .doubleValue  
tto = (ten \* 0.82) .doubleValue  
temp = (tto + 26) .doubleValue  
}  
else if(ute \< 0) {  
ten = (ute \* -1).doubleValue  
tto = (ten \* 0.2).doubleValue  
temp = (tto + 35) .doubleValue  
}  
if (temp \> 45) { temp = 45}  
postUpdate(temperature\_VK\_SetPunkt, temp);  
end

ROS

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [May 4, 2021, 2:25pm UTC](https://community.openhab.org/t/got-errors-on-my-rule/121794/8 "2021-05-04T14:25:06Z")

</div>

> [@ROS](#):
>
> var ute = KNXDevice\_Energi\_EN\_UteTemperatur

That would never have worked in OH1 either.  
Aren’t you interested in that Item’s **state**?

---

<div class="post-metadata">

**Author:** ![ROS](https://community.openhab.org/letter_avatar_proxy/v4/letter/r/ebca7d/32.png) [@ROS](https://community.openhab.org/u/ROS)\
**Post date:** [May 4, 2021, 3:53pm UTC](https://community.openhab.org/t/got-errors-on-my-rule/121794/9 "2021-05-04T15:53:27Z")

</div>

I changes line 2 to be equal the one in OH1:  
var double ute = (KNXDevice\_Energi\_EN\_UteTemperatur.state as DecimalType).doubleValue

I got this error:  
2021-05-04 17:50:47.581 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘test’ failed: Could not cast 8.5 °C to org.openhab.core.library.types.DecimalType; line 2, column 19, length 54

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [May 4, 2021, 4:03pm UTC](https://community.openhab.org/t/got-errors-on-my-rule/121794/10 "2021-05-04T16:03:02Z")

</div>

Your Item is not the same type that it was in OH1.  
You have a Number:Temperature type now.

> [@Working with Number:Temperature Items in rules](https://community.openhab.org/t/working-with-number-temperature-items-in-rules/116197):
>
> openHAB provides Quantity Type features, which can seem baffling. On top of that, Temperature type Quantities have a few quirks all of their own. These notes intend to guide the rules author. I’ve shown work examples in DSL rules language, see below for other scripts examples. All have similar features, if different syntax. Knowing what can be done is half the battle. What is a Quantity Type? Simply, Item states and rule variables may contain Quantities - that just means a number AND a unit …

---

<div class="post-metadata">

**Author:** ![ROS](https://community.openhab.org/letter_avatar_proxy/v4/letter/r/ebca7d/32.png) [@ROS](https://community.openhab.org/u/ROS)\
**Post date:** [May 4, 2021, 4:11pm UTC](https://community.openhab.org/t/got-errors-on-my-rule/121794/11 "2021-05-04T16:11:42Z")

</div>

Thanks.

I changed to:  
var ute = (KNXDevice\_Energi\_EN\_UteTemperatur.state as QuantityType).toBigDecimal

and no errors, yet 🙂

---

<div class="post-metadata">

**Author:** ![ROS](https://community.openhab.org/letter_avatar_proxy/v4/letter/r/ebca7d/32.png) [@ROS](https://community.openhab.org/u/ROS)\
**Post date:** [May 4, 2021, 4:56pm UTC](https://community.openhab.org/t/got-errors-on-my-rule/121794/12 "2021-05-04T16:56:16Z")

</div>

I am getting closer.

This is the code now:

var ute = (KNXDevice\_Energi\_EN\_UteTemperatur.state as QuantityType).toBigDecimal  
var tto = ((21.0 - ute) \* 0.5)  
var temp = 0.0  
var ten = 0.0  
if (ute \>= 21) {temp = 5.0}  
else if (ute \>= 11) {temp = tto + 21.0}  
else if (ute \>= 0) {  
ten = (11.0 - ute)  
tto = ten \* 0.82  
temp = tto + 26  
}  
else if (ute \< 0) {  
**ten = ute \* -1.0**  
“for this line I get this error:  
Type mismatch: cannot convert from BigDecimal to double; line 13, column 326, length 10”  
tto = ten \* 0.2  
temp = tto + 35  
}  
if (temp \> 45) {temp = 45}

---

<div class="post-metadata">

**Author:** ![ROS](https://community.openhab.org/letter_avatar_proxy/v4/letter/r/ebca7d/32.png) [@ROS](https://community.openhab.org/u/ROS)\
**Post date:** [May 4, 2021, 4:58pm UTC](https://community.openhab.org/t/got-errors-on-my-rule/121794/13 "2021-05-04T16:58:55Z")

</div>

> [@ROS](#):
>
> var ute = (KNXDevice\_Energi\_EN\_UteTemperatur.state as QuantityType).toBigDecimal  
> var tto = ((21.0 - ute) \* 0.5)  
> var temp = 0.0  
> var ten = 0.0  
> if (ute \>= 21) {temp = 5.0}  
> else if (ute \>= 11) {temp = tto + 21.0}  
> else if (ute \>= 0) {  
> **ten = (11.0 - ute)**  
> **Sorry, it was here**

I hope it is no problem.

---

<div class="post-metadata">

**Author:** ![ROS](https://community.openhab.org/letter_avatar_proxy/v4/letter/r/ebca7d/32.png) [@ROS](https://community.openhab.org/u/ROS)\
**Post date:** [May 5, 2021, 9:21am UTC](https://community.openhab.org/t/got-errors-on-my-rule/121794/14 "2021-05-05T09:21:04Z")

</div>

Hi rossko57

When I have this code : **ten = ute \* -1.0**  
I get this eror:  
Type mismatch: cannot convert from BigDecimal to double; line 16, column 350, length 10

When I write it like this: **ten = -1.0 \* ute** no error and everything is working.

Can there be a bug here?

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [May 5, 2021, 9:38am UTC](https://community.openhab.org/t/got-errors-on-my-rule/121794/15 "2021-05-05T09:38:32Z")

</div>

> [@ROS](#):
>
> Can there be a bug here?

No, it’s just DSL rules being picky about types.  
When it sees an expression like  
**ute \* -1.0**  
there are no types, it has to guess what to use.  
First thing it finds is variable `ute`, earlier on that was declared as a BigDecimal type, so that’s what it will try to use to evaluate the expression.  
Next is the operator -, minus, that’s okay it can do minus with a BigDecimal.  
Next is the text “1.0”, the rules interpreter defaults to parsing that as a double type.  
Oh dear, types don’t match, have to do a conversion - it tries BigDecimal to double which doesn’t work (that’s a curious Java omission).

Written the other way  
**-1.0 \* ute**  
the types come up in a different order, and a double to BigDecimal works okay.

In _general_ in DSL it is best to not type things and let the interpreter sort it out. But sometimes you just have to play with types in these situations.
