Ikea sensors in unknown state with HA restart

I am using this battery alert script to notify me if any batteries that falls below the set threshold. This script also alert of battery that is in the unknown and unavailable states.

I have some Ikea remotes (E1524) and motion sensor (E1524) that are integrated with HA. I notice HA shows these sensor batteries as unknown after restarting of HA. It changes to a % when the devices are depressed, however. Besides from the motion sensor, I seldom use the remotes. What can I do to prevent HA detecting these devices as unknown after every restart? It’s quite cumbersome to have to track down all the devices and wake them up.

So I think I need to add retain: true to mqtt. I tried adding to the config file under zigbee2mqtt, but it isn’t working. Perhaps its the wrong place to add it or it is now depreciated?

Which version of Home Assistant are you using? There was a bug in how it handled MQTT Binary Sensors on startup in 0.112.0 (and didn’t get fixed until 0.112.5 which is only released for the Core installation method).

Home Assistant 0.112.4
Docker version 19.03.8

0.112.4 doesn’t contain the fix for this:

The correction is in 0.112.5 but that version was never released for Home Assistant OS, Supervised, or Container (only for Core). It will be available in 0.113.

I am now at ver 0.113. Rebooted HA 2 times, but my sensors still shows unknown. Is there a setting I must add?

Seems to be working now after updating zigbee2mqtt add-on. Batteries are showing percentage and not unknown after every restart of HA.