How do I find out the previous state of a switch?

I need this for a Livolo zigbee switch that in case of a power failure does not return to the “on” state, it goes to the “off” state. If I could use the previous state then I would create an automation which at restart HA if the previous state of the switch was “on” then the state of the switch would become “on”.

create an automation that is triggered by change of state of your switch and store it in input_boolean.
then on HA restart set your switch in the same state as your input_boolean.