Set Vocal reminders through chromecast

Hi,

I am trying to use the voicecommand to set an alarm like “Alarm in 5 minutes oven”

After, the 5 minutes, it should say through my chromecast audio “Alarm over after 5 minutes oven”

   rule "Voice control alarm"
   when
    Item VoiceCommand received command
    then

    var String command = VoiceCommand.state.toString.toLowerCase
    logInfo("voice control" ;"VoiceCommand received----" + command+ "----";)

    var String cmd = null
    var Timer timer = null

    if ( command.contains("alarm") || command.contains("alarme ") {

    command = command.replace("alarme ")
    command = command.replace("alarm ";)
    command = command.replace("dans ")// command = command.replace(" in ","")//

    val SplitVoiceTimer = command.state.toString.split(" ")
    val myminutes = Float::parseFloat(SplitVoiceTimer get(0) ) as Number //212

    val cmd = SplitVoiceTimer get(1)

    if(timer==null) {
    timer = createTimer(now.plusMinutes(myminutes)) [
    say ("Alarme apres "+ minutes + " minutes pour "+ cmd)
    timer = null
    ]
    }
    }
  1. What is your opinion on this code ?

  2. the fact is that if the purpose of the reminder is composed of two words, it will give back only the first.

  3. i have looked inxtend/documentation, i didn’t find a method to find the first occurence of a string or to find the position in a string on array item.

Thanks in advance for your help

What are you trying to accomplish with the calls to replace? Typically you provide two arguments, the String you want to replace and the String you want to replace it with.

This is probably completely syntactically incorrect.

If the first word in the voice command isn’t a Number you will get errors.

Timer’s require ints, not floating point numbers so even if the first word of the voice command is a number, if it has a decimal this will fail with errors.

You should use consistent indentation. Every time you have a { all the subsequent lines should be indented until you reach the }.

There a several voice command tutorials and threads on this forum. I recommend searching for those and looking for good ways to handle voice commands.

1 Like