I tested the behavior with Matter.js.
The device is a bridge, so different sensors can be added dynamically even after Matter pairing has already been completed.
When the device has just started and CumulativeEnergyImported = null, the attribute is visible on the Matter server but not in the web interface.
After the attribute receives a valid value, it appears in the web interface within about 5 minutes.
As I understand it, the logic that prevents attributes with a null value from being displayed is implemented in MatterDiscoverySchema in this file:
https://github.com/home-assistant/core/blob/dev/homeassistant/components/matter/sensor.py#L1003
There is even a dedicated parameter allow_none_value. If allow_none_value=True is set like this:
MatterDiscoverySchema( platform=Platform.SENSOR, entity_description=MatterSensorEntityDescription( key="ElectricalEnergyMeasurementCumulativeEnergyImported", device_class=SensorDeviceClass.ENERGY, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfEnergy.MILLIWATT_HOUR, suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, suggested_display_precision=3, state_class=SensorStateClass.TOTAL_INCREASING, # id 0 of the EnergyMeasurementStruct is the cumulative energy (in mWh) device_to_ha=lambda x: x.energy, ), entity_class=MatterSensor, allow_none_value=True, required_attributes=( clusters.ElectricalEnergyMeasurement.Attributes.CumulativeEnergyImported, ), ),
then the Energy entity will appear in the web interface even if its current value is null.
To be honest, I am not sure which behavior is preferable:
whether the attribute should appear immediately with an “Unknown” state until real measurement values are received,
or appear later only once valid measured values are available.
In my opinion, the delayed appearance of the attribute slightly degrades the user experience.