├── .gitignore ├── README.md ├── fibaro_fgr_222 ├── down.png ├── up.png ├── README.md └── fibaro_fgr_222.groovy └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # smartthings 2 | a repository with my smartthings stuff 3 | -------------------------------------------------------------------------------- /fibaro_fgr_222/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/julienbachmann/smartthings/HEAD/fibaro_fgr_222/down.png -------------------------------------------------------------------------------- /fibaro_fgr_222/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/julienbachmann/smartthings/HEAD/fibaro_fgr_222/up.png -------------------------------------------------------------------------------- /fibaro_fgr_222/README.md: -------------------------------------------------------------------------------- 1 | # Fibaro FGR 222 2 | Smartthings device handler for Fibaro roller shutter 2. Unfortunatly this device handler does not work for roller shutter 3. 3 | 4 | # Installation 5 | From your smartthings IDE (http://ide.smartthings.com), create a new Device Hanlder and paste this code in `From code` tab. 6 | 7 | To install your micro module, disconnect power supply, then wire the micro module to the switch and to the motor. Then before your re-connect the power supply, go to your smartthings app and click on `Add a Thing` and then re-connect power supply. 8 | 9 | The smartthings app should automatically detect the new thing and ask you to set a name. You can also choose the switch type you are using: momentary, toggle or single button. 10 | 11 | When you click `done`, wait some seconds and roller shutter will automatically perform a calibration to set max and min boundaries. 12 | 13 | You can now use your roller shutter in smartthings app. 14 | 15 | 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Julien 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /fibaro_fgr_222/fibaro_fgr_222.groovy: -------------------------------------------------------------------------------- 1 | metadata { 2 | definition (name: "Fibaro FGR-222", namespace: "julienbachmann", author: "Julien Bachmann") { 3 | capability "Sensor" 4 | capability "Actuator" 5 | 6 | capability "Switch" 7 | capability "Switch Level" 8 | capability "Window Shade" 9 | 10 | capability "Polling" 11 | capability "Power Meter" 12 | capability "Energy Meter" 13 | capability "Refresh" 14 | capability "Configuration" 15 | 16 | attribute "syncStatus", "enum", ["syncing", "synced"] 17 | 18 | command "sync" 19 | command "stop" 20 | command "up" 21 | command "down" 22 | 23 | fingerprint inClusters: "0x26,0x32" 24 | } 25 | 26 | tiles(scale: 2) { 27 | multiAttributeTile(name:"mainTitle", type:"generic", width:6, height:4, canChangeIcon: true) { 28 | tileAttribute("device.windowShade", key: "PRIMARY_CONTROL") { 29 | attributeState "open", label:'Open', backgroundColor:"#ffa81e", action: "close", nextState: "closing" 30 | attributeState "partially open", label:'Partial', backgroundColor:"#d45614", action: "open", nextState: "opening" 31 | attributeState "closed", label:'Closed', backgroundColor:"#00a0dc", action: "open", nextState: "opening" 32 | attributeState "opening", label:'Opening', backgroundColor:"#ffa81e", action: "stop", nextState: "partially open" 33 | attributeState "closing", label:'Closing', backgroundColor:"#00a0dc", action: "stop", nextState: "partially open" 34 | } 35 | tileAttribute("device.level", key: "SLIDER_CONTROL") { 36 | attributeState "level", action:"setLevel", defaultState: true, icon:"st.Home.home9" 37 | } 38 | } 39 | valueTile("power", "device.power", width: 2, height: 2) { 40 | state "default", label:'${currentValue} W' 41 | } 42 | valueTile("energy", "device.energy", width: 2, height: 2) { 43 | state "default", label:'${currentValue} kWh' 44 | } 45 | standardTile("refresh", "device.switch", width: 2, height: 2, inactiveLabel: false, decoration: "flat") { 46 | state "default", label:"Refresh", action:"refresh", icon:"st.secondary.refresh-icon" 47 | } 48 | standardTile(name: "calibrate", width: 2, height: 2, decoration: "flat") { 49 | state "default", action:"configure", label:"Calibrate", backgroundColor:"#0000a8" 50 | } 51 | standardTile(name: "up", width: 2, height: 2, decoration: "flat") { 52 | state "default", action:"up", icon:"https://raw.githubusercontent.com/julienbachmann/smartthings/master/fibaro_fgr_222/up.png?v=3" 53 | } 54 | standardTile(name: "down", width: 2, height: 2, decoration: "flat") { 55 | state "default", action:"down", icon:"https://raw.githubusercontent.com/julienbachmann/smartthings/master/fibaro_fgr_222/down.png?v=3" 56 | } 57 | standardTile("sync", "device.syncStatus", width: 2, height: 2, inactiveLabel: false, decoration: "flat") { 58 | state "default", action:"sync" , label:"Sync", backgroundColor:"#00a800" 59 | state "synced", action:"sync" , label:"Sync", backgroundColor:"#00a800" 60 | state "syncing" , label:"Syncing", backgroundColor:"#a8a800" 61 | } 62 | main(["mainTitle"]) 63 | details(["mainTitle", "up", "power", "refresh", "down", "sync", "calibrate"]) 64 | } 65 | 66 | preferences { 67 | input name: "invert", type: "bool", title: "Invert up/down", description: "Invert up and down actions" 68 | input name: "openOffset", type: "decimal", title: "Open offset", description: "The percentage from which shutter is displayerd as open" 69 | input name: "closeOffset", type: "decimal", title: "Close offset", description: "The percentage from which shutter is displayerd as close" 70 | input name: "offset", type: "decimal", title: "offset", description: "This offset allow to correct the value returned by the device so it match real value" 71 | 72 | section { 73 | input ( 74 | type: "paragraph", 75 | element: "paragraph", 76 | title: "DEVICE PARAMETERS:", 77 | description: "Device parameters are used to customise the physical device. " + 78 | "Refer to the product documentation for a full description of each parameter." 79 | ) 80 | 81 | getParamsMd().findAll( {!it.readonly} ).each { // Exclude readonly parameters. 82 | 83 | def lb = (it.description.length() > 0) ? "\n" : "" 84 | 85 | switch(it.type) { 86 | case "number": 87 | input ( 88 | name: "configParam${it.id}", 89 | title: "#${it.id}: ${it.name}: \n" + it.description + lb +"Default Value: ${it.defaultValue}", 90 | type: it.type, 91 | range: it.range, 92 | required: it.required 93 | ) 94 | break 95 | 96 | case "enum": 97 | input ( 98 | name: "configParam${it.id}", 99 | title: "#${it.id}: ${it.name}: \n" + it.description + lb + "Default Value: ${it.defaultValue}", 100 | type: it.type, 101 | options: it.options, 102 | required: it.required 103 | ) 104 | break 105 | } 106 | } 107 | } // section 108 | } 109 | } 110 | 111 | def parse(String description) { 112 | log.debug("parse ${description}") 113 | def result = null 114 | def cmd = zwave.parse(description, [0x20: 1, 0x26: 3, 0x70: 1, 0x32:3]) 115 | if (cmd) { 116 | result = zwaveEvent(cmd) 117 | if (result) { 118 | log.debug("Dispatch events ${result}") 119 | } 120 | } else { 121 | log.debug("Couldn't zwave.parse ${description}") 122 | } 123 | result 124 | } 125 | 126 | def correctLevel(value) { 127 | def result = value 128 | if (value == "off") { 129 | result = 0; 130 | } 131 | if (value == "on" ) { 132 | result = 100; 133 | } 134 | result = result - (offset ?: 0) 135 | if (invert) { 136 | result = 100 - result 137 | } 138 | return result 139 | } 140 | 141 | def createWindowShadeEvent(value) { 142 | def theWindowShade = "partially open" 143 | if (value >= (openOffset ?: 95)) { 144 | theWindowShade = "open" 145 | } 146 | if (value <= (closeOffset ?: 5)) { 147 | theWindowShade = "closed" 148 | } 149 | return createEvent(name: "windowShade", value: theWindowShade) 150 | } 151 | 152 | def createSwitchEvent(value) { 153 | def switchValue = "on" 154 | if (value >= (openOffset ?: 95)) { 155 | switchValue = "on" 156 | } 157 | if (value <= (closeOffset ?: 5)) { 158 | switchValue = "off" 159 | } 160 | return createEvent(name: "switch", value: switchValue) 161 | } 162 | 163 | def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) { 164 | logger.debug("basic report ${cmd}") 165 | def result = [] 166 | if (cmd.value != null) { 167 | def level = correctLevel(cmd.value) 168 | result << createEvent(name: "level", value: level, unit: "%") 169 | if (device.currentValue('windowShade') == "opening" || device.currentValue('windowShade') == "closing") { 170 | result << response([zwave.meterV2.meterGet(scale: 2).format()]) 171 | } 172 | else { 173 | result << createWindowShadeEvent(level) 174 | } 175 | } 176 | log.debug("basic result ${result}") 177 | return result 178 | } 179 | 180 | def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv3.SwitchMultilevelReport cmd) { 181 | log.debug("switch multi level report ${cmd.value}") 182 | def result = [] 183 | if (cmd.value != null) { 184 | def level = correctLevel(cmd.value) 185 | result << createEvent(name: "level", value: level, unit: "%") 186 | if (device.currentValue('windowShade') == "opening" || device.currentValue('windowShade') == "closing") { 187 | result << response([zwave.meterV2.meterGet(scale: 2).format()]) 188 | } 189 | else { 190 | result << createWindowShadeEvent(level) 191 | } 192 | } 193 | log.debug("switch result ${result}") 194 | return result 195 | } 196 | 197 | def zwaveEvent(physicalgraph.zwave.Command cmd) { 198 | log.debug("other event ${cmd}") 199 | } 200 | 201 | def zwaveEvent(physicalgraph.zwave.commands.meterv3.MeterReport cmd) { 202 | if (cmd.meterType == 1) { 203 | if (cmd.scale == 2) { 204 | def result = [] 205 | result << createEvent(name: "power", value: Math.round(cmd.scaledMeterValue), unit: "W") 206 | if (cmd.scaledMeterValue < 1.0) { 207 | result << createWindowShadeEvent(device.currentValue('level')) 208 | result << response(["delay 500", zwave.switchMultilevelV3.switchMultilevelGet().format()]) 209 | } 210 | else { 211 | result << response(["delay 2000", zwave.switchMultilevelV3.switchMultilevelGet().format()]) 212 | } 213 | log.debug("power result ${result}") 214 | return result 215 | } else { 216 | return createEvent(name: "electric", value: cmd.scaledMeterValue, unit: ["pulses", "V", "A", "R/Z", ""][cmd.scale - 3]) 217 | } 218 | } 219 | } 220 | 221 | def zwaveEvent(physicalgraph.zwave.commands.configurationv1.ConfigurationReport cmd) { 222 | log.debug("zwaveEvent(): Configuration Report received: ${cmd}") 223 | } 224 | 225 | def updated() { 226 | setSynced(); 227 | } 228 | 229 | def on() { 230 | open() 231 | } 232 | 233 | def off() { 234 | close() 235 | } 236 | 237 | def stop() { 238 | def cmds = [] 239 | logger.debug("stop") 240 | cmds << zwave.switchMultilevelV1.switchMultilevelStopLevelChange().format() 241 | cmds << zwave.switchMultilevelV3.switchMultilevelGet().format() 242 | return delayBetween(cmds, 2000) 243 | } 244 | 245 | def up() { 246 | def currentWindowShade = device.currentValue('windowShade') 247 | if (currentWindowShade == "opening" || currentWindowShade == "closing") { 248 | return stop() 249 | } 250 | return open() 251 | } 252 | 253 | def down() { 254 | def currentWindowShade = device.currentValue('windowShade') 255 | if (currentWindowShade == "opening" || currentWindowShade == "closing") { 256 | return stop() 257 | } 258 | return close() 259 | } 260 | 261 | def open() { 262 | logger.debug("open") 263 | sendEvent(name: "windowShade", value: "opening") 264 | if (invert) { 265 | return privateClose() 266 | } 267 | else { 268 | return privateOpen() 269 | } 270 | } 271 | 272 | def close() { 273 | logger.debug("close") 274 | sendEvent(name: "windowShade", value: "closing") 275 | if (invert) { 276 | return privateOpen() 277 | } 278 | else { 279 | return privateClose() 280 | } 281 | } 282 | 283 | def privateOpen() { 284 | def cmds = [] 285 | cmds << zwave.basicV1.basicSet(value: 0xFF).format() 286 | cmds << zwave.switchMultilevelV3.switchMultilevelGet().format() 287 | log.debug("send CMD: ${cmds}") 288 | return delayBetween(cmds, 2000) 289 | } 290 | 291 | def privateClose() { 292 | def cmds = [] 293 | cmds << zwave.basicV1.basicSet(value: 0).format() 294 | cmds << zwave.switchMultilevelV3.switchMultilevelGet().format() 295 | log.debug("send CMD: ${cmds}") 296 | return delayBetween(cmds, 2000) 297 | } 298 | 299 | def presetPosition() { 300 | setLevel(50) 301 | } 302 | 303 | def poll() { 304 | delayBetween([ 305 | zwave.meterV2.meterGet(scale: 0).format(), 306 | zwave.meterV2.meterGet(scale: 2).format(), 307 | ], 1000) 308 | } 309 | 310 | def refresh() { 311 | log.debug("refresh") 312 | delayBetween([ 313 | zwave.switchMultilevelV3.switchMultilevelGet().format(), 314 | zwave.meterV2.meterGet(scale: 2).format(), 315 | ], 500) 316 | } 317 | 318 | def setLevel(level) { 319 | if (invert) { 320 | level = 100 - level 321 | } 322 | if(level > 99) level = 99 323 | if (level <= (openOffset ?: 95) && level >= (closeOffset ?: 5)) { 324 | level = level - (offset ?: 0) 325 | } 326 | 327 | log.debug("set level ${level}") 328 | delayBetween([ 329 | zwave.basicV1.basicSet(value: level).format(), 330 | zwave.switchMultilevelV1.switchMultilevelGet().format() 331 | ], 10000) 332 | } 333 | 334 | def configure() { 335 | log.debug("configure roller shutter") 336 | delayBetween([ 337 | zwave.configurationV1.configurationSet(parameterNumber: 29, size: 1, scaledConfigurationValue: 1).format(), // start calibration 338 | zwave.switchMultilevelV1.switchMultilevelGet().format(), 339 | zwave.meterV2.meterGet(scale: 0).format(), 340 | zwave.meterV2.meterGet(scale: 2).format(), 341 | ], 500) 342 | } 343 | 344 | def sync() { 345 | log.debug("sync roller shutter") 346 | def cmds = [] 347 | sendEvent(name: "syncStatus", value: "syncing", isStateChange: true) 348 | getParamsMd().findAll( {!it.readonly} ).each { // Exclude readonly parameters. 349 | if (settings."configParam${it.id}" != null) { 350 | cmds << zwave.configurationV1.configurationSet(parameterNumber: it.id, size: it.size, scaledConfigurationValue: settings."configParam${it.id}".toInteger()).format() 351 | cmds << zwave.configurationV1.configurationGet(parameterNumber: it.id).format() 352 | } 353 | } 354 | log.debug("send cmds ${cmds}") 355 | runIn(0.5 * cmds.size(), setSynced) 356 | delayBetween(cmds, 500) 357 | } 358 | 359 | def setSynced() { 360 | log.debug("Synced") 361 | sendEvent(name: "syncStatus", value: "synced", isStateChange: true) 362 | } 363 | 364 | private getParamsMd() { 365 | return [ 366 | [id: 3, size: 1, type: "number", range: "0..1", defaultValue: 0, required: false, readonly: false, 367 | name: "Reports type", 368 | description: "0 – Blind position reports sent to the main controller using Z-Wave Command Class.\n" + 369 | "1 - Blind position reports sent to the main controller using Fibar Command Class.\n" + 370 | "Parameters value shoud be set to 1 if the module operates in Venetian Blind mode."], 371 | [id: 10, size: 1, type: "number", range: "0..4", defaultValue: 0, required: false, readonly: false, 372 | name: "Roller Shutter operating modes", 373 | description: "0 - Roller Blind Mode, without positioning\n" + 374 | "1 - Roller Blind Mode, with positioning\n" + 375 | "2 - Venetian Blind Mode, with positioning\n" + 376 | "3 - Gate Mode, without positioning\n" + 377 | "4 - Gate Mode, with positioning"], 378 | [id: 12, size:2, type: "number", range: "0..65535", defaultValue: 0, required: false, readonly: false, 379 | name: "Time of full turn of the slat", 380 | description: "In Venetian Blind mode (parameter 10 set to 2) the parameter determines time of full turn of the slats.\n" + 381 | "In Gate Mode (parameter 10 set to 3 or 4) the parameter defines the COUNTDOWN time, i.e. the time period after which an open gate starts closing. In any other operating mode the parameter value is irrelevant.\n" + 382 | "Value of 0 means the gate will not close automatically.\n" + 383 | "Available settings: 0-65535 (0 - 655,35s)\n" + 384 | "Default setting: 150 (1,5 s)"], 385 | [id: 13, size:1, type: "number", range: "0..2", defaultValue: 0, required: false, readonly: false, 386 | name: "Set slats back to previous position", 387 | description: "In Venetian Blind Mode (parameter 10 set to 2) the parameter influences slats positioning in various situations. In any other operating mode the parameter value is irrelevant.\n" + 388 | "0 - Slats return to previously set position only in case of the main controller operation\n" + 389 | "1 - Slats return to previously set position in case of the main controller operation, momentary switch operation, or when the limit switch is reached.\n" + 390 | "2 - Slats return to previously set position in case of the main controller operation, momentary switch operation, when the limit switch is reached or after " + 391 | " receiving a “STOP” control frame (Switch Multilevel Stop)."], 392 | [id: 14, size:1, type: "number", range: "0..2", defaultValue: 0, required: false, readonly: false, 393 | name: "Switch type", 394 | description: "The parameter settings are relevant for Roller Blind Mode and Venetian Blind Mode (parameter 10 set to 0, 1, 2).\n" + 395 | "0 - Momentary switches\n" + 396 | "1 - Toggle switches\n" + 397 | "2 - Single, momentary switch. (The switch should be connected to S1 terminal)"], 398 | [id: 18, size:1, type: "number", range: "0..255", defaultValue: 0, required: false, readonly: false, 399 | name: "Motor operation detection.", 400 | description: "Power threshold to be interpreted as reaching a limit switch. \n" + 401 | "Available settings: 0 - 255 (1-255 W)\n" + 402 | "The value of 0 means reaching a limit switch will not be detected \n" + 403 | "Default setting: 10 (10W)."], 404 | [id: 22, size:2, type: "number", range: "0..65535", defaultValue: 0, required: false, readonly: false, 405 | name: "Motor operation time.", 406 | description: "Time period for the motor to continue operation. \n" + 407 | "Available settings: 0 – 65535 (0 – 65535s)\n" + 408 | "The value of 0 means the function is disabled.\n" + 409 | "Default setting: 240 (240s. – 4 minutes)"], 410 | [id: 30, size:1, type: "number", range: "0..2", defaultValue: 0, required: false, readonly: false, 411 | name: "Response to general alarm", 412 | description: "0 - No reaction.\n" + 413 | "1 - Open blind.\n" + 414 | "2 - Close blind."], 415 | [id: 31, size:1, type: "number", range: "0..2", defaultValue: 0, required: false, readonly: false, 416 | name: "Response to flooding alarm", 417 | description: "0 - No reaction.\n" + 418 | "1 - Open blind.\n" + 419 | "2 - Close blind."], 420 | [id: 32, size:1, type: "number", range: "0..2", defaultValue: 0, required: false, readonly: false, 421 | name: "Response to smoke, CO or CO2 alarm", 422 | description: "0 - No reaction.\n" + 423 | "1 - Open blind.\n" + 424 | "2 - Close blind."], 425 | [id: 33, size:1, type: "number", range: "0..2", defaultValue: 0, required: false, readonly: false, 426 | name: "Response to temperature alarm", 427 | description: "0 - No reaction.\n" + 428 | "1 - Open blind.\n" + 429 | "2 - Close blind."], 430 | [id: 35, size:1, type: "number", range: "0..2", defaultValue: 0, required: false, readonly: false, 431 | name: "Managing slats in response to alarm.", 432 | description: "0 - Do not change slats position - slats return to the last set position\n" + 433 | "1 - Set slats to their extreme position"], 434 | [id: 40, size:1, type: "number", range: "0..2", defaultValue: 0, required: false, readonly: false, 435 | name: "Power reports", 436 | description: "Power level change that will result in new power value report being sent." + 437 | "The parameter defines a change that needs to occur in order to trigger the report. The value is a percentage of the previous report.\n" + 438 | "Power report threshold available settings: 1-100 (1-100%).\n" + 439 | "Value of 0 means the reports are turned off."] 440 | 441 | ] 442 | } 443 | --------------------------------------------------------------------------------