Issue of the topic:
I have lights that can be set to 5 scenes ranging from OFF (0) to All lights at 100% (4). Each scene value of each light is persisted.
Switch Light_VH_Woonkamer_Leeslampje // The light itself
Switch Light_VH_Woonkamer_Leeslampje_S1 // S1 value, there is no S0 as S0 is OFF
Switch Light_VH_Woonkamer_Leeslampje_S2 // S2 value
Switch Light_VH_Woonkamer_Leeslampje_S3 // S3 value, there is no S4 as S0 is 100%/ON
I then have a rule that sends the appropriate value when the scene is selected.All the cases are written out full but that results in much code; 5 cases times 10 lights, you get the picture.
So I am thinking to shorten the code by using “receivedCommand” in my sendCommand code:
rule "Woonkamer Scenes"
when
Item Scene_VH_Woonkamer received command
then
// 0="Uit", 1="TV", 2="Cosy", 3="Lezen", 4="Maximaal"
switch (receivedCommand){
case 0:{
sendCommand(Light_VH_Woonkamer_Leeslampje, OFF)
}
case 1,
case 2,
case 3:{
sendCommand(Light_VH_Woonkamer_Leeslampje, "Light_VH_Woonkamer_Leeslampje_S" + receivedCommand + ".state.toString")
}
case 4:{
sendCommand(Light_VH_Woonkamer_Leeslampje, "ON")
}
}
end
I was hoping that this would result in using the received command to send the right scene value but in stead I get the following errors:
2020-03-14 16:10:41.871 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert 'Light_VH_Woonkamer_Leeslampje_S1.state.toString' to a command type which item 'Light_VH_Woonkamer_Leeslampje' accepts: [OnOffType, RefreshType].
It looks like the 2nd part of the sendCommand sees a string where I expected it to be “ON” of “OFF”
I’m not quite sure what you want to achieve here for case 3 though. You say “ON” of “OFF”, but under what circumstances for case 3? Don’t you want to piece together the item receiving the command, not the command itself as you are doing now?
What I am trying to archieve is that if the scene command is 1, 2 or 3 that item Light_VH_Woonkamer_Leeslampje is receiving the persisted value (ON of OFF) that is part of that scene. So in scene 1 the light is OFF but in scene 2 its ON.
So I want to piece together on of the 3 possible values and send it to the light based on the receivedCommand.
The code I used is just a small part of the total code, my livingroom has about 15 different lights, be it ON/OFF or Dimmertypes. I now have about 4 pages of sendCommand clauses with case statements to make it work
3 possible values - since Light_VH_Woonkamer_Leeslampje is defined as a Switch it should only have the two On or OFF possible values (disregarding a 3rd UNDEF :). Also sicne you have 5 different scenes why don’t oyu hard code the ON/OFF value for each lanp within these 5 switch cases.
rule "Woonkamer Scenes"
when
Item Scene_VH_Woonkamer received command
then
// 0="Uit", 1="TV", 2="Cosy", 3="Lezen", 4="Maximaal"
switch (receivedCommand){
case 0 : {
sendCommand(Light_VH_Woonkamer_Leeslampje, OFF)
}
case 1 : {
sendCommand(Light_VH_Woonkamer_Leeslampje, OFF)
}
case 2 : {
sendCommand(Light_VH_Woonkamer_Leeslampje, ON)
}
case 3:{
sendCommand(Light_VH_Woonkamer_Leeslampje, ON)
}
case 4:{
sendCommand(Light_VH_Woonkamer_Leeslampje, ON)
}
}
end
For the dimmers you can define different vlaues being sent for each of the switch cases.
I set these switches by another piece of code that learns my scene. For this lets presume in scene 1 the light is off , for scene 2 its on and for 3 off again:
```csv
Switch Light_VH_Woonkamer_Leeslampje_S1 => OFF
Switch Light_VH_Woonkamer_Leeslampje_S2 => ON
Switch Light_VH_Woonkamer_Leeslampje_S3 => OFF
these values are persisted. So now I send scene “1” the value of Switch Light_VH_Woonkamer_Leeslampje_S1 is being send to the light, which is OFF in this case.
I am trying to reduce the number of lines in my rules files. At the moment I have have 5 case statements of which 3 (1,2 and 3) have 15 lines each. The only thing that differs in the 1,2 & 3 case lines is the “S_”, underscore being 1, 2 or 3. So yes, I want to concatenate the names as well.
Then I’m afraid I’m stuck with getting the string, which you will always end up with the concatination, to an OnOffType from which you need to get the state.
Someone else might be able to point you in the right direction.
The problem is exactly what it says.
You have a string “someItem.state.toSring”, which is not a suitable command for a switch. .
It’s just a string.
It might look like an Item name etc., but it’s not going to get evaluated.
It’s just a string, exactly like “xxx” or “stop system now”
If you have a string and you would like to get the Item that has a name of that string …
This will send the value Light_VH_Woonkamer_Leeslampje_S1 in case of scene 1 to my light Light_VH_Woonkamer_Leeslampje, Light_VH_Woonkamer_Leeslampje_S2 in case of scene 2 etc.