[SOLVED] Controlling openHAB with your voice : Rules syntax

Hi

i have found this really smart project and i have just an issue of syntax, i think

rule "Voice control"
when
    Item VoiceCommand received command
then
    // https://github.com/openhab/openhab/wiki/Controlling-openHAB-with-your-voice
    var String command = VoiceCommand.state.toString.toLowerCase
    logInfo("voice control","VoiceCommand received----" + command+ "----")

    var String cmd = null
 
 if ( command.contains("éteins")  || command.contains("turn off")  || command.contains("eteins")|| command.contains("éteindre")) {
           	logInfo("cmd ", "OFF two condition works" )	
		 cmd = "OFF"
            logInfo("cmd ", "éteindre: " + cmd )	
}

  if ( command.contains("allume") || command.contains("allumer") or  || command.contains("turn on")) {
         	cmd = "ON"
		 logInfo("cmd ", "ONtwo condition works" )	
   }


//        } else if (command.contains("ouvre")) {
//            cmd = "OPEN"
//        } else if (command.contains("ferme"))  {
//            cmd = "CLOSE"
//    }



     if (command.contains("bain"))  {
				  logInfo("cmd ", "bain: " + cmd )	
					sdblight.sendCommand(cmd)
       				sdblight.postUpdate(cmd)

					appliqueSwitch.sendCommand(cmd)
					appliqueSwitch.postUpdate(cmd)  


					SP2_1.sendCommand(cmd)
					SP2_1.postUpdate(cmd)


if (command.contains("douche"))  {
	logInfo("cmd ", "douche: " + cmd )	

	ZWaveSwitch1_Channel1_Right.sendCommand(cmd)
     	ZWaveSwitch1_Channel2_Left.sendCommand(cmd)
        }
}
end

but in the log, we can see the IF statement do not work

2018-04-01 18:11:47.503 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----allume salle de bain----

2018-04-01 18:11:47.514 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----allume salle de bain----

2018-04-01 18:11:47.508 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----allume salle de bain----

==> /var/log/openhab2/events.log <==

2018-04-01 18:12:09.123 [ome.event.ItemCommandEvent] - Item 'VoiceCommand' received command et ta salle de bain

2018-04-01 18:12:09.143 [vent.ItemStateChangedEvent] - VoiceCommand changed from allume salle de bain to et ta salle de bain

==> /var/log/openhab2/openhab.log <==

2018-04-01 18:12:09.147 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----allume salle de bain----

2018-04-01 18:12:09.152 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----et ta salle de bain----

2018-04-01 18:12:09.161 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----allume salle de bain----

==> /var/log/openhab2/events.log <==

2018-04-01 18:12:09.529 [vent.ItemStateChangedEvent] - Current_DateTime changed from 2018-04-01T18:11:09.512+0300 to 2018-04-01T18:12:09.517+0300

2018-04-01 18:12:17.634 [ome.event.ItemCommandEvent] - Item 'VoiceCommand' received command turn off salle de bain

2018-04-01 18:12:17.663 [vent.ItemStateChangedEvent] - VoiceCommand changed from et ta salle de bain to turn off salle de bain

==> /var/log/openhab2/openhab.log <==

2018-04-01 18:12:17.681 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----turn off salle de bain----

2018-04-01 18:12:17.696 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----turn off salle de bain----

2018-04-01 18:12:17.699 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----turn off salle de bain----

==> /var/log/openhab2/events.log <==

2018-04-01 18:12:26.000 [ome.event.ItemCommandEvent] - Item 'VoiceCommand' received command turn off douche

==> /var/log/openhab2/openhab.log <==

2018-04-01 18:12:26.034 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----turn off douche----

2018-04-01 18:12:26.034 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----turn off douche----

2018-04-01 18:12:26.039 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----turn off douche----

==> /var/log/openhab2/events.log <==

2018-04-01 18:12:26.027 [vent.ItemStateChangedEvent] - VoiceCommand changed from turn off salle de bain to turn off douche

2018-04-01 18:12:27.751 [me.event.ThingUpdatedEvent] - Thing 'zwave:device:162723a63f8:node4' has been updated.

2018-04-01 18:12:28.002 [vent.ItemStateChangedEvent] - lastseen_Hen changed from 2018-04-01T18:11:27.763+0300 to 2018-04-01T18:12:27.982+0300

2018-04-01 18:12:35.999 [ome.event.ItemCommandEvent] - Item 'VoiceCommand' received command turn on douche

==> /var/log/openhab2/openhab.log <==

2018-04-01 18:12:36.033 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----turn on douche----

2018-04-01 18:12:36.033 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----turn on douche----

==> /var/log/openhab2/events.log <==

2018-04-01 18:12:36.040 [vent.ItemStateChangedEvent] - VoiceCommand changed from turn off douche to turn on douche

==> /var/log/openhab2/openhab.log <==

2018-04-01 18:12:36.055 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----turn on douche----

what is wrong in my condition???

Thanks!!

  if ( command.contains("allume") || command.contains("allumer") || command.contains("turn on")) {

There was a or in there that didn’t belong

Et voila…

Thanks.

it helped partially

rule "Voice control"
when
    Item VoiceCommand received command
then
    // https://github.com/openhab/openhab/wiki/Controlling-openHAB-with-your-voice
    var String command = VoiceCommand.state.toString.toLowerCase
    logInfo("voice control","VoiceCommand received----" + command+ "----")

    var String cmd = null
 
 if ( command.contains("éteins")  || command.contains("turn off")  || command.contains("eteins")|| command.contains("éteindre")) {
           	logInfo("cmd ", "OFF two condition works" )	
		 cmd = "OFF"
            logInfo("cmd ", "éteindre: " + cmd )	
}

  if ( command.contains("allume") || command.contains("allumer")  || command.contains("turn on")) {
         	cmd = "ON"
		 logInfo("cmd ", "ONtwo condition works" )	
   }


//        } else if (command.contains("ouvre")) {
//            cmd = "OPEN"
//        } else if (command.contains("ferme"))  {
//            cmd = "CLOSE"
//    }



     if (command.contains("bain") || command.contains("ben"))  {
				       logInfo("cmd ", "bain: " + cmd )	
					sdblight.sendCommand(cmd)
       				sdblight.postUpdate(cmd)

					appliqueSwitch.sendCommand(cmd)
					appliqueSwitch.postUpdate(cmd)  


					SP2_1.sendCommand(cmd)
					SP2_1.postUpdate(cmd)


if (command.contains("douche"))  {
	logInfo("cmd ", "douche: " + cmd )	

	ZWaveSwitch1_Channel1_Right.sendCommand(cmd)
     	ZWaveSwitch1_Channel2_Left.sendCommand(cmd)
        }
}
end

it works for salle de bain

2018-04-02 10:13:25.075 [ome.event.ItemCommandEvent] - Item 'VoiceCommand' received command allume salle de bain
2018-04-02 10:13:25.092 [vent.ItemStateChangedEvent] - VoiceCommand changed from Amin salle de bain to allume salle de bain

==> /var/log/openhab2/openhab.log <==
2018-04-02 10:13:25.132 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----allume salle de bain----
2018-04-02 10:13:25.136 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----allume salle de bain----
2018-04-02 10:13:25.132 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----allume salle de bain----
2018-04-02 10:13:25.155 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----allume salle de bain----
2018-04-02 10:13:25.175 [INFO ] [.eclipse.smarthome.model.script.cmd ] - ONtwo condition works
2018-04-02 10:13:25.184 [INFO ] [.eclipse.smarthome.model.script.cmd ] - bain: ON

==> /var/log/openhab2/events.log <==
2018-04-02 10:13:25.190 [ome.event.ItemCommandEvent] - Item 'sdblight' received command ON
==> /var/log/openhab2/openhab.log <==
2018-04-02 10:13:25.197 [INFO ] [ab.binding.exec.internal.ExecBinding] - executed commandLine '/usr/bin/python /etc/openhab2/scripts/SendCode_Salon_RF.py /etc/openhab2/scripts/Codes/SDB_VENTA_ON.txt'
==> /var/log/openhab2/events.log <==
2018-04-02 10:13:25.202 [GroupItemStateChangedEvent] - gSdb changed from OFF to ON through sdblight
2018-04-02 10:13:25.208 [vent.ItemStateChangedEvent] - sdblight changed from OFF to ON
2018-04-02 10:13:25.211 [ome.event.ItemCommandEvent] - Item 'appliqueSwitch' received command ON
2018-04-02 10:13:25.218 [GroupItemStateChangedEvent] - gAll changed from OFF to ON through sdblight
2018-04-02 10:13:25.223 [vent.ItemStateChangedEvent] - appliqueSwitch changed from OFF to ON

but i have still two issues:

  1. the french word éteindre with the accent on the e is not identified.
2018-04-02 10:13:39.343 [ome.event.ItemCommandEvent] - Item 'VoiceCommand' received command éteindre salle de bain
2018-04-02 10:13:39.357 [vent.ItemStateChangedEvent] - VoiceCommand changed from allume salle de bain to éteindre salle de bain

==> /var/log/openhab2/openhab.log <==

2018-04-02 10:13:39.387 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----éteindre salle de bain----
2018-04-02 10:13:39.393 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----éteindre salle de bain----
2018-04-02 10:13:39.400 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----éteindre salle de bain----
2018-04-02 10:13:39.397 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----éteindre salle de bain----
2018-04-02 10:13:39.458 [INFO ] [.eclipse.smarthome.model.script.cmd ] - bain: null
2018-04-02 10:13:39.462 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert 'null' to a command type which item 'sdblight' accepts: [OnOffType, RefreshType].
2018-04-02 10:13:39.467 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert 'null' to a state type which item 'sdblight' accepts: [OnOffType, UnDefType].
2018-04-02 10:13:39.472 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert 'null' to a command type which item 'appliqueSwitch' accepts: [OnOffType, RefreshType].
2018-04-02 10:13:39.477 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert 'null' to a state type which item 'appliqueSwitch' accepts: [OnOffType, UnDefType].
2018-04-02 10:13:39.482 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert 'null' to a command type which item 'SP2_1' accepts: [OnOffType, RefreshType].
2018-04-02 10:13:39.486 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert 'null' to a state type which item 'SP2_1' accepts: [OnOffType, UnDefType].

==> /var/log/openhab2/events.log <==
  1. “allumer douche” do not work and i have not idea why
018-04-02 10:18:15.357 [ome.event.ItemCommandEvent] - Item 'VoiceCommand' received command allumer douche
2018-04-02 10:18:15.368 [vent.ItemStateChangedEvent] - VoiceCommand changed from Allume douche to allumer douche

==> /var/log/openhab2/openhab.log <==

2018-04-02 10:18:15.390 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----allumer douche----
2018-04-02 10:18:15.396 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----allumer douche----
2018-04-02 10:18:15.398 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----allumer douche----
2018-04-02 10:18:15.399 [INFO ] [smarthome.model.script.voice control] - VoiceCommand received----allumer douche----
2018-04-02 10:18:15.406 [INFO ] [.eclipse.smarthome.model.script.cmd ] - ONtwo condition works
==> /var/log/openhab2/events.log <==

Try to use spaces instead of “tabs” to indent your code
It is more consistent and easier to copy and paste between editors

 if ( command.contains("éteins") || command.contains("turn off") || command.contains("eteins") || command.contains("éteindre")) {
  1. There is no } to close your “bain” if condition:
    if (command.contains("bain") || command.contains("ben"))  {
        logInfo("cmd ", "bain: " + cmd )	
        sdblight.sendCommand(cmd)
        sdblight.postUpdate(cmd)
        appliqueSwitch.sendCommand(cmd)
        appliqueSwitch.postUpdate(cmd)  
        SP2_1.sendCommand(cmd)
        SP2_1.postUpdate(cmd)
    }

Thanks/Merci !!!

it works

now, i have an integration with voice command and google assistant!!!