Skip to content

Commit ec9ae32

Browse files
committed
fibaro-rgbw-controller v0.04
installed(): Initialises attribute values in addition to state. updated(): Added check to prevent double execution, and to call installed() if not run.
1 parent a52e699 commit ec9ae32

File tree

2 files changed

+81
-46
lines changed

2 files changed

+81
-46
lines changed

devices/fibaro-rgbw-controller/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Fibaro RGBW Controller (FGRGBWM-441)
22
https://github.com/codersaur/SmartThings/tree/master/devices/fibaro-rgbw-controller
33

4-
Copyright (c) 2016 [David Lomas](https://github.com/codersaur)
4+
Copyright (c) [David Lomas](https://github.com/codersaur)
55

66
## Overview
77

@@ -168,6 +168,10 @@ There are two known bugs in firmware 25.25, which this device handler attempts t
168168

169169
## Version History:
170170

171+
#### 2017-04-17: v0.04
172+
* installed(): Initialises attribute values in addition to state.
173+
* updated(): Added check to prevent double execution, and to call installed() if not run.
174+
171175
#### 2016-11-14: v0.03
172176
* Association Group Members can be edited from the SmartThings GUI.
173177

devices/fibaro-rgbw-controller/fibaro-rgbw-controller.groovy

Lines changed: 76 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
2-
* Copyright 2016 David Lomas (codersaur)
2+
* Copyright David Lomas (codersaur)
33
*
44
* SmartThings Device Handler for: Fibaro RGBW Controller EU v2.x (FGRGBWM-441)
55
*
6-
* Version: 0.03 (2016-11-14)
6+
* Version: 0.04 (2017-04-17)
77
*
88
* Source: https://github.com/codersaur/SmartThings/tree/master/devices/fibaro-rgbw-controller
99
*
@@ -611,7 +611,7 @@ metadata {
611611
"1" : "1: Start favourite program"]
612612

613613
}
614-
614+
615615
section { // ASSOCIATION GROUPS:
616616
input type: "paragraph", element: "paragraph",
617617
title: "ASSOCIATION GROUPS:", description: "Enter a comma-delimited list of node IDs for each association group.\n" +
@@ -888,62 +888,93 @@ def zwaveEvent(physicalgraph.zwave.Command cmd) {
888888
* installed() - Runs when the device is first installed.
889889
**/
890890
def installed() {
891+
log.trace "installed()"
892+
891893
state.debug = true
892894
state.installedAt = now()
893895
state.lastReset = new Date().format("YYYY/MM/dd \n HH:mm:ss", location.timeZone)
894896
state.channelMapping = [null, "Red", "Green", "Blue", "White"]
895897
state.channelThresholds = [null,1,1,1,1]
896898
state.channelModes = [null,1,1,1,1]
899+
900+
// Initialise attributes:
901+
sendEvent(name: "switch", value: "off", displayed: false)
902+
sendEvent(name: "level", value: 0, unit: "%", displayed: false)
903+
sendEvent(name: "hue", value: 0, unit: "%", displayed: false)
904+
sendEvent(name: "saturation", value: 0, unit: "%", displayed: false)
905+
sendEvent(name: "colorName", value: "custom", displayed: false)
906+
sendEvent(name: "color", value: "[]", displayed: false)
907+
sendEvent(name: "activeProgram", value: 0, displayed: false)
908+
sendEvent(name: "energy", value: 0, unit: "kWh", displayed: false)
909+
sendEvent(name: "power", value: 0, unit: "W", displayed: false)
910+
sendEvent(name: "lastReset", value: state.lastReset, displayed: false)
911+
912+
(1..4).each { channel ->
913+
sendEvent(name: "switchCh${channel}", value: "off", displayed: false)
914+
sendEvent(name: "levelCh${channel}", value: 0, unit: "%", displayed: false)
915+
}
916+
917+
["Red", "Green", "Blue", "White"].each { mapping ->
918+
sendEvent(name: "switchCh${mapping}", value: "off", displayed: false)
919+
sendEvent(name: "levelCh${mapping}", value: 0, unit: "%", displayed: false)
920+
}
921+
922+
state.isInstalled = true
897923
}
898924

899925
/**
900926
* updated() - Runs after device settings have been changed in the SmartThings GUI (and/or IDE?).
901-
*
902-
* Note, the updated() method is not a 'command', so it doesn't send commands by default.
903-
* To execute commands from updated() you have to specifically return a HubAction object.
904-
* The response() helper wraps commands up in a HubAction so they can be sent from parse() or updated().
905-
* See: https://community.smartthings.com/t/remotec-z-thermostat-configuration-with-z-wave-commands/31956/12
906927
**/
907928
def updated() {
908929
if ("true" == configDebugMode) log.trace "${device.displayName}: updated()"
909930

910-
state.debug = ("true" == configDebugMode)
911-
912-
// Convert channel mappings to a map:
913-
def cMapping = []
914-
cMapping[1] = configCh1Mapping
915-
cMapping[2] = configCh2Mapping
916-
cMapping[3] = configCh3Mapping
917-
cMapping[4] = configCh4Mapping
918-
state.channelMapping = cMapping
919-
920-
// Convert channel thresholds to a map:
921-
def cThresholds = []
922-
cThresholds[1] = configCh1Threshold.toInteger()
923-
cThresholds[2] = configCh2Threshold.toInteger()
924-
cThresholds[3] = configCh3Threshold.toInteger()
925-
cThresholds[4] = configCh4Threshold.toInteger()
926-
state.channelThresholds = cThresholds
927-
928-
// Convert channel modes to a map:
929-
def cModes = []
930-
cModes[1] = configParam14_1.toInteger()
931-
cModes[2] = configParam14_2.toInteger()
932-
cModes[3] = configParam14_3.toInteger()
933-
cModes[4] = configParam14_4.toInteger()
934-
state.channelModes = cModes
935-
936-
// Validate Paramter #14 settings:
937-
state.isRGBW = ( state.channelModes[1] < 8 ) || ( state.channelModes[2] < 8 ) || ( state.channelModes[3] < 8 ) || ( state.channelModes[4] < 8 )
938-
state.isIN = ( state.channelModes[1] == 8 ) || ( state.channelModes[2] == 8 ) || ( state.channelModes[3] == 8 ) || ( state.channelModes[4] == 8 )
939-
state.isOUT = ( state.channelModes[1] > 8 ) || ( state.channelModes[2] > 8 ) || ( state.channelModes[3] > 8 ) || ( state.channelModes[4] > 8 )
940-
if ( state.isRGBW & ( (state.channelModes[1] != state.channelModes[2]) || (state.channelModes[1] != state.channelModes[3]) || (state.channelModes[1] != state.channelModes[4]) ) ) {
941-
log.warn "${device.displayName}: updated(): Invalid combination of RGBW channels detected. All RGBW channels should be identical. You may get weird behaviour!"
942-
}
943-
if ( state.isRGBW & ( state.isIN || state.isOUT ) ) log.warn "${device.displayName}: updated(): Invalid combination of RGBW and IN/OUT channels detected. You may get weird behaviour!"
944-
945-
// Call configure() and refresh():
946-
return response( [ configure() + refresh() ])
931+
if (!state.updatedLastRanAt || now() >= state.updatedLastRanAt + 2000) {
932+
state.updatedLastRanAt = now()
933+
934+
// Make sure installation has completed:
935+
if (!state.isInstalled) { installed() }
936+
937+
state.debug = ("true" == configDebugMode)
938+
939+
// Convert channel mappings to a map:
940+
def cMapping = []
941+
cMapping[1] = configCh1Mapping
942+
cMapping[2] = configCh2Mapping
943+
cMapping[3] = configCh3Mapping
944+
cMapping[4] = configCh4Mapping
945+
state.channelMapping = cMapping
946+
947+
// Convert channel thresholds to a map:
948+
def cThresholds = []
949+
cThresholds[1] = configCh1Threshold.toInteger()
950+
cThresholds[2] = configCh2Threshold.toInteger()
951+
cThresholds[3] = configCh3Threshold.toInteger()
952+
cThresholds[4] = configCh4Threshold.toInteger()
953+
state.channelThresholds = cThresholds
954+
955+
// Convert channel modes to a map:
956+
def cModes = []
957+
cModes[1] = configParam14_1.toInteger()
958+
cModes[2] = configParam14_2.toInteger()
959+
cModes[3] = configParam14_3.toInteger()
960+
cModes[4] = configParam14_4.toInteger()
961+
state.channelModes = cModes
962+
963+
// Validate Paramter #14 settings:
964+
state.isRGBW = ( state.channelModes[1] < 8 ) || ( state.channelModes[2] < 8 ) || ( state.channelModes[3] < 8 ) || ( state.channelModes[4] < 8 )
965+
state.isIN = ( state.channelModes[1] == 8 ) || ( state.channelModes[2] == 8 ) || ( state.channelModes[3] == 8 ) || ( state.channelModes[4] == 8 )
966+
state.isOUT = ( state.channelModes[1] > 8 ) || ( state.channelModes[2] > 8 ) || ( state.channelModes[3] > 8 ) || ( state.channelModes[4] > 8 )
967+
if ( state.isRGBW & ( (state.channelModes[1] != state.channelModes[2]) || (state.channelModes[1] != state.channelModes[3]) || (state.channelModes[1] != state.channelModes[4]) ) ) {
968+
log.warn "${device.displayName}: updated(): Invalid combination of RGBW channels detected. All RGBW channels should be identical. You may get weird behaviour!"
969+
}
970+
if ( state.isRGBW & ( state.isIN || state.isOUT ) ) log.warn "${device.displayName}: updated(): Invalid combination of RGBW and IN/OUT channels detected. You may get weird behaviour!"
971+
972+
// Call configure() and refresh():
973+
return response( [ configure() + refresh() ])
974+
}
975+
else {
976+
log.debug "updated(): Ran within last 2 seconds so aborting."
977+
}
947978
}
948979

949980
/**

0 commit comments

Comments
 (0)