OH3 - Global Variables in DSL-Rules - Error on start

I copied a DSL-Rule from my OH2-Setup to OH3-M5.

When I start OH3-M5 I get the following Error-Message in the Log:

2020-12-06 22:27:45.745 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'astro-1' failed: a != java.lang.String in astro

But after that the Rule triggers normal, as I can see in the Log:

2020-12-06 22:27:50.531 [INFO ] [hab.core.model.script.astro-rules_99] -  Moondistance updated every 5 Minutes by "astro.things " 2020-12-06T22:27:50.285+0100 / 1 Log every 2 hours

The Rule is:

var Number count=1
var Number mooncount=0

rule "moondistances"
    when
//        Item Dummy4x changed to ON or
        Item Date_distance changed      // Item defined in astro.items  and changed every five minutes(300 sec.) by astro.things
    then
        Date_Kilometer_actual.postUpdate(Date_distance.state.format("%1$ta, %1$td.%1$tb. ") + " / " + Kilometer_distance.state.format("%,.0f km").toString)
        Date_Kilometer_perigee.postUpdate(Date_perigee.state.format("%1$ta, %1$td.%1$tb. ") + " / " + Kilometer_perigee.state.format("%,.0f km").toString)
        Date_Kilometer_apogee.postUpdate(Date_apogee.state.format("%1$ta, %1$td.%1$tb. ") + " / " + Kilometer_apogee.state.format("%,.0f km").toString)
        mooncount = mooncount + 1
        if (mooncount == 1 ) {   //Log every 2 hours - just to inform that rule is still alive
            logInfo("astro-rules" + '_99'," Moondistance updated every 5 Minutes by \"astro.things \" " + Date_distance.state + " / " + mooncount + " Log every 2 hours")
        }
        if (mooncount >= 24) {       //refresh counter
            mooncount = 0
       }
end

and the OH3-Code looks:

triggers:
  - id: "0"
    configuration:
      itemName: Date_distance
    type: core.ItemStateChangeTrigger
conditions: []
actions:
  - inputs: {}
    id: script
    configuration:
      type: application/vnd.openhab.dsl.rule
      script: >
        // context: astro-1

        Date_Kilometer_actual.postUpdate(Date_distance.state.format("%1$ta, %1$td.%1$tb. ") + " / " + Kilometer_distance.state.format("%,.0f km").toString)

        Date_Kilometer_perigee.postUpdate(Date_perigee.state.format("%1$ta, %1$td.%1$tb. ") + " / " + Kilometer_perigee.state.format("%,.0f km").toString)

        Date_Kilometer_apogee.postUpdate(Date_apogee.state.format("%1$ta, %1$td.%1$tb. ") + " / " + Kilometer_apogee.state.format("%,.0f km").toString)

        mooncount = mooncount + 1

        if (mooncount == 1 ) {   //Log every 2 hours - just to inform that rule is still alive
            logInfo("astro-rules" + '_99'," Moondistance updated every 5 Minutes by \"astro.things \" " + Date_distance.state + " / " + mooncount + " Log every 2 hours")
        }

        if (mooncount >= 24) {       //refresh counter
            mooncount = 0
               }
    type: script.ScriptAction

I think that the Declaration and Initialization of the global variables is the problem. But I don’t know how to solve.

Sorry guys, I found the reason for the problem by myself.
As one says “mostly the failure sits in front of the screen” :shushing_face:
The reason was that I have declared the variable “count” but not used in the script.
So please be indulgent with me. :wink:

Cheers
Peter

1 Like