|
1 | 1 | /** |
2 | | - * Copyright 2016 David Lomas (codersaur) |
| 2 | + * Copyright David Lomas (codersaur) |
3 | 3 | * |
4 | 4 | * SmartThings Device Handler for: Fibaro RGBW Controller EU v2.x (FGRGBWM-441) |
5 | 5 | * |
6 | | - * Version: 0.03 (2016-11-14) |
| 6 | + * Version: 0.04 (2017-04-17) |
7 | 7 | * |
8 | 8 | * Source: https://github.com/codersaur/SmartThings/tree/master/devices/fibaro-rgbw-controller |
9 | 9 | * |
@@ -611,7 +611,7 @@ metadata { |
611 | 611 | "1" : "1: Start favourite program"] |
612 | 612 |
|
613 | 613 | } |
614 | | - |
| 614 | + |
615 | 615 | section { // ASSOCIATION GROUPS: |
616 | 616 | input type: "paragraph", element: "paragraph", |
617 | 617 | 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) { |
888 | 888 | * installed() - Runs when the device is first installed. |
889 | 889 | **/ |
890 | 890 | def installed() { |
| 891 | + log.trace "installed()" |
| 892 | + |
891 | 893 | state.debug = true |
892 | 894 | state.installedAt = now() |
893 | 895 | state.lastReset = new Date().format("YYYY/MM/dd \n HH:mm:ss", location.timeZone) |
894 | 896 | state.channelMapping = [null, "Red", "Green", "Blue", "White"] |
895 | 897 | state.channelThresholds = [null,1,1,1,1] |
896 | 898 | 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 |
897 | 923 | } |
898 | 924 |
|
899 | 925 | /** |
900 | 926 | * 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 |
906 | 927 | **/ |
907 | 928 | def updated() { |
908 | 929 | if ("true" == configDebugMode) log.trace "${device.displayName}: updated()" |
909 | 930 |
|
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 | + } |
947 | 978 | } |
948 | 979 |
|
949 | 980 | /** |
|
0 commit comments