Local Control API

When my internet is down, I was still able to control devices locally using my app, how can i achive the same using my custom code, Is there any other way to control it

USE home assistant integration.