[RELEASE] Fibaro Dimmer 2 (FGS-212) Driver

Here is my attempt at a driver for the Fibaro Dimmer 2.

All parameters listed nice a neat and I added syncPending state so users know when a sync has completed.

Full operation tested including central scene ID's which can be read by webCoRE to trigger events based on the number of clicks.

Any issues let me know!!


.


I added to the compatible device wiki.

1 Like

thank you… haven’t seen the wiki yet… let alone requested editing permissions.

Edit: Ahhhh… it’s not a wiki, you mean the wiki category lol… I’ve added my Fibaro Double Relay driver to the list as well.

1 Like

Hey Robin, Nice looking driver, but for me it won't work.
I have a FGD-211 device. Older model

Do you have a way that this can be modified for so my FGD-211 can work?
I just got a Hubitat and moving from a VeraPlus.

Thanks, Jack

Give this a try.

/**
 *  Copyright 2015 SmartThings
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 */
metadata {
	definition (name: "Fibaro Dimmer 2 UK", namespace: "smartthings", author: "rajiv") {
		capability "Energy Meter"
		capability "Actuator"
		capability "Switch"
		capability "Power Meter"
		capability "Polling"
		capability "Refresh"
		capability "Sensor"
		capability "Configuration"
        capability "Switch Level"

		command "reset"
        command "configureAfterSecure"

        fingerprint deviceId: "0x1001", inClusters: "0x5E, 0x20, 0x86, 0x72, 0x26, 0x5A, 0x59, 0x85, 0x73, 0x98, 0x7A, 0x56, 0x70, 0x31, 0x32, 0x8E, 0x60, 0x75, 0x71, 0x27, 0x22, 0xEF, 0x2B"
	}

	// simulator metadata
	simulator {
    	status "on":  "command: 2003, payload: FF"
		status "off": "command: 2003, payload: 00"
		status "09%": "command: 2003, payload: 09"
		status "10%": "command: 2003, payload: 0A"
		status "33%": "command: 2003, payload: 21"
		status "66%": "command: 2003, payload: 42"
		status "99%": "command: 2003, payload: 63"

		for (int i = 0; i <= 10000; i += 1000) {
			status "power  ${i} W": new hubitat.zwave.Zwave().meterV3.meterReport(
				scaledMeterValue: i, precision: 3, meterType: 4, scale: 2, size: 4).incomingMessage()
		}
		for (int i = 0; i <= 100; i += 10) {
			status "energy  ${i} kWh": new hubitat.zwave.Zwave().meterV3.meterReport(
				scaledMeterValue: i, precision: 3, meterType: 0, scale: 0, size: 4).incomingMessage()
		}
        
        ["FF", "00", "09", "0A", "21", "42", "63"].each { val ->
			reply "2001$val,delay 100,2602": "command: 2603, payload: $val"
		}
	}

	// tile definitions
    
	tiles(scale: 2) {
    	multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){
			tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
				attributeState "on", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState:"turningOff"
				attributeState "off", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"turningOn"
				attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState:"turningOff"
				attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"turningOn"
			}
			tileAttribute ("device.level", key: "SLIDER_CONTROL") {
				attributeState "level", action:"switch level.setLevel"
			}
		}
		valueTile("power", "device.power", decoration: "flat", width: 2, height: 2) {
			state "default", label:'${currentValue} W'
		}
		valueTile("energy", "device.energy", decoration: "flat", width: 2, height: 2) {
			state "default", label:'${currentValue} kWh'
		}
		standardTile("reset", "device.energy", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
			state "default", label:'reset kWh', action:"reset"
		}    
		standardTile("configureAfterSecure", "device.configure", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
			state "configure", label:'', action:"configureAfterSecure", icon:"st.secondary.configure"
		}
		standardTile("refresh", "device.power", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
			state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
		}

		main(["switch","power","energy"])
		details(["switch","power","energy","configureAfterSecure","refresh","reset"])
	}
}

def parse(String description) {
	log.trace(description)
	def result = null
    
    if (description != "updated") {
		def cmd = zwave.parse(description, [0x20: 1, 0x26: 3, 0x32: 3, 0x25: 1, 0x98: 1, 0x70: 1, 0x85: 2, 0x9B: 1, 0x90: 1, 0x73: 1, 0x30: 1, 0x28: 1, 0x72: 1])
		if (cmd) {
			result = zwaveEvent(cmd)
		}
    }
    log.debug "Parsed '${description}' to ${result.inspect()}"
	return result
}

// Devices that support the Security command class can send messages in an encrypted form;
// they arrive wrapped in a SecurityMessageEncapsulation command and must be unencapsulated
def zwaveEvent(hubitat.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
	log.trace(cmd)
	def encapsulatedCommand = cmd.encapsulatedCommand([0x20: 1, 0x26: 3, 0x32: 3, 0x25: 1, 0x98: 1, 0x70: 1, 0x85: 2, 0x9B: 1, 0x90: 1, 0x73: 1, 0x30: 1, 0x28: 1, 0x72: 1]) // can specify command class versions here like in zwave.parse
	if (encapsulatedCommand) {
		return zwaveEvent(encapsulatedCommand)
	} else {
		log.warn "Unable to extract encapsulated cmd from $cmd"
		createEvent(descriptionText: cmd.toString())
	}
}

def zwaveEvent(hubitat.zwave.commands.basicv1.BasicReport cmd) {
	log.trace(cmd)
	dimmerEvents(cmd)
}

def zwaveEvent(hubitat.zwave.commands.basicv1.BasicSet cmd) {
	log.trace(cmd)
	dimmerEvents(cmd)
}
def zwaveEvent(hubitat.zwave.commands.switchmultilevelv3.SwitchMultilevelReport cmd) {
	log.trace(cmd)
	dimmerEvents(cmd)
}

def zwaveEvent(hubitat.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd)
{
	log.trace(cmd)
	dimmerEvents(cmd)
}


def dimmerEvents(hubitat.zwave.Command cmd) {
	log.trace(cmd)
	def result = []
	def value = (cmd.value ? "on" : "off")
	def switchEvent = createEvent(name: "switch", value: value, descriptionText: "$device.displayName was turned $value")
	result << switchEvent
	if (cmd.value) {
		result << createEvent(name: "level", value: cmd.value, unit: "%")
	}
	if (switchEvent.isStateChange) {
		result << response(["delay 3000", zwave.meterV2.meterGet(scale: 2).format()])
	}
	return result
}

def zwaveEvent(hubitat.zwave.commands.meterv3.MeterReport cmd) {
	log.trace(cmd)
	if (cmd.meterType == 1) {
		if (cmd.scale == 0) {
			return createEvent(name: "energy", value: cmd.scaledMeterValue, unit: "kWh")
		} else if (cmd.scale == 1) {
			return createEvent(name: "energy", value: cmd.scaledMeterValue, unit: "kVAh")
		} else if (cmd.scale == 2) {
			return createEvent(name: "power", value: Math.round(cmd.scaledMeterValue), unit: "W")
		} else {
			return createEvent(name: "electric", value: cmd.scaledMeterValue, unit: ["pulses", "V", "A", "R/Z", ""][cmd.scale - 3])
		}
	}
}

def zwaveEvent(hubitat.zwave.Command cmd) {
	log.trace(cmd)
	log.debug "No handler for $cmd"
	// Handles all Z-Wave commands we aren't interested in
	createEvent(descriptionText: cmd.toString(), isStateChange: false)
}


def on() {
	log.trace("on")
	secureSequence([
			zwave.basicV1.basicSet(value: 0xFF),
            zwave.switchMultilevelV1.switchMultilevelGet()
	])
}

def off() {
	log.trace("off")
	secureSequence([
			zwave.basicV1.basicSet(value: 0x00),
            zwave.switchMultilevelV1.switchMultilevelGet()
	])
}

def poll() {
	log.trace("poll")
	secureSequence([
		zwave.meterV2.meterGet(scale: 0),
		zwave.meterV2.meterGet(scale: 2)
	])
}

def refresh() {
	log.trace("trace")
	secureSequence([
		zwave.meterV2.meterGet(scale: 0),
		zwave.meterV2.meterGet(scale: 2)
	])
}

def reset() {
	log.trace("reset")
	return secureSequence([
    	zwave.switchMultilevelV1.switchMultilevelGet(),
		zwave.meterV2.meterReset(),
		zwave.meterV2.meterGet(scale: 0),
        zwave.meterV2.meterGet(scale: 2)
	])
}

def setLevel(level) {
	log.trace("setlevel")
	if(level > 99) level = 99
	secureSequence([
		zwave.basicV1.basicSet(value: level),
		zwave.switchMultilevelV1.switchMultilevelGet()
	], 5000)
}

def configureAfterSecure() {
    log.debug "configureAfterSecure()"
        secureSequence([
		zwave.configurationV1.configurationSet(parameterNumber: 20, size: 1, scaledConfigurationValue: 1),	// Enable Dimmer to work with Toggle Switch
		zwave.configurationV1.configurationSet(parameterNumber: 26, size: 1, scaledConfigurationValue: 1),	// S2 can control dimmer as well
		zwave.configurationV1.configurationSet(parameterNumber: 32, size: 1, scaledConfigurationValue: 1),	// On/Off Mode (0=Dimmer,1=On/Off,2=Auto)
		zwave.configurationV1.configurationSet(parameterNumber: 35, size: 1, scaledConfigurationValue: 0),	// Auto Calibration (0=No after Power On, 1=On First Power On, 2=On Each Power On)

		// Register for Group 1
        zwave.associationV2.associationSet(groupingIdentifier:1, nodeId: [zwaveHubNodeId]),
        // Register for Group 2
        zwave.associationV2.associationSet(groupingIdentifier:2, nodeId: [zwaveHubNodeId]),
	])
}

def configure() {
	// Wait until after the secure exchange for this
    log.debug "configure()"
}

def updated() {
	log.debug "updated()"
	response(["delay 2000"] + configureAfterSecure() + refresh())
}

private secure(hubitat.zwave.Command cmd) {
	log.trace(cmd)
	zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
}

private secureSequence(commands, delay=200) {
	log.debug "$commands"
	delayBetween(commands.collect{ secure(it) }, delay)
}

My goodness. I much appreciate your efforts to help me.

I tried to add it, but it errors out "unexpected token: } @ line 57, column 1." so I can't save it.

I just tried it. It saves. Make sure you're pasting it into the driver code, not the app code section.

Saves fine for me.. as a Driver.

Pick Driver Code on the left...

make sure you get the ENTIRE bucket of code. Starts with "/** " Ends with "}" 260 lines later.

You're right. My bad. Copy/paste I must have missed a line. So now it saved fine.

But it does not work. On/off-fail, so I can't test anything else.
I noticed the parameter settings don't show up for setting as well.

What I have done in the past is to load the driver that shows all the parameters. This DH doesn't work for me but it does show the parameters.
I then set the parameters to what I want and then sync the device.
I then go back to the driver that I posted above and the device gets the parameters that I have just sync'd and it works just fine for me.
A lot of messing around I know but I'm a tinkerer at heart. :wink:

Let me see if I got this right.....
First I assign the driver with the parameters to the dimmer. Then I go through and set the parameters and " to set" button click for each parameter.

Then I go and assign your new driver to this device which will still retain the parameters.

Is that what you mean?

Yes. That is what I have done in the past.

I went about trying this out, but quickly see I do not think this will work. My FGD 211 dimmer parameters do not correlate with the FGS 212 parameters. So if I set the driver parameters for say min level, on my parameter number I would be setting maybe a switch type. See what I mean?

In fact my parameter 14 sets mono-stable switch or bi-stable switch. This is #1 important setting, and the driver here does not even have a parameter 14.

So I do not know enough code to be able to modify the parameter settings.
If you look at the FGD 211 dimmer manual pdf it shows parameters and defaults. When I factory reset my device, it did not apply ANY defaults to these parameters, so now all my devices are royally screwed up and I cannot reset them.

I just found a Smarthings 211 dimmer driver on git hub.

Can this be ported to Hubitat ok?

Also I just found a Smarthings FGD-211 dimmer driver on Git Hub.

And the secondary binder.....

Can this be ported to Hubitat ok?

Should work... just change all references to 'physicalgraph' to 'hubitat ', then give it a try.

Note that this old v1 handler does not give you granular control over the parameters, you have to tweak them in the handler code itself.

Great, Thank you for your info!

I will give it a try.

Hi guys,

Forgive me if i ask some silly questions, fairly new to home automation, brand new to Hubitat.

@Robin
I saw that you had made a fibaro dimmer 2 driver for hubitat (I have dimmer 2's in every light switch in my house) which is what made me jump from ST to hubitat. So excited to have local rather than cloud processing but a bit deflated after having them working perfectly with ST and now struggling with them on Hubistat. :pensive:

Unfortunately I must be missing something, maybe a setting somewhere or something as I cant get them to work properly, really intermittent problems, mainly that the 'software' buttons dont do anything.
I should mention a few things... I am using the fibaro relays in most zones as I have LED lamps in all of my light fittings, when I use the physical switch the hub records the state correctly oh and also have the UK version of the hub.

I would be grateful for any help or suggestions. Oh and thanks for writing the driver in the first place. Cant wait to get this resolved and start interesting everything else to hubitat. :blush:

Thank in advance,
Dave

It's possible you have the devices added but not in secure mode, can you try adding one right next to the hub (you'll need extension leads to move the hub I'm afraid).

I only ever setup one of these devices for testing, for a short period, and haven't adopted Hubitat beyond that.

Secure mode? How would i know if i am or not? What is the cause of adding a device in insecure mode?

Plus I had 1 device working with the driver, as soon as I used the driver on the second device they both stopped working. Odd.

Really want to like HE. The response time after pressing a soft button and the device acting makes ST seem crap. Being bit of a ball ache though.