Generic Zigbee Devices (pushbuttons and motion detectors) that work well with Hubitat Elevation

Hi folks,

I've invested a lot of time searching for cheap Zigbee devices below the $20AUD mark that profess to be Zigbee compatible. Most of them say you need to buy a special hub to allow the device to work and do not provide a model number we can use to see if there is a proper driver available. Often you need to get the device and do a lot of playing around to find the right driver, if one is available at all!

Anyway, I have done a lot of the legwork and found some that definitely work on the Hubitat Elevation, albeit with some additional modified drivers (which I will add to this post). I haven't had time to adjust the drivers to auto-detect the devices, but you can manually choose the driver for the device yourself. I am not in any way affiliated with these sellers - this post is purely to help you avoid wasting money on sensors that do not work or time on sensors that do not have a driver.

So here it is, and I hope this helps. All of the devices below I have proven to work well:

Motion Sensors

TS0202 – on stand, CR2450 & TS0202 – small round, CR2450

Use “TS0202 RH3040 Tuya ZigBee Motion Sensor.groovy” by Mikhail Diatchenko

RH3040 – flat top on stand, CR2450

Use “TS0202 RH3040 Tuya ZigBee Motion Sensor.groovy” by Mikhail Diatchenko

RH3040 (3xAAA rechargeable batteries)

Use “TS0202 RH3040 Tuya ZigBee Motion Sensor.groovy” by Mikhail Diatchenko.

Note that all these devices seem to suffer from mechanical connectivity problems with the batteries so you have to juggle the batteries around a bit to get them to stay in. Given AAAs are much longer lasting and easy to get rechargeable ones (and better for the planet not creating extra toxic waste) I am going to persevere with these and add a little solder to make the batteries connect better.

Aqara PIR – on stand (CR2450) – Model = lumi.sensor_motion.aq2

Driver: “Zigbee – Xiaomi Aqara Motion Sensor.groovy” by Markus Liljergren

Pushbuttons

TS0044 Black or white 4 gang pushbuttons.

Use the inbuilt 'Tuya Zigbee Scene Switch' driver.

TS0043 Pushbuttons, 3 gang Pushbuttons.

Use the inbuilt ‘Tuya Zigbee Scene Switch’ driver.

6 gang Pushbutton Aqara OPPLE. Model=lumi.remote.b686opcn01

Use the “Zigbee - Xiaomi Aqara Opple Button Switch Remote.groovy” driver by Markus Liljergren
I have to say this 6 button switch, while more expensive, has been my favourite because it has six different options for activating flows and has a magnetic clip so you can make it portable if you wish. It is not designed to easily replace the button battery but there are some tutorials around to help you do this via removing the button panels.

4 Likes

TS0202 RH3040 Tuya ZigBee Motion Sensor.groovy

All credit to Mikhail Diatchenko's good efforts to get this working.

/**
 *  Konke ZigBee Motion Sensor
 *  Device Driver for Hubitat Elevation hub
 *  Version 1.0.2
 *
 *  Based on code from Robert Morris and ssalahi.
 *
 *  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.
 *
 */

// https://community.hubitat.com/t/konke-motion-sensor/21240/3

import hubitat.zigbee.clusters.iaszone.ZoneStatus
import com.hubitat.zigbee.DataType

metadata {
	definition (name: "TS0202 RH3040 Tuya ZigBee Motion Sensor", namespace: "muxa", author: "Mikhail Diatchenko") {
		capability "MotionSensor"
		capability "Battery"
//        capability "PushableButton"
		capability "Configuration"
        capability "Refresh"
        capability "Sensor"
		capability "Motion Sensor"

        command "active"
        command "inactive"        
        
        fingerprint endpointId: "01", profileId: "0104", inClusters: "0000,0001,0003,0500", outClusters: "0000,0001,0003,0500", manufacturer: "_TYZB01_dl7cejts", model: "TS0202", application:"21"      
        fingerprint endpointId: "01", profileId: "0104", inClusters: "0001,0500,0003,0000", outClusters: "1000,0006,0019,000A", manufacturer: "_TZ3000_mmtwjmaq", model: "TS0202", application:"43"      
	}

	preferences {
		input "motionreset", "number", title: "After motion is detected, wait ___ second(s) until resetting to inactive state. Default = 16 seconds (Hardware resets at 15 seconds)", description: "", range: "1..7200", defaultValue: 16
        input "batteryReportingHours", "number", title: "Report battery every ___ hours. Default = 12h (Minimum 2 h)", description: "", range: "2..12", defaultValue: 12
		
		input name: "infoLogging", type: "bool", title: "Enable info message logging", description: ""
		input name: "debugLogging", type: "bool", title: "Enable debug message logging", description: ""
	}
}

// Parse incoming device messages to generate events
def parse(String description) {

    Map map = [:]
    // logDebug("Parsing: $description")
	if (description?.startsWith('zone status')) {	
         logDebug("Zone status: $description")    
        def zs = zigbee.parseZoneStatus(description)
        map = parseIasMessage(zs)
    }
    else if (description?.startsWith("catchall") || description?.startsWith("read attr"))
    {
        Map descMap = zigbee.parseDescriptionAsMap(description)        
        if (descMap.clusterInt == zigbee.POWER_CONFIGURATION_CLUSTER && descMap.attrInt == 0x0020) {
            map = parseBattery(descMap.value)
        } else if (descMap.command == "07") {
            // Process "Configure Reporting" response            
            if (descMap.data[0] == "00") {
                switch (descMap.clusterInt) {
                    case zigbee.POWER_CONFIGURATION_CLUSTER:
                        logInfo("Battery reporting configured");                        
                        break
                    default:                    
                        log.warn("Unknown reporting configured: ${descMap}");
                        break
                }
            } else {
                log.warn "Reporting configuration failed: ${descMap}"
            }
        } else if (descMap.clusterInt == 0x0500 && descMap.attrInt == 0x0002) {
            logDebug("Zone status repoted: $descMap")
            def zs = new ZoneStatus(Integer.parseInt(descMap.value, 16))
            map = parseIasMessage(zs)        
        } else if (descMap.clusterInt == 0x0500 && descMap.attrInt == 0x0011) {
            logInfo("IAS Zone ID: ${descMap.value}")
        } else if (descMap.profileId == "0000") {
        
           
            // ignore routing table messages
        } else {
            log.warn ("Description map not parsed: $descMap")            
        }
    }
    //------IAS Zone Enroll request------//
	else if (description?.startsWith('enroll request')) {
		logInfo "Sending IAS enroll response..."
		return zigbee.enrollResponse()
	}
      else {
        log.warn "Description not parsed: $description"
    }
    
    if (map != [:]) {
		//logInfo(map.descriptionText)
		logInfo(description)
		return createEvent(map)
	} else
		return [:]
}

// helpers -------------------

def parseIasMessage(ZoneStatus zs) {
        if ((zs.alarm1 || zs.alarm2) && zs.battery == 0 && zs.trouble == 0) {
            // Motion detected
	        return handleMotion(true)
        }
        else if (zs.tamper == 1 && zs.battery == 1 && zs.trouble == 1 && zs.ac == 1) {
            logDebug "Device button pressed"
            map = [
		        name: 'pushed',
		        value: 1,
                isStateChange: true,
                descriptionText: "Device button pushed"
	        ]
        }
        else {
//            log.warn "Zone status message not parsed"
//            if (debugLogging) {
//                logDebug "zs.alarm1 = $zs.alarm1"
//                logDebug "zs.alarm2 = $zs.alarm2"
//                logDebug "zs.tamper = $zs.tamper"
//                logDebug "zs.battery = $zs.battery"
//                logDebug "zs.supervisionReports = $zs.supervisionReports"
//                logDebug "zs.restoreReports = $zs.restoreReports"
//                logDebug "zs.trouble = $zs.trouble"
//                logDebug "zs.ac = $zs.ac"
//                logDebug "zs.test = $zs.test"
//                logDebug "zs.batteryDefect = $zs.batteryDefect"
//            }
        }
}

private handleMotion(motionActive) {    
    if (motionActive) {
        def timeout = motionreset ?: 16
        // The sensor only sends a motion detected message so reset to motion inactive is performed in code
        runIn(timeout, resetToMotionInactive)        
        if (device.currentState('motion')?.value != "active") {
            state.motionStarted = now()
        }
    }
    
	return getMotionResult(motionActive)
}

def getMotionResult(motionActive) {
	def descriptionText = "Detected motion"
    if (!motionActive) {
		descriptionText = "Motion reset to inactive after ${getSecondsInactive()}s"
    }
	return [
			name			: 'motion',
			value			: motionActive ? 'active' : 'inactive',
			descriptionText : descriptionText
	]
}

def resetToMotionInactive() {
	if (device.currentState('motion')?.value == "active") {
		def descText = "Motion reset to inactive after ${getSecondsInactive()}s"
		sendEvent(
			name:'motion',
			value:'inactive',
			// isStateChange: true,
			descriptionText: descText
		)
		logInfo(descText)
	}
}

def getSecondsInactive() {
    if (state.motionStarted) {
        return Math.round((now() - state.motionStarted)/1000)
    } else {
        return motionreset ?: 16
    }
}


def active() {
    sendEvent(name: "motion", value: "active")
    runIn(12, off)
}

def inactive() {
    sendEvent(name: "motion", value: "inactive")
}


// Convert 2-byte hex string to voltage
// 0x0020 BatteryVoltage -  The BatteryVoltage attribute is 8 bits in length and specifies the current actual (measured) battery voltage, in units of 100mV.
private parseBattery(valueHex) {
	//logDebug("Battery parse string = ${valueHex}")
	def rawVolts = Integer.parseInt(valueHex, 16) / 10 // hexStrToSignedInt(valueHex)/10
	def minVolts = voltsmin ? voltsmin : 2.5
	def maxVolts = voltsmax ? voltsmax : 3.0
	def pct = (rawVolts - minVolts) / (maxVolts - minVolts)
	def roundedPct = Math.min(100, Math.round(pct * 100))
	def descText = "Battery level is ${roundedPct}% (${rawVolts} Volts)"
	//logInfo(descText)
    // sendEvent(name: "batteryLevelLastReceived", value: new Date())    
	def result = [
		name: 'battery',
		value: roundedPct,
		unit: "%",
		//isStateChange: true,
		descriptionText: descText
	]
	return result
}

// lifecycle methods -------------

// installed() runs just after a sensor is paired
def installed() {
	logInfo("Installing")    
//	sendEvent(name: "numberOfButtons", value: 1, descriptionText: "Device installed")
    return refresh()
}

// configure() runs after installed() when a sensor is paired or reconnected
def configure() {
	logInfo("Configuring")
    
    return configureReporting()
}

def refresh() {
	logInfo("Refreshing")

    return zigbee.readAttribute(zigbee.POWER_CONFIGURATION_CLUSTER, 0x0020) // battery voltage
}

// updated() runs every time user saves preferences
def updated() {
	logInfo("Updating preference settings")
    
    return configureReporting()
}

// helpers -------------

private def configureReporting() {
    def seconds = Math.round((batteryReportingHours ?: 12)*3600)
    
    logInfo("Battery reporting frequency: ${seconds/3600}h")    
    
    return zigbee.configureReporting(zigbee.POWER_CONFIGURATION_CLUSTER, 0x0020, DataType.UINT8, seconds, seconds, 0x01)
        + zigbee.readAttribute(zigbee.POWER_CONFIGURATION_CLUSTER, 0x20)
}

private def logDebug(message) {
	if (debugLogging) log.debug "${device.displayName}: ${message}"
}

private def logInfo(message) {
	if (infoLogging)
		log.info "${device.displayName}: ${message}"
}

The awesome Markus Liljergren (https://oh-lalabs.com) wrote the other drivers mentioned.
As per this post:
[Release] Xiaomi / Aqara / Opple Drivers with Presence!

2 Likes

Also if you are considering buying the RH3040 model, have a read of the limitations in the reviews before you buy. Once it detects movement, there is a 2-3 minute cooldown period during which it won't send another activation. Fine if you are just switching on a garage light, not so great if you are switching on lights as you walk down a corridor and then need to walk back again!

See the reviews here: https://www.amazon.com/Samotech-Zigbee-Motion-Sensor-Generation/dp/B07WDQCVV4/ref=cm_cr_arp_d_product_top?ie=UTF8

I have luck with this Smart ZigBee Scene Switch 4 Gang Remote as well:

(use 23A battery)

Yeah this one I bought too. I don't have a LR 23A 12V battery to test it yet though as it's kind of an unusual and expensive battery but it looks pretty sleek to have on the wall. It would be great if you can post which driver you used to make it work in Hubitat?

I use the standard 'Tuya Zigbee Scene Switch' driver for the remote. Yup, the battery is unusual.

Just wanted to provide an update.

I ordered this 4 gang switch and it DOES NOT work with the Tuya Zigbee scene switch driver. The model I received is id'd in the pairing as TS004F.

It works with this custom driver. The old TS0044 switches seems to be not produced anymore.

Change the driver and pair it again close to the hub.

1 Like

Wow thanks for the quick response. It really wasn't an issue as I also use zigbee2mqtt so I was just informing others.

To your knowledge are these switches tuya zigbee or are they aqara zigbee (which has issues with certain repeaters)

1 Like

They are Tuya Zigbee, inheriting all Tuya oddities .. :slight_smile: But no problems with Zigbee repeaters.

1 Like

Hello,
I am still new to Hubitat and trying to link this to the hub:

https://www.aliexpress.com/item/4001365407192.html?spm=a2g0o.order_list.0.0.21ef1802yn4NrD

You mentioned we should use "Tuya Zigbee Scene Switch" driver! but I couldn't find it!

Do you mind more details? I would appreciate that.

Thanks alot!

Its a custom driver written by @kkossev that you install

Click on "Drivers Code" link on your hubitat, then in upper right corner click "New Driver". Open the link below in a new browser tab, select all and then switch back to your hubitat tab and paste the code in the driver code editor window. Then click "Save"

You can also click the "import" button and paste the url below.

Now pair your scene switch and it should automatically pick the new driver you just installed.

Here's the link to the driver code
https://raw.githubusercontent.com/kkossev/Hubitat/main/Drivers/Tuya%20TS004F/TS004F.groovy

Thanks alot, very simple instructions! my buttons will arrive in few days but I am wondering does this code support the TS0044 also? the ones I shared are not TS004F.
Thank you.

TS0044 works out if the box using HE inbuilt driver.

Sorry for the dumb question, what do you mean with inbuilt driver? do you mean I should use this?
New device > add by brand > Tuya switch > 4gang

Thanks!

No, you must select 'Tuya ZigBee Scene Switch' for TS0044.

Once the device is paired to the Hub, if the driver that was automatically selected is not the right one, go to device page and manually change the driver to the one above, select it from the list.

1 Like

The device type can be seen in the 'data' section of the device page. It could be either TS0044 (use the inbuilt Tuya zigbee scene switch driver) or it could be TS004F (use the custom driver). Usually, you don't know what you will receive from the seller, until you pair it to the Hub.

1 Like

Thank you! one last question if you don't mind, how you set up the tiles to the right button (1 click, long, double)?

Sorry, I am not sure whether I understand the question.. To use the scene switch to control some lights or something else, you can try the Button Controller inbuilt app.

2 Likes