improve thread functionality and add dimmer for wall switch