I am quite clumsy, I have tried several things and I have not succeeded
This could also be used for devices such as a switch, to be able to configure what to do in case of power restoration, go off, on, keep last state, for example.
If the default handlers and libraries haven’t worked for you. Here’s an implementation sample I used to build the TX message directly to write an attribute value:
--imports
local zcl_messages = require "st.zigbee.zcl"
local messages = require "st.zigbee.messages"
local data_types = require "st.zigbee.data_types"
local write_attribute = require "st.zigbee.zcl.global_commands.write_attribute"
local zb_const = require "st.zigbee.constants"
-- Build the complete ZCL message and send it to the device
local build_zcl_message = function(device,cluster_id,zclh,body_message,mfg_specific_code)
local addrh = messages.AddressHeader(
zb_const.HUB.ADDR,
zb_const.HUB.ENDPOINT,
device:get_short_address(),
device:get_endpoint(cluster_id),
zb_const.HA_PROFILE_ID,
cluster_id
)
local message_body = zcl_messages.ZclMessageBody({
zcl_header = zclh,
zcl_body = body_message
})
local txMessage = messages.ZigbeeMessageTx({
address_header = addrh,
body = message_body
})
--Add the manufacturer info if exists
if mfg_specific_code then
txMessage.body.zcl_header.frame_ctrl:set_mfg_specific()
txMessage.body.zcl_header.mfg_code = data_types.validate_or_build_type(mfg_specific_code, data_types.Uint16, "mfg_code")
end
device:send(txMessage)
end
--Function to write a cluster attribute
local build_write_tx_message = function(device, cluster_id, attr_id, mfg_specific_code,attr_type, attr_value)
local zclh = zcl_messages.ZclHeader({
cmd = data_types.ZCLCommandId(write_attribute.WriteAttribute.ID)
})
local attr_write = write_attribute.WriteAttributeAttributeRecord(
data_types.AttributeId(attr_id),
data_types.ZigbeeDataType(data_types[attr_type].ID),
data_types[attr_type](attr_value)
)
local write_body = write_attribute.WriteAttribute({ attr_write })
build_zcl_message(device,cluster_id,zclh,write_body,mfg_specific_code)
end
--usage sample, this is using the values you shared before
buildWriteTxMessage(device, 0x0010, 0x0055, [manufacturerCode-optional], "Boolean", 0x0001)
The parameter mfg_specific_code can be included when the cluster is manufacturer-specific, if not, it can be omitted.