Hi!
At first of all i have to say, that the HUE Binding does not work as proper as i wanted(sometimes not all bulbs turned on or off). Therefore i used curl request to directly push the requests to hue api. This way i was able to set the Scenes with the hue app and call them.
My Scenario:
Samsung TV turns on (tell me if you want this code). A Rule triggers a switch, which is a randomizer for effectlight. A random number is generated and is passed to the switch condition that calls the specific scenes
rule "Effektlicht Zufall"
when
Item Wohnzimmer_Effektlicht changed to ON
then
var randomNum = rand.nextInt(11)
logInfo("rules","randomnr" + randomNum)
postUpdate(Wohnzimmer_Licht, OFF)
Thread::sleep(1000)
switch randomNum {
case 1: sendCommand(Wohnzimmer_Rotlicht, ON)
case 2: sendCommand(Wohnzimmer_Bayernlicht, ON)
case 3: sendCommand(Wohnzimmer_Blaulicht, ON)
case 4: sendCommand(Wohnzimmer_Effekt_1, ON)
case 5: sendCommand(Wohnzimmer_Effekt_2, ON)
case 6: sendCommand(Wohnzimmer_Effekt_3, ON)
case 7: sendCommand(Wohnzimmer_Effekt_4, ON)
case 8: sendCommand(Wohnzimmer_Effekt_5, ON)
case 9: sendCommand(Wohnzimmer_Effekt_6, ON)
case 10: sendCommand(Wohnzimmer_Effekt_7, ON)
case 0: sendCommand(Wohnzimmer_Effekt_8, ON)
}
end
An example for calling a Scene:
rule "Effekt 8 einstellen"
when
Item Wohnzimmer_Effekt_8 changed to ON
then
var String hueApiCall = "curl@@-X@@PUT@@-d@@{\"scene\": \"%s\" }@@http://192.168.2.253/api/7Sxo426mEW4ka9OGKRB0o2rKIN4GQ5ZgWuSwLwZE/groups/1/action"
executeCommandLine(String::format(hueApiCall, "ZjFI5attO7dvmoY"))
postUpdate(Wohnzimmer_Effektlicht_Status, OFF)
postUpdate(Wohnzimmer_Effektlicht_Status, ON)
end
Explanation of the rule:
"scene": "%s" }<— This is the String you have to Pass to JSON API
http://192.168.2.253/apikey/groups/1/action is the URL you have to call (despite of group number and IP)
executeCommandLine(String::format(hueApiCall, “ZjFI5attO7dvmoY”)) ← this string is the Scene ID you get from the hue JSON API ( Get Started - Philips Hue Developer Program )
To get all Scenes, set a get request to http://ip/api/yourapikey/scenes
postUpdate(Wohnzimmer_Effektlicht_Status, OFF)<— calls a rule that sets all other lights to OFF (to get proper status)
postUpdate(Wohnzimmer_Effektlicht_Status, ON)<— just sets the status to ON after setting it OFF
Relating to Alexa: you can pass all the homekit tags to your items. Alexa can grab them so you can call these items. Official Alexa Smart Home Skill for openHAB 2 helped me alot.
If you have questions, feel free to ask