Roller automation - problem with HashMap in a lambda function - remove, get, put is not a member of java.util.HashMap

Hello All,

First of all I am pretty impressed with OH.
Based on the examples I tried to create a roller automation. The HW setup is (only for background)
2 relays connected sequentially, the first is on/off the second is direction (up/down).
The actual direction for the second relay (on/off as NC or NO) depends on whether left / right mount on the roller.
I have to pass the defaults for up/down/off state for the 2nd relay.

Everything works fine except the hashmaps, whenever I try to access its member functions I got the error
‘get’ is not a member of ‘java.util.HashMap’

import org.eclipse.xtext.xbase.lib.*

// see https://github.com/openhab/openhab1-addons/wiki/Reusable-Rules-via-Functions as initial code idea                                                                                                    
// total runtime of the rollershutters                                                                                                                                                                      
val int ROLLER_TIMEOUT = 20

// timers to switch it off after the timeout                                                                                                                                                                
val java.util.Map<String, org.openhab.model.script.actions.Timer> rollerTimers = newHashMap

// lambda expression that can be used as a function (here: with 6 parameters)                                                                                                                               
//val org.eclipse.xtext.xbase.lib.Functions$Function6 rollerLogic = [                                                                                                                                       
//org.openhab.core.library.items.SwitchItem relayItem,                                                                                                                                                      
val Functions$Function6 rollerLogic = [
    String roller_command,
    String relayStates,
    SwitchItem relayItem,
    SwitchItem relayItemUpDown,
    org.openhab.model.script.actions.Timer timers,
    int timeout |
           logInfo("Roller", "CMD " + roller_command + relayItem.name)
           logInfo("Roller", "R1: " + relayItem.toString())
           logInfo("Roller", "R2:"  + relayItemUpDown.toString())
           logInfo("Roller", "R1 state" + relayItem.state)
           logInfo("Roller", "R2 state" + relayItemUpDown.state)
           //logInfo("Roller", "state " + relayStates.split("/").get(0))                                                                                                                                    
           logInfo("Roller", "UP: " + relayStates.split("/").get(0) + "DOWN: " + relayStates.split("/").get(1) + " Default: " + relayStates.split("/").get(2))
           if (roller_command == "STOP"){
               logInfo("Roller", "STOP")
               if (relayItem.state == ON) relayItem.sendCommand(OFF)
               if (relayItemUpDown.state != relayStates.split("/").get(2))  relayItemUpDown.sendCommand(relayStates.split("/").get(2))
               // remove timer from map because nothing is ON anymore                                                                                                                                       
               timers.remove(relayItem.name)                                                                                                                                                                
           }                                                                                                                                                                                                
           if (roller_command == "UP"){
               logInfo("Roller", "UP")
              if (relayItemUpDown.state != relayStates.split("/").get(0)) relayItemUpDown.sendCommand(relayStates.split("/").get(0))
              if (relayItem.state == OFF) relayItem.sendCommand(ON)
              // if there is already a timer, cancel it                                                                                                                                                     
              timers.get(relayItem.name)?.cancel
              // now create a new timer for switching off                                                                                                                                                   
              timers.put(relayItem.name, createTimer(now.plusSeconds(timeout)) [|
                                   logInfo("RollerTimer", "UP")
                                   // switch it off afterwards, if it is not already off                                                                                                                    
                                   if (relayItem.state == ON) relayItem.sendCommand(OFF)
                                   if (relayItemUpDown != relayStates.split("/").get(2))  relayItemUpDown.sendCommand(relayStates.split("/").get(2))
                                   // remove timer from map because nothing is ON anymore                                                                                                                   
                                   timers.remove(relayItem.name)
                                ])
           }
           if (roller_command == "DOWN"){
               logInfo("Roller", "DOWN")
              if (relayItemUpDown.state != relayStates.split("/").get(1)) relayItemUpDown.sendCommand(relayStates.split("/").get(1))
              if (relayItem.state != ON ) relayItem.sendCommand(ON)
              // if there is already a timer, cancel it                                                                                                                                                     
              timers.get(relayItem.name)?.cancel
              // now create a new timer for switching off   
              // now create a new timer for switching off                                                                                                                                                   
              timers.put(relayItem.name, createTimer(now.plusSeconds(timeout)) [|
                                   logInfo("RollerTimer", "UP")
                                   // switch it off afterwards, if it is not already off                                                                                                                    
                                   if (relayItem.state == ON) relayItem.sendCommand(OFF)
                                   if (relayItemUpDown != relayStates.split("/").get(2))  relayItemUpDown.sendCommand(relayStates.split("/").get(2))
                                   // remove timer from map because nothing is ON anymore                                                                                                                   
                                   timers.remove(relayItem.name)
                                ])
           }
           if (roller_command == "DOWN"){
               logInfo("Roller", "DOWN")
              if (relayItemUpDown.state != relayStates.split("/").get(1)) relayItemUpDown.sendCommand(relayStates.split("/").get(1))
              if (relayItem.state != ON ) relayItem.sendCommand(ON)
              // if there is already a timer, cancel it                                                                                                                                                     
              timers.get(relayItem.name)?.cancel
              // now create a new timer for switching off                                                                                                                                                   
              timers.put(relayItem.name, createTimer(now.plusSeconds(timeout)) [|
                                   logInfo("RollerTimer", "DOWN")
                                   // switch it off afterwards, if it is not already off                                                                                                                    
                                   if (relayItem.state == ON) relayItem.sendCommand(OFF)
                                   if (relayItemUpDown.state != relayStates.split("/").get(2))  relayItemUpDown.sendCommand(relayStates.split("/").get(2))
                                   // remove timer from map because nothing is ON anymore                                                                                                                   
                                   timers.remove(relayItem.name)
                                ])
           }
]



rule "Roller Guestroom"
    when
        Item rsGuestroom received command
    then
        rollerLogic.apply(receivedCommand.toString(), "ON/OFF/OFF", roller_guestroom_on, 
        roller_guestroom_updown, rollerTimers, 5)
end

Any help / hints are highly appreciated.

Br,
/r

Seems like a mismatch in the argument declaration, now it works, so question is obsoleted :slight_smile:

@Robert_Szabo
Could you publish the final code that work, to help with users that may come across the same problem, please?