Uponor Smatrix binding request

This should work:

import java.util.HashMap

val numRooms = 6
val numModules = 1

val Procedures$Procedure3<List, Integer, Integer> processRequest = [ itemQueryList, roomNumber, moduleNumber |
    val HashMap<String, String> idMap = newHashMap(
        "20" -> "module_id",
        "21" -> "cooling_available",
        "22" -> "holiday_mode",
        "23" -> "forced_eco_mode",
        "24" -> "hc_mode",
        "25" -> "hc_masterslave",
        "26" -> "ts_sv_version",
        "27" -> "holiday_setpoint",
        "28" -> "average_temp_low",
        "29" -> "low_temp_alarm_limit",
        "30" -> "low_temp_alarm_hysteresis",
        "31" -> "remote_access_alarm",
        "32" -> "device_lost_alarm",
        "33" -> "no_comm_controller1",
        "34" -> "no_comm_controller2",
        "35" -> "no_comm_controller3",
        "36" -> "no_comm_controller4",
        "37" -> "average_room_temperature",
        "38" -> "controller_presence",
        "39" -> "allow_hc_mode_change",
        "40" -> "hc_master_type",

        "60" -> "output_module",
        "61" -> "rh_deadzone",
        "62" -> "controller_sv_version",
        "63" -> "thermostat_presence",
        "64" -> "supply_high_alarm",
        "65" -> "supply_low_alarm",
        "66" -> "average_room_temperature_NO",
        "67" -> "measured_outdoor_temperature",
        "68" -> "supply_temp",
        "69" -> "dehumidifier_status",
        "70" -> "outdoor_sensor_presence",

        "80" -> "eco_profile_active_cf",
        "81" -> "dehumidifier_control_activation",
        "82" -> "rh_control_activation",
        "83" -> "eco_profile_number",
        "84" -> "setpoint_write_enable",
        "85" -> "cooling_allowed",
        "86" -> "rh_setpoint",
        "87" -> "min_setpoint",
        "88" -> "max_setpoint",
        "89" -> "min_floor_temp",
        "90" -> "max_floor_temp",
        "91" -> "room_setpoint",
        "92" -> "eco_offset",
        "93" -> "eco_profile_active",
        "94" -> "home_away_mode_status",
        "95" -> "room_in_demand",
        "96" -> "rh_limit_reached",
        "97" -> "floor_limit_status",
        "98" -> "technical_alarm",
        "99" -> "tamper_indication",
        "100" -> "rf_alarm",
        "101" -> "battery_alarm",
        "102" -> "rh_sensor",
        "103" -> "thermostat_type",
        "104" -> "regulation_mode",
        "105" -> "room_temperature",
        "106" -> "room_temperature_ext",
        "107" -> "rh_value",
        "108" -> "ch_linked_to_th",
        "109" -> "room_name",
        "110" -> "utilization_factor_24h",
        "111" -> "utilization_factor_7d",
        "112" -> "reg_mode",
        "113" -> "channel_average",
        "114" -> "radiator_heating")

    val url = "http://<ip>/api"
    val contenttype = "application/json"
    var POSTrequest = '{"jsonrpc":"2.0", "id":8, "method":"read", "params":{ "objects":[%s]}}'
    val request = String.format(POSTrequest, itemQueryList.join(','))
    val json = sendHttpPostRequest(url, contenttype, request);
    val count = Integer::parseInt(transform("JSONPATH", "$.result.objects.length()", json));
    for(var i = 0; i < count; i++) {
        if (transform("JSONPATH", "$.result.objects[" +i+ "]", json).contains("value")) {
            val Number id = Integer::parseInt(transform("JSONPATH", "$.result.objects[" +i+ "].id", json))
            val value = transform("JSONPATH", "$.result.objects[" +i+ "].properties.85.value", json)

            var Number realId = id - (moduleNumber * 500) - (roomNumber * 40)
            val printString = "%1$-35s : %2$10s : %3$2d : %4$2d"
            val name = idMap.get("" + realId)
            logWarn("Uponor", String.format(printString, name, ""+value, roomNumber.intValue(), moduleNumber.intValue()))
        }
    }
]

rule "Read Uponor values 2"
when
    Time cron "0 0/1 * * * ?"
then
    val itemQuery = '{"id":"%s","properties":{"85":{}}}'
    val itemQueryList = newArrayList()
    //Add global keys to query
    for (var i = 20; i < 41; i++) {
        itemQueryList.add(String.format(itemQuery, i))
    }
    logWarn("Uponor", "************ Global values *****************")
    processRequest.apply(itemQueryList, 0, 0)
    //Add module keys to query
    for (var j = 0; j < numModules; j++) {
        itemQueryList = newArrayList()
        for (var i = 60; i < 71; i++) {
            itemQueryList.add(String.format(itemQuery, i + j*500))
        }
        logWarn("Uponor", "************ Module " + j + " values *****************")
        processRequest.apply(itemQueryList, 0, j)
    }


    //Query room keys
    for (var j = 0; j < numModules; j++) {
        for (var k = 0; k < numRooms; k++) {
            itemQueryList = newArrayList()
            for (var i = 80; i < 115; i++) {
                itemQueryList.add(String.format(itemQuery, i + k*40 + j*500))
            }
            logWarn("Uponor", "************ Room " + k + " and Module " + j + " values *****************")
            processRequest.apply(itemQueryList, k, j)
        }
    }
end