Voice Command - rule - rollershutters

Hello everyone,

Maybe you have an idea how I can simplify my rule.
I want to bring my shutters to a certain height by voice command (10, 20, 30, …, 100). So far my rule looks like this:

rule "Voice"
when
Item VoiceCommand received command
then
var String command = receivedCommand.toString.toLowerCase
logInfo("Voice.Rec","VoiceCommand received "+command)


if (command.contains("10")&&command.contains("rollo"))
{
 
 if (command.contains("1")) {
 S1.sendCommand(10)
 }
 else if (command.contains("2")) {
 S2.sendCommand(10)
 }
 else if (command.contains("3")) {
 S3.sendCommand(10)
 }
 else if (command.contains("4")) {
 S4.sendCommand(10)
 }
 else if (command.contains("5")) {
 S5.sendCommand(10)
 }
 else if (command.contains("küche")&&command.contains("tür")) {
 S6.sendCommand(10)
 }
 else if (command.contains("küche")&&command.contains("fenster")) {
 S7.sendCommand(10)
 }
 else if (command.contains("wc")) {
 GF_Toilet_Shutter.sendCommand(10)
 }
 else if (command.contains("htr")) {
 GF_LaundryRoom_Shutter.sendCommand(10)
 }
 else if (command.contains("bad")) {
 FF_Bathroom_Shutter.sendCommand(10)
 }
 else if (command.contains("schlafzimmer")) {
 FF_Bedroom_Shutter.sendCommand(10)
 }
 else if (command.contains("lilia")) {
 FF_KidsRoom_Shutter.sendCommand(10)
 }
 else if (command.contains("johannes")) {
 FF_GuestRoom_Shutter.sendCommand(10)
 }
 
}
end

This works so far. Unfortunately I would have to do it nine more times. That somehow doesn’t seem very effective to me.

Is there a more clever way?

Best regards!

switch(expression) {
  case x:
    // code block
    break;
  case y:
    // code block
    break;
  default:
    // code block
}

So

rule "Voice"
when
Item VoiceCommand received command
then
var String command = receivedCommand.toString.toLowerCase
logInfo("Voice.Rec","VoiceCommand received "+command)

if (command.contains("10")&&command.contains("rollo"))
{
    switch (command) {
    case '1' : S1.sendCommand(10)
    case '2' : S2.sendCommand(10)
    }
}

end

Something like this might be easer

case 'küchentür' : S6.sendCommand(10)

Will this work, too?

I am unsure of the message that you recieve.

You may need to transform the message to make it easy for a switch case but yes that should work.

switch case is able to use any type, so

switch(string) {
    case "one":
    case "two":
    case "three":
}

will also work. But you have to use only one type per switch, so this is not allowed:

switch(object) {
    case "one":
    case "two":
    case 3:
}

Instead you have to ensure, that the number is a string:

switch(object.toString) {
    case "one":
    case "two":
    case "3":
}
2 Likes

I do not have rollershutters.
When I compare it to setup for lightning I would have assumed that it is possible to do this without setting up a specific rule.
For lightning setup like it is required for loudness of a receiver e.g.

Dimmer      Yamaha_Volume          "Yamaha_Lautstaerke [%.1f %%]"          ["Lighting"]         { channel="yamahareceiver:zone:9ab0c000_f668_11de_9976_4c1b8626444e:Main_Zone:zone_channels#volume" }

I just need to say: Alexa, turn down the Yamaha Lautstaerke to 50%
Doesn’t this similar work for roller shutter setup ?