Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
EdgeDrivers_change defaults
local capabilities = require "st.capabilities"
local zcl_clusters = require "st.zigbee.zcl.clusters"
local ZigbeeDriver = require "st.zigbee"
local constants = require "st.zigbee.constants"
local defaults = require "st.zigbee.defaults"
local contact_sensor_defaults = require "st.zigbee.defaults.contactSensor_defaults"
local data_types = require "st.zigbee.data_types"
local common = require("common")
local function acceleration_handler(driver, device, value, zb_rx)
device:emit_event(capabilities.accelerationSensor.acceleration(value.value == 1 and "active" or "inactive"))
end
local function ias_zone_status_change_handler(driver, device, zb_rx)
if (device.preferences.useOnGarageDoor ~= "Yes") then
contact_sensor_defaults.ias_zone_status_change_handler(driver, device, zb_rx)
end
end
local function ias_zone_status_attr_handler(driver, device, zone_status, zb_rx)
if (device.preferences.useOnGarageDoor ~= "Yes") then
contact_sensor_defaults.ias_zone_status_attr_handler(driver, device, zone_status, zb_rx)
end
end
local function added(driver, device)
--Add the manufacturer-specific attributes to generate their configure reporting and bind requests
for capability_id, configs in pairs(common.get_cluster_configurations(device:get_manufacturer())) do
if device:supports_capability_by_id(capability_id) then
for _, config in pairs(configs) do
device:add_configured_attribute(config)
device:add_monitored_attribute(config)
end
end
end
end
----------------------Driver configuration----------------------
local handlers = {
global = {},
cluster = {
[zcl_clusters.IASZone.ID] = {
[zcl_clusters.IASZone.client.commands.ZoneStatusChangeNotification.ID] = ias_zone_status_change_handler
}
},
attr = {
[common.MFG_CLUSTER] = {
[common.ACCELERATION_ATTR_ID] = acceleration_handler,
[common.X_AXIS_ATTR_ID] = common.axis_handler(2, false),
[common.Y_AXIS_ATTR_ID] = common.axis_handler(3, false),
[common.Z_AXIS_ATTR_ID] = common.axis_handler(1, false)
},
[zcl_clusters.IASZone.ID] = {
[zcl_clusters.IASZone.attributes.ZoneStatus.ID] = ias_zone_status_attr_handler
}
},
zdo = {}
}
local zigbee_multipurpose_driver_template = {
supported_capabilities = {
capabilities.contactSensor,
capabilities.battery,
capabilities.threeAxis,
capabilities.accelerationSensor,
capabilities.refresh
},
zigbee_handlers = handlers,
lifecycle_handlers = {
added = added
},
ias_zone_configuration_method = constants.IAS_ZONE_CONFIGURE_TYPE.AUTO_ENROLL_RESPONSE,
sub_drivers = { require("smartthings"), require("samjin") }
}
--Run driver
defaults.register_for_default_handlers(zigbee_multipurpose_driver_template, zigbee_multipurpose_driver_template.supported_capabilities)
local zigbee_multipurpose = ZigbeeDriver("smartthingsMultipurposeSensor", zigbee_multipurpose_driver_template)
zigbee_multipurpose:run()
local zcl_clusters = require "st.zigbee.zcl.clusters"
local tempMeasurement = zcl_clusters.TemperatureMeasurement
local device_management = require "st.zigbee.device_management"
local tempMeasurement_defaults = require "st.zigbee.defaults.temperatureMeasurement_defaults"
local can_handle = function(opts, driver, device)
return device:get_manufacturer() == "Samjin"
end
local function do_configure(self,device)
device:send(device_management.build_bind_request(device, tempMeasurement.ID, self.environment_info.hub_zigbee_eui))
device:send(tempMeasurement.attributes.MeasuredValue:configure_reporting(device, 30, 3600, 200))
device:configure()
end
local function temp_attr_handler(self, device, tempvalue, zb_rx)
tempMeasurement_defaults.temp_attr_handler(self, device, tempvalue, zb_rx)
end
local samjin_sensor = {
NAME = "MultiSensor",
lifecycle_handlers = {
doConfigure = do_configure
},
zigbee_handlers = {
attr = {
[tempMeasurement.ID] = {
[tempMeasurement.attributes.MeasuredValue.ID] = temp_attr_handler
}
}
},
can_handle = can_handle
}
return samjin_sensor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment