Migration OH 2.5 -> 3.2 rules

heyho
ive got an issue during the migration from oh2.5 to 3.2.
im too stupid to convert some of my rules to the new engine

val stark = ShellyStarke80.state as Number //(this item is a group)
val starkgt = 64
val wer = triggeringItem.name                          
starkhoch80.sendCommand(wer)
if(starkgt <= stark)
{
val wer = triggeringItem.name
mailstarke80.sendCommand(ON)
starkhoch80.sendCommand(wer)
}
if(starkgt > stark)
{
mailstarke80.sendCommand(OFF)
}

the error i get is:

 Duplicate local variable wer; line 7, column 146, length 3
2022-01-24 15:05:48.103 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'e525c8d5c7' failed: val stark = ShellyStarke80

no matter what i try, i cant get it working…
help anyone? :slight_smile:
thanks

Duplicate local variable on line 7?

there are none
where?

val wer = triggeringItem.name

What happens if you use another name on line 7?

nothing helpfull

2022-01-24 16:09:32.529 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'e525c8d5c7' failed: <eval>:1:4 Expected ; but found stark
val stark = ShellyStarke80.state as Number
    ^ in <eval> at line number 1 at column number 4

i thinks its something with the way the rule engine works
might be new syntax, idk. i read through the documentation but didnt find a solution…

You did define two times var wer, once outside your if, once inside, both with the same content, not sure what’s the reason as it will be the same.

but it did work in 2.5 without issues

Fair enough, still does not really look useful (with limited knowledge of your rule).
Nevertheless that’s only your first line, the other error points to your first Code var.
How is your group item defined? Is it a number type?

Are you copy-pasting a rule from a file into the GUI rules entry?
Please use the GUI code tab, to show us the whole structure.

i copy-paste the execution-part of the rule from oh 2.5 to the script part int he ui of oh 3.2
the whole rule looks like that in oh2.5

rule "shellystark80"
when
Member of ShellyStarke80 changed
then
val stark = ShellyStarke80.state as Number
val starkgt = 64
val wer = triggeringItem.name
starkhoch80.sendCommand(wer)
if(starkgt <= stark)
{
val wer = triggeringItem.name
mailstarke80.sendCommand(ON)
starkhoch80.sendCommand(wer)
}
if(starkgt > stark)
{
mailstarke80.sendCommand(OFF)
}
end

taking only the execution-part thats what the rule looks like in 3.2

configuration: {}
triggers:
  - id: "1"
    configuration:
      groupName: ShellyStarke80
    type: core.GroupStateUpdateTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/javascript
      script: |-
        val stark = ShellyStarke80.state as Number
        val starkgt = 64
        val wer2 = triggeringItem.name
        starkhoch80.sendCommand(wer2)
        if(starkgt <= stark)
        {
        val wer2 = triggeringItem.name
        mailstarke80.sendCommand(ON)
        starkhoch80.sendCommand(wer2)
        }
        if(starkgt > stark)
        {
        mailstarke80.sendCommand(OFF)
        }
    type: script.ScriptAction

p.s. i changed the var wer to wer2 just for testing purpose

But your rule is/was in DSL language.

F**K im blind / stupid…

back to the original issue :smiley:
i jsut remove the second declaration and thats it i guess

2022-01-24 16:45:04.531 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'e525c8d5c7' failed: val stark = ShellyStarke80.state as Number
val starkgt = 60
val wer2 = triggeringItem.name
starkhoch80.sendCommand(wer2)
if(starkgt <= stark)
{
val wer2 = triggeringItem.name
mailstarke80.sendCommand(ON)
starkhoch80.sendCommand(wer2)
}
if(starkgt > stark)
{
mailstarke80.sendCommand(OFF)
}
   Duplicate local variable wer2; line 7, column 148, length 4

Well, yes. Are you going to fix it? The second val wer2 seems completely pointless.

yep thats it… removing the second declaration did the trick…
im awfull at spotting own mistakes :sweat_smile: thanks :heart: