Advertisement
Guest User

Untitled

a guest
Apr 24th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 2.87 KB | None | 0 0
  1. /**
  2.  *  LiFX
  3.  *
  4.  *  Copyright 2014 Josh Doehla / TechUnity
  5.  *
  6.  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  7.  *  in compliance with the License. You may obtain a copy of the License at:
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  12.  *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  13.  *  for the specific language governing permissions and limitations under the License.
  14.  *
  15.  */
  16.  
  17. preferences {
  18.     input("server", "text", title: "Server", description: "Server IP")
  19.     input("port", "text", title: "Port", description: "Server Port")
  20.     input("url", "text", title: "URL", description: "Server URL")
  21.     input("group", "text", title: "Group", description: "Group # ('0' for all bulbs)")
  22. }
  23.  
  24. metadata {
  25.     definition (name: "MiLight", namespace: "DougWare", author: "Doug Eubanks") {
  26.         capability "Switch"
  27.         capability "Color Control"
  28.         capability "Switch Level"
  29.         capability "Configuration"
  30.         capability "Color Control"
  31.         capability "Color Temperature"
  32.     }
  33. }
  34.  
  35. simulator {
  36. }
  37.  
  38. tiles {
  39.     standardTile("offSwitch", "device.switch", width: 1, height: 1, canChangeIcon: true) {
  40.         state "off", label:'Off', action:"switch.off", icon:"st.Lighting.light11", backgroundColor:"#bbbbbb"
  41.     }
  42.     standardTile("onSwitch", "device.switch", width: 1, height: 1, canChangeIcon: true)
  43.     {
  44.         state "on", label:'On', action:"switch.on", icon:"st.Lighting.light11", backgroundColor:"#ffffff"
  45.     }
  46.     controlTile("levelSliderControl", "device.level", "slider", height: 1, width: 3, inactiveLabel: false)
  47.     {
  48.         state "level", action:"switch level.setLevel"
  49.     }
  50.     controlTile("rgbSelector", "device.color", "color", height: 3, width: 3, inactiveLabel: false) {
  51.         state "color", action:"setColor"
  52.     }
  53.     main "offSwitch"
  54.     details(["offSwitch","onSwitch","levelSliderControl","rgbSelector"])
  55. }
  56.  
  57. def on() {
  58.     httpGet("https://${settings.server}:${settings.port}/Milight/milight1.php?command=on&group=${settings.group}", successClosure)
  59.     sendEvent(name: 'level', value: "100")
  60. }
  61.  
  62. def off() {
  63.     httpGet("https://${settings.server}:${settings.port}/Milight/milight1.php?command=off&group=${settings.group}", successClosure)
  64.     sendEvent(name: 'level', value: "0")
  65. }
  66.  
  67. def setLevel(value) {
  68.     def levelDecimal = new BigDecimal(value)
  69.     httpGet("https://${settings.server}:${settings.port}/Milight/milight1.php?command=brightness&group=${settings.group}&brightness=${levelDecimal}", successClosure)
  70. }
  71.  
  72. def setColor(colormap) {
  73.     httpGet("https://${settings.server}:${settings.port}/Milight/milight1.php?command=color&group=${settings.group}&color=${colormap.hex}", successClosure)
  74. }
  75.  
  76. def successClosure = { response ->
  77.   log.debug "Request was successful"
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement