Help with rules

Just wondered if anyone would like to help me, fixing my rules? After update to openhab2.1/2.2 some of my rules doesn’t work anymore. It’s mainly because of syntax errors which leads to openhab ignoring my rules.


import org.openhab.core.library.types.*
import org.openhab.core.persistence.* 
import org.openhab.model.script.actions.*
import org.openhab.core.types.Command 
import org.openhab.core.types.*
import org.openhab.core.items.GenericItem 
import java.util.regex.Matcher
import java.util.regex.Pattern
import java.util.regex.*


rule "Voice control"

when

    Item VoiceCommand received command

then

    var String command = VoiceCommand.state.toString.toLowerCase
    logInfo("Voice.Rec","VoiceCommand received "+command)
    var State newState = null
    // find new state, toggle otherwise (if possible)
    if (command.contains("grader") || command.contains("prosent") || command.contains("dim")) {
        // extract new state (find the digits in the string)
        var Pattern p = Pattern::compile(".* ([0-9]+) (grad|prozent).*")
        var Matcher m = p.matcher(command)
        if (m.matches()) {
            logInfo("Voice.Rec","found number is "+m.group(1))
            newState = new StringType(m.group(1).trim())
        } else {
            logInfo("Voice.Rec","command does not match")
        }
    }
	
    else if (command.contains("av")|| command.contains("stopp") || command.contains("deaktiver")) {
        newState = OFF
    } else if (command.contains("på") || command.contains("start")|| command.contains("start") || command.contains("run")) {
        newState = ON
    } else if (command.contains("senk") || command.contains("ned") || command.contains("reduser") || command.contains("dim ned")) {
        newState = DOWN
    } else if (command.contains("øk") || command.contains("opp") || command.contains("mer") || command.contains("dim opp")) {
        newState = UP
    } else if (command.contains("rød")) {
        newState = new HSBType(new Color(255, 0, 0));
    } else if (command.contains("blå")) {
        newState = new HSBType(new Color(0, 0, 255));
    } else if (command.contains("hvit")) {
        newState = new HSBType(new Color(255, 255, 255));
    }

    // find room
    var String room = null
    var String roomItemPart = null
    var String roomArticle="i"
    if (command.contains("Stue") || command.contains("Living")) {
        room = "Living"
		roomItemPart = "FF_Living"
    } else if (command.contains("Kjøkken") || command.contains("Kitchen")) {
        room = "Kitchen"
        roomItemPart = "FF_Kitchen"
    } else if (command.contains("Entrance") || command.contains("gang")) {
        room = "Corridor"
        roomItemPart = "FF_Corridor"
    } else if (command.contains("Trening") || command.contains("gym")) {
        room = "Trening"
        roomItemPart = "GF_Trening"
    } else if (command.contains("Bad")) {
        room = "Bad"
        roomItemPart = "FF_Toilet"
	} else if (command.contains("ute") || command.contains("Outside")) {
        room = "Corridor"
        roomItemPart = "FF_Corridor"
        
    }
    // purpose
    var String itemType=null
    var String itemSubType=""
    var String reply=""
    if (command.contains("lys") || command.contains("downlights")) {
        itemType = "Light"
        if (newState instanceof HSBType) {
            if (room=="Living") {
                itemSubType="_Ceiling"
            } else if (room=="Corridor") {
                itemSubType="_Ceiling"
			} else if (room=="Corridor") {
                itemSubType="_Outdoor"
            }
        }
    } else if (command.contains("rolladen") || command.contains("jalousien")) {
        itemType = "Shutter"
        if (newState instanceof StringType) {
            itemType = "Shutter_Pos"
        }
        if (room=="Wohnzimmer") {
            // Unterscheiden zwischen Tür/Fenster
            if (command.contains("tür")) {
                itemSubType = "_Door"
            } else if (command.contains("fenster")) {
                itemSubType = "_Window"
            }
        }
    } else if (command.contains("temperatur")) {
        itemType = "Temperature"
        itemSubType = "_Target"
        reply = "Ok, Temperatur "+roomArticle+" "+room+" på "+newState+" Grader satt"
    }

    if (itemType!=null && (roomItemPart!=null || command.contains("all")) && newState!=null) {
        logInfo("Voice.Rec", "sending "+newState+" to "+itemType+"_"+roomItemPart+itemSubType)
        if (command.contains("all")) {
            if (roomItemPart==null)
                roomItemPart=""
            val String itemName = itemType+"_"+roomItemPart+itemSubType
            val State finalState = newState
            logInfo("Voice.Rec","searching for  *"+itemName+"* items")
            All?.allMembers.filter(s | s.name.contains(itemName) && s.acceptedDataTypes.contains(finalState.class)).forEach[item|
                logInfo("Voice.Rec","item  "+item+" found")
                sendCommand(item,finalState.toString)
            ]   
        } else {
            sendCommand(roomItemPart+"_"+itemType+itemSubType,newState.toString)
        }
        if (reply!="")
            say(reply)
    }

end 

response from openhab.log

2017-08-06 12:27:39.020 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'VoiceCommand.rules', using it anyway:
The use of wildcard imports is deprecated.
The use of wildcard imports is deprecated.
The use of wildcard imports is deprecated.
The use of wildcard imports is deprecated.
The use of wildcard imports is deprecated.
There is no context to infer the closure's argument types from. Consider typing the arguments or put the closures into a typed context.
There is no context to infer the closure's argument types from. Consider typing the arguments or put the closures into a typed context.

another rule:

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.core.types.Command
import org.openhab.core.types.*
import org.openhab.core.items.GenericItem
import java.util.regex.Matcher
import java.util.regex.Pattern

rule "Voice control 2"

when

    Item VoiceCommand received command

then
	var String command = VoiceCommand.state.toString.toLowerCase
    logInfo("Voice.Rec","VoiceCommand received "+command)
    var State newState = null
        
	if (command.contains("utelys av") 
    sendCommand(FF_Corridor_Light_Outdoor, "OFF")
	else if 
	(command.contains("utelys på")
	sendCommand(FF_Corridor_Light_Outdoor, "ON")
	else if 
	(command.contains("downlights stue av")
	sendCommand(FF_Living_Light_Ceiling, "OFF")
	else if 
	(command.contains("downlights stue på")
	sendCommand(FF_Living_Light_Ceiling, "ON")
	else if 
	(command.contains("sonos kjøkken play")
	sendCommand(Sonos_Kitc_Control, "PLAY")
	else if 
	(command.contains("sonos kjøkken stop")
	sendCommand(Sonos_Kitc_Control, "PAUSE")
	else if 
	(command.contains("sonos stue pc")
	sendCommand(SonosStue_PlayLineIn, "RINCON_000E58A5CBE201400")
	else if 
	(command.contains("sonos stue play")
	sendCommand(Sonos_Livi_Control, PLAY)
	else if 
	(command.contains("bad play")
	sendCommand(ChromecastAudioGruppe_Control, "PLAY")
	else if 
	(command.contains("bad stop")
	sendCommand(ChromecastAudioGruppe_Control, "PAUSE")
	else if 
	(command.contains("soverom play")
	sendCommand(ChromecastAudioGruppe_Control, "PLAY")
	else if 
	(command.contains("soverom stop")
	sendCommand(ChromecastAudioGruppe_Control, "PAUSE")
	else if 
	(command.contains("stemning")
	sendCommand(Scenarie_Stemning, "ON")
	else if 
	(command.contains("sove")
	sendCommand(Scenarie_Sove, "OFF")

	
	end
	

response from openhab.log

2017-08-06 12:30:32.808 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'Voicecontrol.rules'
2017-08-06 12:30:32.826 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'Voicecontrol.rules' is either empty or cannot be parsed correctly!
2017-08-06 12:30:33.188 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'Voicecontrol.rules' has errors, therefore ignoring it: [22,5]: missing ')' at 'sendCommand'
[25,2]: missing ')' at 'sendCommand'
[28,2]: missing ')' at 'sendCommand'
[31,2]: missing ')' at 'sendCommand'
[34,2]: missing ')' at 'sendCommand'
[37,2]: missing ')' at 'sendCommand'
[40,2]: missing ')' at 'sendCommand'
[43,2]: missing ')' at 'sendCommand'
[46,2]: missing ')' at 'sendCommand'
[49,2]: missing ')' at 'sendCommand'
[52,2]: missing ')' at 'sendCommand'
[55,2]: missing ')' at 'sendCommand'
[58,2]: missing ')' at 'sendCommand'
[61,2]: missing ')' at 'sendCommand'
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.java.math.*
import org.joda.time.*

var Timer CheckSinglePlayerTimer = null
var Timer SonosGroupVisibility = null

val Functions$Function6 updateSingleGroups = [
		NumberItem group1_num,
		NumberItem group2_num,
		NumberItem group3_num,
		StringItem player_a_groupID,
		StringItem player_b_groupID,
		StringItem player_a_name |

		// If the player the updated player has been grouped to is in the "NONE"-group (or is NULL),
		// find a group with zero players and update status of both players.
		if(player_b_groupID.state=="0" || player_b_groupID.state==NULL) {
			if(group1_num.state==0) {
				postUpdate(player_a_groupID,"1")
				postUpdate(player_b_groupID,"1")
				logInfo("openhab", player_a_name + " player + 1 updated to group 1")

			} else if(group2_num.state==0) {
				postUpdate(player_a_groupID,"2")
				postUpdate(player_b_groupID,"2")
				logInfo("openhab", player_a_name + " player + 1 updated to group 2")

			} else if(group3_num.state==0) {
				postUpdate(player_a_groupID,"3")
				postUpdate(player_b_groupID,"3")
				logInfo("openhab", player_a_name + " player + 1 updated to group 3")
			}
		// Else set the updated player to the group id of the matched player
		} else if(player_a_groupID.state!=player_b_groupID.state) {
			postUpdate(player_a_groupID,player_b_groupID.state)
			logInfo("openhab", player_a_name + " player updated to group " + player_b_groupID.state.toString)
		}
		return NULL
	]

val Functions$Function6 checkSinglePlayers = [
		StringItem CheckZonegroupID,
		StringItem ZonegroupID_a,
		StringItem ZonegroupID_b,
		StringItem ZonegroupID_c,
		StringItem UpdatePlayer,
		StringItem UpdatePlayerName |

		if(CheckZonegroupID.state!=ZonegroupID_a.state && CheckZonegroupID.state!=ZonegroupID_b.state && CheckZonegroupID.state!=ZonegroupID_c.state) {
			postUpdate(UpdatePlayer,"0")
			logInfo("openhab", UpdatePlayerName + "player updated to group 0")

		}
		return NULL
	]

///// NUMBER OF PLAYERS IN GROUP
//
//	A simple count of the number of players
//	in each group is made. This is used in
//	various rules, e.g. to determine
//	if a group should be visible in the UI or not.
//
/////////////////////////////////

rule "Sonos number of players in group"
	when
		Item SonosGroupID_Kitc received update or
		Item SonosGroupID_Gues received update or
		Item SonosGroupID_Livi received update or
		Item SonosGroupID_Bath received update
	then
		var Number Group_1 = 0
		var Number Group_2 = 0
		var Number Group_3 = 0

		if(SonosGroupID_Kitc.state=="1"){
			Group_1 = Group_1 + 1
		}else if(SonosGroupID_Kitc.state=="2"){
			Group_2 = Group_2 + 1
		}else if(SonosGroupID_Kitc.state=="3"){
			Group_3 = Group_3 + 1
		}

		if(SonosGroupID_Gues.state=="1"){
			Group_1 = Group_1 + 1
		}else if(SonosGroupID_Gues.state=="2"){
			Group_2 = Group_2 + 1
		}else if(SonosGroupID_Gues.state=="3"){
			Group_3 = Group_3 + 1
		}

		if(SonosGroupID_Bath.state=="1"){
			Group_1 = Group_1 + 1
		}else if(SonosGroupID_Bath.state=="2"){
			Group_2 = Group_2 + 1
		}else if(SonosGroupID_Bath.state=="3"){
			Group_3 = Group_3 + 1
		}

		if(SonosGroupID_Livi.state=="1"){
			Group_1 = Group_1 + 1
		}else if(SonosGroupID_Livi.state=="2"){
			Group_2 = Group_2 + 1
		}else if(SonosGroupID_Livi.state=="3"){
			Group_3 = Group_3 + 1
		}

		postUpdate(Sonos_Group1_Number,Group_1)
		postUpdate(Sonos_Group2_Number,Group_2)
		postUpdate(Sonos_Group3_Number,Group_3)
end

///// GROUPING RULES
//
//	The rule will check every other player that the
//	  (1) Group number of the player beeing added corresponds to the player it is beeing added to
//	  (2) Zone-ids are not equal (not already grouped)
//	  (3) That the player beeing checked has a state (not NULL)
//
//	Additional nested logic is required to determine in what direction the player shall be grouped (A to B or B to A).
//	This is a special case that kicks in when both players are single before grouping: It is not possible
//	to add a player that is the local coordinator to a player which is not.
//
/////////////////////////////////


rule "Sonos group kitchen"
	when 
		Item SonosGroupID_Kitc received command
	then
	
		// Short sleep to make shure the rule to calculate the number of players in a group has executed before the logic is applied.
		Thread::sleep(300)

		if(SonosGroupID_Kitc.state==SonosGroupID_Gues.state && SonosGroupID_Kitc.state!="0" && Sonos_Kitc_ZoneGroupID.state!=Sonos_Gues_ZoneGroupID.state && Sonos_Gues_ZoneGroupID.state!=NULL && ((Sonos_Gues_LocalCoordinator.state==ON) || (Sonos_Kitc_LocalCoordinator.state==ON && ((SonosGroupID_Kitc.state=="1" && Sonos_Group1_Number.state=="2") || (SonosGroupID_Kitc.state=="2" && Sonos_Group2_Number.state=="2") || (SonosGroupID_Kitc.state=="3" && Sonos_Group3_Number.state=="2"))))){ 
			
			logInfo("openhab","Entered sonos kitchen grouping rule number 1")
			
			if(Sonos_Gues_LocalCoordinator.state==ON){
				Sonos_Gues_Add.sendCommand("RINCON_B8E937B43B6C01400")
				logInfo("openhab","Kitchen player added to guest room")
			}else if(Sonos_Kitc_LocalCoordinator.state==ON && ((SonosGroupID_Kitc.state=="1" && Sonos_Group1_Number.state=="2") || (SonosGroupID_Kitc.state=="2" && Sonos_Group2_Number.state=="2") || (SonosGroupID_Kitc.state=="3" && Sonos_Group3_Number.state=="2"))) {
				Sonos_Kitc_Add.sendCommand("RINCON_guestroomplayer")
				logInfo("openhab","Guest room player added to kitchen")
			}

		}else if(SonosGroupID_Kitc.state==SonosGroupID_Bath.state && SonosGroupID_Kitc.state!="0" && Sonos_Kitc_ZoneGroupID.state!=Sonos_Bath_ZoneGroupID.state && Sonos_Bath_ZoneGroupID.state!=NULL && ((Sonos_Bath_LocalCoordinator.state==ON) || (Sonos_Kitc_LocalCoordinator.state==ON && ((SonosGroupID_Kitc.state=="1" && Sonos_Group1_Number.state=="2") || (SonosGroupID_Kitc.state=="2" && Sonos_Group2_Number.state=="2") || (SonosGroupID_Kitc.state=="3" && Sonos_Group3_Number.state=="2"))))){ 
			
			logInfo("openhab","Entered sonos kitchen grouping rule number 2")
			
			if(Sonos_Bath_LocalCoordinator.state==ON){
				Sonos_Bath_Add.sendCommand("RINCON_B8E937B43B6C01400")
				logInfo("openhab","Kitchen player added to bathroom")
			}else if(Sonos_Kitc_LocalCoordinator.state==ON && ((SonosGroupID_Kitc.state=="1" && Sonos_Group1_Number.state=="2") || (SonosGroupID_Kitc.state=="2" && Sonos_Group2_Number.state=="2") || (SonosGroupID_Kitc.state=="3" && Sonos_Group3_Number.state=="2"))) {
				Sonos_Kitc_Add.sendCommand("RINCON_bathroomplayer")
				logInfo("openhab","Bathroom player added to kitchen")
			}

		}else if(SonosGroupID_Kitc.state==SonosGroupID_Livi.state && SonosGroupID_Kitc.state!="0" && Sonos_Kitc_ZoneGroupID.state!=Sonos_Livi_ZoneGroupID.state && Sonos_Livi_ZoneGroupID.state!=NULL && ((Sonos_Livi_LocalCoordinator.state==ON) || (Sonos_Kitc_LocalCoordinator.state==ON && ((SonosGroupID_Kitc.state=="1" && Sonos_Group1_Number.state=="2") || (SonosGroupID_Kitc.state=="2" && Sonos_Group2_Number.state=="2") || (SonosGroupID_Kitc.state=="3" && Sonos_Group3_Number.state=="2"))))){ 
			
			logInfo("openhab","Entered sonos kitchen grouping rule number 3")
			
			if(Sonos_Livi_LocalCoordinator.state==ON){
				Sonos_Livi_Add.sendCommand("RINCON_B8E937B43B6C01400")
				logInfo("openhab","Kitchen player added to living room")
			}else if(Sonos_Kitc_LocalCoordinator.state==ON && ((SonosGroupID_Kitc.state=="1" && Sonos_Group1_Number.state=="2") || (SonosGroupID_Kitc.state=="2" && Sonos_Group2_Number.state=="2") || (SonosGroupID_Kitc.state=="3" && Sonos_Group3_Number.state=="2"))) {
				Sonos_Kitc_Add.sendCommand("RINCON_000E58A5CBE201400")
				logInfo("openhab","Living room player added to Kitchen")
			}

		}else{
			Sonos_Kitc_StandAlone.sendCommand("ON")
			logInfo("openhab","Kitchen player set to stand alone")
		}
end

//// UPDATE GROUPING RULES
//
//	The rules will update the appropiate group
//	when a sonos player is grouped, either
//  in the OH2 UI or within the Sonos app.
//	
/////////////////////////////////

rule "Sonos update group membership bathroom"
	when
		Item Sonos_Bath_ZoneGroupID changed
	then
		if(Sonos_Bath_ZoneGroupID.state==Sonos_Kitc_ZoneGroupID.state && Sonos_Kitc_ZoneGroupID.state!=NULL) {
			updateSingleGroups.apply(Sonos_Group1_Number, Sonos_Group2_Number, Sonos_Group3_Number, SonosGroupID_Bath, SonosGroupID_Kitc, "Bathroom")

		} else if(Sonos_Bath_ZoneGroupID.state==Sonos_Gues_ZoneGroupID.state && Sonos_Gues_ZoneGroupID.state!=NULL) {
			updateSingleGroups.apply(Sonos_Group1_Number, Sonos_Group2_Number, Sonos_Group3_Number, SonosGroupID_Bath, SonosGroupID_Gues, "Bathroom")

		} else if(Sonos_Bath_ZoneGroupID.state==Sonos_Livi_ZoneGroupID.state && Sonos_Livi_ZoneGroupID.state!=NULL) {
			updateSingleGroups.apply(Sonos_Group1_Number, Sonos_Group2_Number, Sonos_Group3_Number, SonosGroupID_Bath, SonosGroupID_Livi, "Bathroom")

		// The zone-id changed, but is not grouped with any other players (removed from group).
		// To allow grouping in the UI without the state being reset to single, a timer is applied.
		// This works since grouping in both the OH UI and the Sonos app usually is not performed simultaneously.
		} else {
			if(CheckSinglePlayerTimer==null) {
				CheckSinglePlayerTimer = createTimer(now.plusSeconds(20), [|
					checkSinglePlayers.apply(Sonos_Bath_ZoneGroupID, Sonos_Kitc_ZoneGroupID, Sonos_Gues_ZoneGroupID, Sonos_Livi_ZoneGroupID, SonosGroupID_Bath,"Bathroom")
					checkSinglePlayers.apply(Sonos_Kitc_ZoneGroupID, Sonos_Bath_ZoneGroupID, Sonos_Gues_ZoneGroupID, Sonos_Livi_ZoneGroupID, SonosGroupID_Kitc,"Kitchen")
					checkSinglePlayers.apply(Sonos_Gues_ZoneGroupID, Sonos_Bath_ZoneGroupID, Sonos_Kitc_ZoneGroupID, Sonos_Livi_ZoneGroupID, SonosGroupID_Gues,"Guest room")
					checkSinglePlayers.apply(Sonos_Livi_ZoneGroupID, Sonos_Bath_ZoneGroupID, Sonos_Kitc_ZoneGroupID, Sonos_Gues_ZoneGroupID, SonosGroupID_Livi,"Living room")
					CheckSinglePlayerTimer = null
				])
				logInfo("openhab","CheckSinglePlayerTimer scheduled")
			} else {
				CheckSinglePlayerTimer.reschedule(now.plusSeconds(20))
				logInfo("openhab","CheckSinglePlayerTimer rescheduled")
			}
		} 

end

///// GROUP VISIBILITY
//
//	The rule is used to control the UI.
//  Specifically, it used to determin
//  if a group should be hidden and if
//  no, which player is to be shown within
//  the group. This has to be the local
//	coordinator in the group.
// 
/////////////////////////////////

rule "Sonos group visibility"
	when
		Item SonosGroupID_Kitc received update or
		Item SonosGroupID_Gues received update or
		Item SonosGroupID_Bath received update or
		Item SonosGroupID_Livi received update 
	then
		if(SonosGroupVisibility==null) {
			SonosGroupVisibility = createTimer(now.plusSeconds(5), [|

				if(Sonos_Group1_Number.state<=1){
					postUpdate(Sonos_Group1_Visibility,"Hide")

				}else if(Sonos_Group1_Number.state>=2){
					if(SonosGroupID_Kitc.state=="1" && Sonos_Kitc_LocalCoordinator.state==ON){
						postUpdate(Sonos_Group1_Visibility,"Kitchen")
					}else if(SonosGroupID_Gues.state=="1" && Sonos_Gues_LocalCoordinator.state==ON){
						postUpdate(Sonos_Group1_Visibility,"Guest room")
					}else if(SonosGroupID_Bath.state=="1" && Sonos_Bath_LocalCoordinator.state==ON){
						postUpdate(Sonos_Group1_Visibility,"Bathroom")
					}else if(SonosGroupID_Livi.state=="1" && Sonos_Livi_LocalCoordinator.state==ON){
						postUpdate(Sonos_Group1_Visibility,"Living room")
					}
				}

				if(Sonos_Group2_Number.state<=1){
					postUpdate(Sonos_Group2_Visibility,"Hide")
				}else if(Sonos_Group2_Number.state>=2){
					if(SonosGroupID_Kitc.state=="2" && Sonos_Kitc_LocalCoordinator.state==ON){
						postUpdate(Sonos_Group2_Visibility,"Kitchen")
					}else if(SonosGroupID_Gues.state=="2" && Sonos_Gues_LocalCoordinator.state==ON){
						postUpdate(Sonos_Group2_Visibility,"Guest room")
					}else if(SonosGroupID_Bath.state=="2" && Sonos_Bath_LocalCoordinator.state==ON){
						postUpdate(Sonos_Group2_Visibility,"Bathroom")
					}else if(SonosGroupID_Livi.state=="2" && Sonos_Livi_LocalCoordinator.state==ON){
						postUpdate(Sonos_Group2_Visibility,"Living room")
					}
				}

				if(Sonos_Group3_Number.state<=1){
					postUpdate(Sonos_Group3_Visibility,"Hide")
				}else if(Sonos_Group3_Number.state>=2){
					if(SonosGroupID_Kitc.state=="3" && Sonos_Kitc_LocalCoordinator.state==ON){
						postUpdate(Sonos_Group3_Visibility,"Kitchen")
					}else if(SonosGroupID_Gues.state=="3" && Sonos_Gues_LocalCoordinator.state==ON){
						postUpdate(Sonos_Group3_Visibility,"Guest room")
					}else if(SonosGroupID_Bath.state=="3" && Sonos_Bath_LocalCoordinator.state==ON){
						postUpdate(Sonos_Group3_Visibility,"Bathroom")
					}else if(SonosGroupID_Livi.state=="3" && Sonos_Livi_LocalCoordinator.state==ON){
						postUpdate(Sonos_Group3_Visibility,"Living room")
					}
				}

			])
			logInfo("openhab","SonosGroupVisibility scheduled")
			SonosGroupVisibility = null

		} else {
			SonosGroupVisibility.reschedule(now.plusSeconds(5))
			logInfo("openhab","SonosGroupVisibility rescheduled")
		}

end

response from openhab.log

2017-08-06 12:33:38.677 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'sonos1.rules', using it anyway:
The use of wildcard imports is deprecated.
The use of wildcard imports is deprecated.
The use of wildcard imports is deprecated.
The use of wildcard imports is deprecated.
The use of wildcard imports is deprecated.
Function6 is a raw type. References to generic type Function6<P1, P2, P3, P4, P5, P6, Result> should be parameterized
Function6 is a raw type. References to generic type Function6<P1, P2, P3, P4, P5, P6, Result> should be parameterized

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.core.items.*
import java.util.regex.Matcher
import java.util.regex.Pattern
 
rule "Talekontroll"
 
/* ---------------------------------------------------------
   Upon receipt of a voice command, an attempt is made
    - Room
    - Item
    - Status
    To recognize. If all three are set, correspondingly
    Switched.
   --------------------------------------------------------- */
 
 
// When voice command is received

when
        Item VoiceCommand received command
then
        // To lowercase
        var String command = VoiceCommand.state.toString.toLowerCase
 
        // LOG output
        logInfo("Voice.Rec","INFO: command received voice command "+command)
 
/* Status -------------------------------------------------- */
        var String status = null
		
		//First find the new state:
		var Number hasNumber = 0
		var Number hasState = 0
	
		if(command.contains("degree") || command.contains("procent") || command.contains("%")){
		
		// extract new state (find the digits in the string)
        
		val java.util.regex.Pattern p = java.util.regex.Pattern::compile(".* ([0-9]+).*")
        var java.util.regex.Matcher m = p.matcher(command)
        if (m.matches()) {
            status = new String(m.group(1).trim())
            hasNumber = 1
     
        // Status OFF
        if (command.contains("av")||
                command.contains("turn off") ||
                command.contains("stop") ||
                command.contains("deactivate")) {
                        status = "OFF"
                        logInfo("Voice.Rec", "INFO: status OFF")
 
        // Status ON
        } else if (command.contains ("på") ||
                        command.contains("on")||
                        command.contains("turn on") ||
                        command.contains("start") ||
                        command.contains("activate")) {
                        status = "ON"
                        logInfo("Voice.Rec", "INFO: status ON")
		
		// Otherwise, no status detected
        } else {
                logInfo("Voice.Rec", "WARN: No status detected")
        }
 
/* Room ---------------------------------------------------- */
/*  The items are designed in such a way that a speech-
    Of the abbreviation for the room, eg bedroom for bedroom
    Or WZ for living room. This is followed by a description
    Of the actual item, e.g. Floor lamp, temperature, etc.
    Together, e.g. WZ_Stehlamp.
   --------------------------------------------------------- */
        var String roomDescription = null
        var String itemRoomPart = null
 
        // 1st part of the item
        if (command.contains("soverom")) {
                roomDescription = "bedroom"
                itemRoomPart = "FF_Bedroom"
                logInfo("Voice.Rec", "INFO: Room "+roomDescription)
 
        } else if (command.contains("stue")) {
                roomDescription = "living"
                itemRoomPart = "FF_Living"
                logInfo("Voice.Rec", "INFO: Room "+roomDescription)
		
		} else if (command.contains("gang")) {
                roomDescription = "Corridor"
                itemRoomPart = "FF_Corridor"
                logInfo("Voice.Rec", "INFO: Room "+roomDescription)
 
        } else {
                logInfo("Voice.Rec", "WARN: no Room detected")
        }
/* Item ---------------------------------------------------- */
        var String itemDescription = null
        var String itemName = null
 
        // Item search
        if (command.contains("lys") ||
                command.contains("lys")) {
                itemDescription = "Light"
                itemName = "Light"
                logInfo("Voice.Rec", "INFO: Item "+itemDescription)
        } else if (command.contains("downlights")) {
                itemDescription = "downlights"
                itemName = "Light_Ceiling"
                logInfo("Voice.Rec", "INFO: Item "+itemDescription)
        }
        // to be continued ...
        else {
                logInfo("Voice.Rec", "WARN: no Item recognized")
        }
/* SubItem ---------------------------------------------------- */
        var String subItemDescription = null
        var String subItemName = null
 
        // subItem search
        if (command.contains("tak") ||
                command.contains("ceiling")) {
                subItemDescription = "Downlights"
                subItemName = "Ceiling"
                logInfo("Voice.Rec", "INFO: Item "+subItemDescription)
        } else if (command.contains("lyskrone")) {
                subItemDescription = "lyskrone"
                subItemName = "pendel"
                logInfo("Voice.Rec", "INFO: Item "+subItemDescription)
        }
        // to be continued ...
        else {
                logInfo("Voice.Rec", "WARN: no subItem recognized")
        }
 
/* Assemble ------------------------------------------- */
        val String fullItemName = null
 
        // ONLY when everything has been detected
        if ( status != null &&
                itemRoomPart != null &&
				itemName != null ) {
                fullItemName = itemRoomPart+"_"+itemName 
                logInfo("Voice.Rec", "INFO: fullItemName "+fullItemName)
                sendCommand(fullItemName,status)
 
        } else {
                logInfo("Voice.Rec", "WARN: Command not complete")
        }
end

response from openhab.log

2017-08-06 12:39:39.772 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'speech.rules'
2017-08-06 12:39:39.786 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'speech.rules' is either empty or cannot be parsed correctly!
2017-08-06 12:39:40.450 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'speech.rules' has errors, therefore ignoring it: [153,1]: mismatched input 'end' expecting '}'

Ok, first you should clean up you imports. As fa as i know the openhab importlines are no longe necessary.

With the second rule a ) is missing at the end of the if statement and as far as i see same problem with the else if statements. Should be something like this:

if (command.contains("utelys av"))

Then it is always a good idea to follow the right syntax. Your lambda definition ist not right, because some type definitions are not there. Should be something like:

 val org.eclipse.xtext.xbase.lib.Functions$Function6<NumberItem, NumberItem, NumberItem, StringItem, StringItem, StringItem> updateSingleGroups = [
		NumberItem group1_num,
		NumberItem group2_num,
		NumberItem group3_num,
		StringItem player_a_groupID,
		StringItem player_b_groupID,
		StringItem player_a_name |

You should try firt to resolve all designer errors.

Thomas

I’ll second Thomas’s suggestion. Load the rules into ESH Designer to check for syntax errors.

I’ll also suggest going through the Migration Tutorial which covers all the changes you need to make when moving to OH 2.x from 1.x.

1 Like

Thank you very much for your time and help.
As you probably understood, I’m not too good with coding, so most of my rules are copy/paste material :slight_smile:
I have been using ESH designer to point out the syntax errors, but failed in fixing them myself. Some of your advise above helped me in using some of my rules, but

val org.eclipse.xtext.xbase.lib.Functions$Function6<NumberItem, NumberItem, NumberItem, StringItem, StringItem, StringItem> updateSingleGroups = [
		NumberItem group1_num,
		NumberItem group2_num,
		NumberItem group3_num,
		StringItem player_a_groupID,
		StringItem player_b_groupID,
		StringItem player_a_name |

is still no go :frowning:

Could you please give us some information where the designer shows an error and which error this is. Make it a little easier to us.

Thomas

I will thank you for your time and help on this topic. But I have decided to remove the Sonos.rules due to multiple syntax errors after openhab upgrade.
@Dibbler42: I should have provided more information, but I feel that it is more hassle than gaining from this. Because I would need to take several screenshots of ESH designer error pop-ups etc. Probably the best way to do it, is if you paste the code in your designer, If you want and have the time :wink:

But trying to solve another issue here now :slight_smile: I have a Loxone smart home unit which i use for logics and user interface for my home. I use it in combination with openhab2.

I have modbus binding runnning on OH2, and i want to send item.state to Loxone over http.
I’ve done something similar earlier, but then I’ve sent a given state on or off, defined in the .items -file itself.

What i’m trying to do now, Is making a rule that sends the actual state of modbus item Systemair_FanSpeed to http://url

example of doing this with a switch in Items file earlier:

/* Multimedia */
Switch All_media_ONOFF   "AV system"   <multimedia>  (FF_Living)   { http=">[ON:POST:http://user:password@IP/dev/sps/io/All_Media_ONOFF/on]" }

So now I would like something like:

//Systemair_FanSpeed_State//
rule systemair_fanspeed_state

when
Item Systemair_FanSpeed received update

then
\\send Systemair_FanSpeed.state to HTTP-URL(http://user:password@IP/dev/sps/io/Systemair_FanSpeed/) \\

end

I’m trying to write a rule that will fire if the temperature within the next 3,6,9 or 12 hours will be above 79. I’m not getting any errors, but I’m also not getting the “Temperature Change Detected” in the log.

Is there a more efficient way to write this type of rule and if not, can someone please correct my syntax?

rule "Max temperature"
when
	Item 12_HourTemp received update
then
	val Double 12Temp = Double::parseDouble(12_HourTemp.state.format("%.3f"))
	val Double 9Temp = Double::parseDouble(9_HourTemp.state.format("%.3f"))
	val Double 6Temp = Double::parseDouble(6_HourTemp.state.format("%.3f"))
	val Double 3Temp = Double::parseDouble(3_HourTemp.state.format("%.3f"))
	
	logInfo("Max Temp Change", "Temperature Change Detected")

	if (12Temp > 79) ||
			(9Temp > 79) ||
			(6Temp > 79) ||
			(3Temp > 79) {
			
				sendCommand(Summer, ON)
				logInfo("Max Temp", " 12 hour temp logged as " + 12Temp)
	} else  { 
		sendCommand(Summer, OFF)
		logInfo("Max Temp", "Summer OFF, no temperature over 79 for next 12 hours")
	}
end

Item file:

Number:Temperature 3_HourTemp "Hour3 Temp [%.1f %unit%]" <temperature> 	(Weather, gMaxTemp)		{ channel="openweathermap:weather-and-forecast:c5e7a131:local:forecastHours03#temperature" }
Number:Temperature 6_HourTemp "Hour6 Temp [%.1f %unit%]" <temperature> 	(Weather, gMaxTemp)		{ channel="openweathermap:weather-and-forecast:c5e7a131:local:forecastHours06#temperature" }
Number:Temperature 9_HourTemp "Hour9 Temp [%.1f %unit%]" <temperature> 	(Weather, gMaxTemp)		{ channel="openweathermap:weather-and-forecast:c5e7a131:local:forecastHours09#temperature" }
Number:Temperature 12_HourTemp "Hour12 Temp [%.1f %unit%]" <temperature> 	(Weather, gMaxTemp)	{ channel="openweathermap:weather-and-forecast:c5e7a131:local:forecastHours12#temperature" }

Log file showing I am getting values:

2019-02-20 18:10:50.512 [vent.ItemStateChangedEvent] - 3_HourTemp changed from 76.964 °F to 75.524 °F
2019-02-20 18:10:50.604 [vent.ItemStateChangedEvent] - 6_HourTemp changed from 70.376 °F to 69.296 °F
2019-02-20 18:10:50.720 [vent.ItemStateChangedEvent] - 9_HourTemp changed from 65.93 °F to 65.21 °F
2019-02-20 18:10:50.854 [vent.ItemStateChangedEvent] - 12_HourTemp changed from 63.968 °F to 63.608 °F

Names must not begin with numbers.

(referring to Items)

1 Like