Created
September 8, 2021 21:01
-
-
Save nayelyzarazua-bluetrail/a28257cfa85d6149de4713f08c3fbcd6 to your computer and use it in GitHub Desktop.
MCD_Edge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local caps = 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 fancy_switch_def = [[{ | |
"id": "commonsmall09402.copySwitch", | |
"version": 1, | |
"status": "proposed", | |
"name": "copy switch", | |
"attributes": { | |
"fancySwitch": { | |
"schema": { | |
"type": "object", | |
"properties": { | |
"value": { | |
"type": "string", | |
"enum": [ | |
"On", | |
"Off" | |
] | |
} | |
}, | |
"additionalProperties": false, | |
"required": [ | |
"value" | |
] | |
}, | |
"enumCommands": [] | |
} | |
}, | |
"commands": { | |
"fancyOff": { | |
"name": "fancyOff", | |
"arguments": [] | |
}, | |
"fancyOn": { | |
"name": "fancyOn", | |
"arguments": [] | |
}, | |
"fancySet": { | |
"name": "fancySet", | |
"arguments": [ | |
{ | |
"name": "state", | |
"optional": false, | |
"schema": { | |
"type": "string", | |
"enum": [ | |
"On", | |
"Off" | |
] | |
} | |
} | |
] | |
} | |
} | |
}]] | |
local zoozLedMode_def = [[{ | |
"id": "platemusic11009.zoozLedMode", | |
"version": 1, | |
"status": "proposed", | |
"name": "Zooz LED Mode", | |
"attributes": { | |
"ledMode": { | |
"schema": { | |
"type": "object", | |
"properties": { | |
"value": { | |
"type": "string", | |
"enum": [ | |
"onWhenOff", | |
"onWhenOn", | |
"alwaysOff", | |
"alwaysOn" | |
] | |
} | |
}, | |
"additionalProperties": false, | |
"required": [ | |
"value" | |
] | |
}, | |
"setter": "setLedMode", | |
"enumCommands": [] | |
} | |
}, | |
"commands": { | |
"setLedMode": { | |
"name": "setLedMode", | |
"arguments": [ | |
{ | |
"name": "value", | |
"optional": false, | |
"schema": { | |
"type": "string", | |
"enum": [ | |
"onWhenOff", | |
"onWhenOn", | |
"alwaysOff", | |
"alwaysOn" | |
] | |
} | |
} | |
] | |
} | |
} | |
}]] | |
local fancySwitch = caps.build_cap_from_json_string(fancy_switch_def) | |
local zoozLedMode = caps.build_cap_from_json_string(zoozLedMode_def) | |
--... | |
local function fancy_on_handler(driver, device, command) | |
log.error("fancy_on_handler") | |
switch_defaults.on(driver, device, command) | |
end | |
local function fancy_off_handler(driver, device, command) | |
log.error("fancy_off_handler") | |
switch_defaults.off(driver, device, command) | |
end | |
local function fancy_set_handler(driver, device, command) | |
log.error("fancy_set_handler") | |
if command.args.state == "On" then | |
switch_defaults.on(driver, device, command) | |
elseif command.args.state == "Off" then | |
switch_defaults.off(driver, device, command) | |
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 = { | |
[zcl_clusters.IASZone.ID] = { | |
[zcl_clusters.IASZone.attributes.ZoneStatus.ID] = ias_zone_status_attr_handler | |
} | |
}, | |
zdo = {} | |
} | |
local zigbee_multipurpose_driver_template = { | |
supported_capabilities = { | |
fancy_switch,zoozLedMode, | |
caps.contactSensor, | |
caps.battery, | |
caps.temperatureMeasurement | |
}, | |
capability_handlers = { | |
[fancySwitch.ID] = { | |
[fancySwitch.commands.fancyOn.NAME] = fancy_on_handler, | |
[fancySwitch.commands.fancyOff.NAME] = fancy_off_handler, | |
[fancySwitch.commands.fancySet.NAME] = fancy_set_handler, | |
}, | |
[zoozLedMode.ID] = { | |
[zoozLedMode.commands.setLedMode.NAME] = set_ledMode | |
} | |
}, | |
zigbee_handlers = handlers, | |
ias_zone_configuration_method = constants.IAS_ZONE_CONFIGURE_TYPE.AUTO_ENROLL_RESPONSE, | |
} | |
-- | |
--Run driver | |
defaults.register_for_default_handlers(zigbee_multipurpose_driver_template, {caps.contactSensor,caps.battery,caps.temperatureMeasurement}) | |
local zigbee_multipurpose = ZigbeeDriver("smartthingsMultipurposeSensor", zigbee_multipurpose_driver_template) | |
zigbee_multipurpose:run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment