How to send a zigbee cmd payload like readAttribute

Hello!
I have a ZigBee device. How to change this exmaple to send a Command ID:[0x04] payload?

local read_body = read_attribute.ReadAttribute({0x0000})
local zclh = zcl_messages.ZclHeader({
  cmd = data_types.ZCLCommandId(read_attribute.ReadAttribute.ID)
})
local addrh = zb_messages.AddressHeader(
    zb_const.HUB.ADDR,
    zb_const.HUB.ENDPOINT,
    0xDEAD,
    0x01,
    zb_const.HA_PROFILE_ID,
    0x0006
)
local message_body = zcl_messages.ZclMessageBody({
  zcl_header = zclh,
  zcl_body = read_body
})
local built_message = zb_messages.ZigbeeMessageTx({
  address_header = addrh,
  body = message_body
})
print(built_message:pretty_print(zb_utils.MULTILINE_FORMAT_CONFIG))
-- ZigbeeMessageTx:
--    Uint16: 0x0000
--    AddressHeader:
--        src_addr: 0x0000
--        src_endpoint: 0x01
--        dest_addr: 0xDEAD
--        dest_endpoint: 0x01
--        profile: 0x0104
--        cluster: OnOff
--    ZCLMessageBody:
--        ZCLHeader:
--            frame_ctrl: 0x00
--            seqno: 0x00
--            ZCLCommandId: 0x00
--        ReadAttribute:
--            AttributeId: 0x0000

I want to send a paylaod like this Command

device:send(built_message)
1 Like

Do you need that low-level code? The clusters library already has read and write commands to create the requests that you just send.

Like

command = Level.attributes.OnOffTransitionTime:write(device, 0)
device:send(command)
1 Like

Thank you, but that’s not what I wanted. I didn’t express clearance

Thank you, but that’s not what I wanted. I didn’t express clearance :rofl:

I see you’ve edited the first post and did not want to set an attribute but send a command. The point stands though, do you need that low-level code?

For standard clusters this is enough:

local command = Level.commands.MoveToLevelWithOnOff(device, 254, 0)
device:send(command)

Thank you.But I have a private cluster. I want custom cmd payload like this. :rofl:

That’s why it’s important to be precise in the questions, at first if was “set an attribute” (write), then it was send a MoveToLevelWithOnOff command (standard cluster), now it’s a custom cluster.

You can check how some community drivers for Tuya devices do it, they create the definition for the custom clusters: EdgeDrivers/personal-tuya-devices/src/init.lua at beta · w35l3y/EdgeDrivers · GitHub . There, zcl_clusters.TuyaEF00 is not a standard cluster but provided with the driver, you can see the code at EdgeDrivers/personal-tuya-devices/src/st/zigbee/generated/zcl_clusters/TuyaEF00 at beta · w35l3y/EdgeDrivers · GitHub

I believe you’ll have to create the definition of your cluster if it includes custom commands so it plays nice with the rest of the SmartThings library that validates the requests and handles the responses.

2 Likes

Thank you very much. :sob:

1 Like