Activation of toggle checkbox without user iteraction

I’m developing an app where I receive information through the mqtt protocol. There is a toggle button in my application that I want to check when a message is received. Is there anyway to emulate a user interaction with a toggle checkbox and checked it dinamically?

Thanks!