cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WB55: Zigbee Reporting OnOff Server Attribute

DL_Weng
Associate II

Hello,


I am trying to use WB55 as a Zigbee device on HomeAssistant. I have made some progress so far, and I can use it as an OnOff switch on HomeAssistant and report my switch status in real-time to HomeAssistant.


At first, I added WB55 to HomeAssistant and it worked very well. I modified the client to server based on the demo, so it changes the OnOff state every second, and I can see its status changes in real time on HomeAssistant. But if I restart the device, I won't see any status changes again when WB55 is reconnected to HomeAssistant. I didn't do anything in HomeAssistant, reconnecting looks completely automatic.


I provided the source code I modified and its logs. I hope to receive an answer.


Thank you
Weng

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @DL_Weng,

After analyzing your case I noticed an issue on the cluster attribute defined by default, as a workaround from the application side, you have to configure the zcl_iaszone_server_attr_list  as follow : 

 

static enum ZclStatusCodeT
zcl_attr_cb(struct ZbZclClusterT *cluster, struct ZbZclAttrCbInfoT *cb);
/* ON OFF CLUSTER */
/* On Off  Attributes persistent flag set */
static const struct ZbZclAttrT zcl_iaszone_server_attr_list[] = {
		{
			ZCL_IAS_ZONE_SVR_ATTR_ZONE_STATUS, ZCL_DATATYPE_BITMAP_16BIT,
			ZCL_ATTR_FLAG_REPORTABLE|ZCL_ATTR_FLAG_PERSISTABLE, 0, NULL, {0, 0}, {0, 0}
		},
	    {
	        ZCL_IAS_ZONE_SVR_ATTR_CIE_ENDPOINT, ZCL_DATATYPE_UNSIGNED_8BIT,
	        ZCL_ATTR_FLAG_INTERNAL | ZCL_ATTR_FLAG_CB_READ | ZCL_ATTR_FLAG_CB_WRITE, 0,
	        zcl_attr_cb, {0, 0}, {0, 0}
	    },
	};

static enum ZclStatusCodeT
zcl_attr_cb(struct ZbZclClusterT *cluster, struct ZbZclAttrCbInfoT *cb)
{
    if (cb->type == ZCL_ATTR_CB_TYPE_READ) {
        return ZCL_STATUS_SUCCESS;
    }
    else if (cb->type == ZCL_ATTR_CB_TYPE_WRITE) {
        return ZCL_STATUS_SUCCESS;
    }
    else {
        return ZCL_STATUS_FAILURE;
    }
}

 

With this configuration, the ZCL_IAS_ZONE_SVR_ATTR_ZONE_STATUS  attribute is persistable, when changing its status, you have to wait ~10sec to receive the notify callback to save the persistence elements.

Best regards,

Ouadi

View solution in original post

7 REPLIES 7
Ouadi
ST Employee

Hi @DL_Weng,

I recommend to use persistence feature in your application that allows to backup the zigbee network parameters already configured as persistable, in your case you should configure ZCL_ONOFF_ATTR_ONOFF to be reportable/Persistable.

You can have a look on the application Zigbee_OnOff_Router_NVM and the wiki page => Zigbee persistent data management and non-volatile memory 

Regards,

Ouadi

Thank you for your response. I am currently implementing the function I want to do based on Zigbee_OnOff_Router_NVM. I have changed OnOff server to IasZone server. Every time I click on SW1, IasZone will be toggled. Based on the experience of OnOff server, it can restore its previous OnOff state after each restart. But even if I turn on IasZone, it will still be in Off state the next time I restart.
I provided new source code and its logs.

Hello,

You have to be sure to wait for APP_ZIGBEE_persist_notify_cb to save persistent data when you change the status of your attribute, then if you restart the device it will be restore the last value stored. 

Regards,

Ouadi

Hi,

I have been waiting for several minutes after opening IasZone and have not seen any logs of "Notification to save persistent data requested from stack". After I restarted, the default status changed back to closed.

I provided the log.

Thanks

DL_Weng

Hi @DL_Weng,

After analyzing your case I noticed an issue on the cluster attribute defined by default, as a workaround from the application side, you have to configure the zcl_iaszone_server_attr_list  as follow : 

 

static enum ZclStatusCodeT
zcl_attr_cb(struct ZbZclClusterT *cluster, struct ZbZclAttrCbInfoT *cb);
/* ON OFF CLUSTER */
/* On Off  Attributes persistent flag set */
static const struct ZbZclAttrT zcl_iaszone_server_attr_list[] = {
		{
			ZCL_IAS_ZONE_SVR_ATTR_ZONE_STATUS, ZCL_DATATYPE_BITMAP_16BIT,
			ZCL_ATTR_FLAG_REPORTABLE|ZCL_ATTR_FLAG_PERSISTABLE, 0, NULL, {0, 0}, {0, 0}
		},
	    {
	        ZCL_IAS_ZONE_SVR_ATTR_CIE_ENDPOINT, ZCL_DATATYPE_UNSIGNED_8BIT,
	        ZCL_ATTR_FLAG_INTERNAL | ZCL_ATTR_FLAG_CB_READ | ZCL_ATTR_FLAG_CB_WRITE, 0,
	        zcl_attr_cb, {0, 0}, {0, 0}
	    },
	};

static enum ZclStatusCodeT
zcl_attr_cb(struct ZbZclClusterT *cluster, struct ZbZclAttrCbInfoT *cb)
{
    if (cb->type == ZCL_ATTR_CB_TYPE_READ) {
        return ZCL_STATUS_SUCCESS;
    }
    else if (cb->type == ZCL_ATTR_CB_TYPE_WRITE) {
        return ZCL_STATUS_SUCCESS;
    }
    else {
        return ZCL_STATUS_FAILURE;
    }
}

 

With this configuration, the ZCL_IAS_ZONE_SVR_ATTR_ZONE_STATUS  attribute is persistable, when changing its status, you have to wait ~10sec to receive the notify callback to save the persistence elements.

Best regards,

Ouadi

I have made modifications based on the code you provided. IasZone server is generally available now.

I still have a question about the value update of IasZone status. According to the Zigbee Cluster Library, a 'Zone Status Change Notification Command' should be generated when the status changes. The log of the command I saw on HomeAssistant is' Report  Attributes'.

Is there any interface that can generate 'Zone Status Change Notification Command'?

The log is as follows:

2024-10-28 15:01:01.353 DEBUG (MainThread) [zigpy.application] Received a packet: ZigbeePacket(timestamp=datetime.datetime(2024, 10, 28, 7, 1, 1, 353598, tzinfo=datetime.timezone.utc), src=AddrModeAddress(addr_mode=<AddrMode.NWK: 2>, address=0x389D), src_ep=17, dst=AddrModeAddress(addr_mode=<AddrMode.NWK: 2>, address=0x0000), dst_ep=1, source_route=None, extended_timeout=False, tsn=0, profile_id=260, cluster_id=1280, data=Serialized[b'\x18\r\n\x02\x00\x19\x01\x00\xfe\xff0\x01'], tx_options=<TransmitOptions.NONE: 0>, radius=29, non_member_radius=0, lqi=112, rssi=None)
2024-10-28 15:01:01.355 DEBUG (MainThread) [zigpy.zcl] [0x389D:17:0x0500] Received ZCL frame: b'\x18\r\n\x02\x00\x19\x01\x00\xfe\xff0\x01'
2024-10-28 15:01:01.355 DEBUG (MainThread) [zigpy.zcl] [0x389D:17:0x0500] Decoded ZCL frame header: ZCLHeader(frame_control=FrameControl<0x18>(frame_type=<FrameType.GLOBAL_COMMAND: 0>, is_manufacturer_specific=0, direction=<Direction.Server_to_Client: 1>, disable_default_response=1, reserved=0, *is_cluster=False, *is_general=True), tsn=13, command_id=10, *direction=<Direction.Server_to_Client: 1>)
2024-10-28 15:01:01.356 DEBUG (MainThread) [zigpy.zcl] [0x389D:17:0x0500] Decoded ZCL frame: IasZone:Report_Attributes(attribute_reports=[Attribute(attrid=0x0002, value=TypeValue(type=bitmap16, value=<bitmap16: 1>)), Attribute(attrid=0xFFFE, value=TypeValue(type=enum8, value=<enum8.undefined_0x01: 1>))])
2024-10-28 15:01:01.356 DEBUG (MainThread) [zigpy.zcl] [0x389D:17:0x0500] Received command 0x0A (TSN 13): Report_Attributes(attribute_reports=[Attribute(attrid=0x0002, value=TypeValue(type=bitmap16, value=<bitmap16: 1>)), Attribute(attrid=0xFFFE, value=TypeValue(type=enum8, value=<enum8.undefined_0x01: 1>))])
2024-10-28 15:01:01.357 DEBUG (MainThread) [zigpy.zcl] [0x389D:17:0x0500] Attribute report received: zone_status=<bitmap16: 1>, 0xFFFE=<enum8.undefined_0x01: 1>

Ouadi
ST Employee

The Zone Status attribute is reported to home assistant each time its value is changed, you need maybe to subscribe to the notification in home assistant side to receive the status change notification.

For any issue, please create a new post.

Regards,

Ouadi