but I have no personal experience wrt. controlling FHEM by other means than using FHEMWEB or andFHEM (android app).
Some hints anyhow:
- Your questioning should make more clear, what "outside the FHEM environment" means: same machine, same network segment, somewhere over internet or telphone line etc..
- Imo, best approach is to have local systems acting independently. Typically this would include FHEM deciding on most of the things happening at a specific place. In case you have to inform FHEM about whatever, you may send an email, add calendar entries and so on and make FHEM check for these kind of infos regularly (e.g. "will visit my weekend house tomorrow"). Doing that way should reduce vulnerability/problems arising of a non reliable connection to the remote system. In case you plan to do some own scripting outside FHEM, you may "reinvent the wheel", a lot of funktionality is already there/built in.
- For interaction from telnet or OS level with FHEM, you may have a look at the commandref, keywords "Introduction" and "FHEM command types"