Binary_sensor and binary_switch problem at reboot

Is it possible to create a script, input_boolean, or automation that automatically saves binary_sensor state upon reboot of hassio?
And reload this state at startup so that the sensor gets the same state it had before reboot?

I have several binary_sensors on doors and windows plus some binary_switches to turn on / off led strips. If a door or window is open at the reboot of the hassio then they appear as closed after boot.
Same with the lights. They may be turned on before reboot, but appear as turned off after reboot.

It becomes difficult to rely on an alarm system if you can’t trust binary_sensors to provide the correct state

These devices communicate with hassio through an RFXTRX antenna.

Can anyone please help me here?