Door rf sensor doesn't remember state after restart hassOS but state is unknow, is there a way to remember last state first? can you restart

Thank you very much, if in this case I use node red, will the effect be the same as using python?
according to the following steps