As far as I can tell there’s no official method of doing this, but there are third party scripts such as pysonofflanr3. After a teensy bit of editing (because a library has been updated since the last release) the script runs however it needs the “api_key” which is the encryption key for the device. There are instructions on how to get the key however none of the three methods work. One requires old firmware, another requires a particular kind of router, and the last requires putting the device into compatible pairing mode which is supposed to allow another device to connect to it, but I’m guessing the BASICR2 I have doesn’t have that capability as holding down the button will not cause an AP to show up.
So is there another way to get the encryption key or, alternately, is there another way of controlling sonoff devices with a script? If not, what devices would people suggest to be able to do this?