I found a workaround, but wanted to point out that some generated cluster definitions do not take into account the nullability of attributes, for instance OnLevel:
local request = clusters.LevelControl.attributes.OnLevel:write(device, endpoint_id, value)
device:send(request)
If value is an integer it sends the command fine, if it’s nil it throws a validation error:
[string “st/matter/data_types/init.lua”]:164: Error creating Uint8: [string “st/matter/data_types/base_defs/UintABC.lua”]:95: Uint8 value must be an integer"
Also tried to build a Null type and pass it as value, just in case.
local null_value = data_types.validate_or_build_type(nil, data_types.Null)
But will complain again:
“[string “st/matter/generated/zap_clusters/LevelControl…”]:68: Expecting Uint8 (0x04) for “Uint8” received Null: Null”
OnLevel is a nullable attribute, has the X qualifier in Matter specification and the nullable field is true in the XML cluster definition.
The workaround
If someone needs to write a nullable attribute and the generated cluster won’t let them, just manually create the whole request for the null value, in this case it would be:
local data_types = require "st.matter.data_types"
local cluster_base = require "st.matter.cluster_base"
...
local null_value = data_types.validate_or_build_type(nil, data_types.Null)
local request = cluster_base.write(device, endpoint_id, 0x0008, 0x0011, nil, null_value)