Nice posting. Some comments about the Rules (since I don’t know anything about HABPanel widgets I can’t comment there).
-
If you are on OH 2 you should not import anything from org.openhab. Remove all of your imports.
-
sqeezeServer, squeezeplayer, station1, station2, station3, and station4 are all constants, use val instead of var to declare them.
-
you should add a default case and set kitchenPlaylist to “off” or to some other value that you test for later and report an error for unknown values of KitchenMusicPlaylist. This will save your butt in the long run when you add a new station but forget to update the switch.
The Rule is nice and short. I like it. I do have some advanced things you might consider to make it even shorter and flexible. These are not necessarily mutually compatible nor necessary, they just might be something people wouldn’t consider trying.
-
Design Pattern: Human Readable Names in Messages - put the mapping between your KitchenMusicPlaylist.state and station into a .map file. You can then replace all of the stationx constants as well as your switch statement with
kitchenPlaylist = transform("MAP", "stations.map", KitchenMusicPlaylist.state)
This will also let you add or change stations in the future without needing to touch your Rules file. -
Design Pattern: Encoding and Accessing Values in Rules combined with Design Pattern: Associated Items - Create a Group for the stations and an Item for each stations using a name that can be constructed from the value of KitchenMusicPlaylist.state. Set the state of these station Items to the values in your global vars. You can then replace your global station variables and your switch statement with
kitchenPlaylist = Stations.members.findFirst[station | station.name = "Station_" + KitchenMusicPlaylist.state.toString].state.toString
You can add/remove/change stations by adding new Items following the DPs above to initialize them to the proper value without needing to modify this Rule.
Keep up the good work!