Use HABApp to set the states accordingly. You can transform your scripts in to rules and call them accordingly.