Thanx for your feedback. There are three reasons why i like Dimmer or Number for scenes.
- Selection in sitemap only allows numbers or ON/OFF as value
- Numbers in the database are better than strings
- Visualization in Grafana is a lot easier with numbers
What i don’t like is that you have to define constants als mappings in every rules file to get better readable rules because global imports or constants for all rules are not possible.
// global definition for scene (enum)
val POWEROFF = 0
val MUSIC = 1
val FILM = 2
In the rule i am using these constants to get better readable code:
rule "Set multimedia scene"
when
Item Scenes_Multimedia received command
then
switch receivedCommand as Number {
case POWEROFF: {
// power off every multimedia device
}
case MUSIC: {
// play music in all rooms
}
case FILM: {
// play youtube on chromecast
}
}
end
It would be great to be able to use the transform map scenes.map as kind of enum table.
0=POWEROFF
POWEROFF=0
1=MUSIC
MUSIC=1
2=FILM
FILM=2
To get a mapping in both directions you have to set one mapping with the scene number as key and the scene name as value and a second mapping with key/value swapped. But then you would get duplicate entries in a selection if that would be possible. So what is missing is a transform entry that works in both directions like an enum does.
In the rules file you then woud need something like:
rule "Set multimedia scene"
when
Item Scenes_Multimedia received command
then
switch receivedCommand.toString {
case transform("MAP", "scenes.map", "POWEROFF"): {
// power off every multimedia device
}
case transform("MAP", "scenes.map", "MUSIC"): {
// play music in all rooms
}
case transform("MAP", "scenes.map", "FILM"): {
// play youtube on chromecast
}
}
end
This would be some kind of global enum but it is not readable very well in my opinion.
And the other big problem is that there is no way to use this mapping in the selection. So scenes have to be hard coded in the sitemap which is not very nice. Here is a discussion about this missing feature:
Selection with transform.map file as map items
At the moment it is not possible with the transform map.
So adding constants as mapping where needed is the way i go at the moment.
Or do you have any better solution for something like a global enum?