You can do it half-way, but it's going to be a cloud based switch as well.
Use this code. When you turn on the "switch" that this code creates, it will trigger a virtual motion sensor. You then create a routine that triggers the switch to turn on when the motion is triggered. You create a second that turns the switch off, or you edit the code.
You cannot do the opposite as @marktheknife points out. Alexa and Google Assistant (which cannot do it either) are not as complete a smart home platform as HomeKit or a hub from Hubitat or SmartThings.
This Z-Wave relay is the better way and costs the same however, then just add any smart button and you'll be able to trigger it with Google Assistant, Alexa, the button, a Hubitat Dashboard, your HE UI via drivers, time of day, etc.