Zw.command Syntax Question - Adding variable in hex string

Command is: zw.Command(0x91, 0x00, ‘\x1D\x0D\x01\xFF\x00’))

I need to change the hex value for last byte. Something like:

zw.Command(0x91, 0x00, ‘\x1D\x0D\x01\xFF\x’…value)) where value would be a 2-digit hex string.

All combinations of providing this has been fruitless.

Apologies for simple questions – I am trying to program after 20 years of rust.



I think you’re trying to do something like:

local byteValue = 0x55  -- hex 55
local cmdString = string.format("\x1D\x0D\x01\xFF%c", byteValue) 
-- cmdString should now contain the string (shown as embedded escaped bytes) '\x1D\x0D\x01\xFF\x55'
zw.Command(0x91, 0x00, cmdString)
  • Use the %c conversion to output the character byte from the input directly
  • You can’t leave a hanging \x in your string, as there is no value after it when the string is interpreted

I didn’t test this but I think it gets what you want.

A couple other notes:

  • I would use symbol names for things like command class ID’s. I might even create a define for the 0x00 command value, whatever it maps to with your specific device you’re working with. Symbols are always better than magic numbers.
local cc = require "st.zwave.CommandClass"
zw.Command(cc.MANUFACTURER_PROPRIETARY, 0x00, cmdString)
  • zw.Command won’t actually send anything on the radio - you’ll have to use the :send() functions for that of course. zw.Command just creates a command formatted zwave object.