I do this by storing the state of each relay pin in a virtual pin ie every time I write to a physical pin I also write to a virtual pin whichis stored on server. On a reset or power loss etc I do a syn each virtual pin at start up and do the same to the digital pin therefore reinstating the status of each relay at time of failure