SmartThings integration - flip a virtual switch to run a command
-
The article below describes the old TRIGGERcmd SmartThings integration. As of today, 1/13/2023, please refer to this article instead.
Samsung still hasn't approved my integration, but in the meantime you can install it manually.
This article tells you how to make virtual SmartThings switches that trigger your commands on your computer.
Here's a video that quickly shows this setup process.
Also this video shows the new feature that sends an on or off parameter from the virtual switch to your command so you can open or close programs like Kodi.The TRIGGERcmd SmartThings integration uses two files that you paste into your SmartThings developer console. You log into the developer console with the same email address and password you used to setup your SmartThings hub.
These are the steps:
Log into https://account.smartthings.com with your SmartThings account.Click "My Locations," and select your location. (screenshot)
Login again if it prompts you.
Click "My SmartApps," then "+ New SmartApp," then "From Code", then paste in this code and click Create.
Click "Publish," then "For Me" to publish it. (screenshot)
Click "My Device Handlers," then "+ Create New Device Hander," then "From Code", then paste in this code and click Create.
Click "Publish," then "For Me" to publish it. (screenshot)
Open the SmartThings app on your phone.
Under Automation, select the SmartApps tab.
Select "+ Add a SmartApp" at the bottom of the list. (screenshot)
Scroll to the bottom of the list and select "My Apps". (screenshot)
Select TRIGGERcmd. (screenshot)
If you log into TRIGGERcmd with an email address and password (as opposed to Facebook, Twitter, or Google account), then you can skip this step. Otherwise, log into your TRIGGERcmd account and click "Welcome [your name]" then Profile, and type in a password. You'll need that for this next step.
Enter your TRIGGERcmd email address and password, and tap Next. (screenshot)
Tap "Select Commands," and check the checkboxes next to each command you want to add, then tap Done. (screenshot)
Now you should see the commands you selected in your "Things" list under "My Home". (screenshot)
Tap the "OFF" buttons to trigger those commands. The button you tap will turn green and change to ON for a second, and the command will run.EDIT 10/11/17: I updated the SmartThings code to send on or off as a parameter when you toggle the virtual switch on and off. If the command doesn't allow parameters, then the command just runs when you toggle the switch off and on.
Now you can include TRIGGERcmd commands in your Routines and SmartApps as if they're switches!
NOTE: If you delete a command from your TRIGGERcmd account before unselecting it via the TRIGGERcmd SmartApp, you'll get errors trying to update your list of TRIGGERcmd virtual switches until you delete the virtual switch associated with that command from the Things list. Bubba ( @Nate-Hales on this forum) did a detailed video that includes how to delete them here: https://youtu.be/R9mZK2U-zkQ?t=864 Just tap the switch, then the gear in the upper-right, then the red Remove button.
EDIT 10/23/17: I added logic to the SmartThings code to delete your ST switch automatically if you delete the corresponding TRIGGERcmd command, but the code can't delete the ST switches if they're used by other SmartApps, so you'll still have to delete them manually in some cases.
EDIT 5/25/19: Now the SmartThings switches are tied to the commands via the computer name / command name combo, so you can move your commands to a new computer, name the computer the same as the old computer (in the web gui), and you won't have to re-create your SmartThings switches. You also won't have to recreate ST switches when you change command properties, as long as the command's name field remains the same. You can tell if you're using the new code if you see "TRIGGERcmd V2" at the top of the SmartApp code.
EDIT 7/31/2021: I updated the SmartApp code to V3 today. I found a bug in the cleanup schedule that was bogging down the server once per hour. Please update your SmartApp code if doesn't already have TRIGGERcmd V3 at the top.
-
CAN I TELL YOU HOW AWESOME YOU ARE!!! WE HAVE TO GET SOME YOUTUBERS TO KNOW ABOUT THIS!! THIS IS THE MISSING LINK!!
-
@Nate-Hales, thank you so much. I thought it was awesome too, so it's good to have someone confirm it.
I just took a walk with my wife and when we got home I said to Google Assistant my phone, "open sesame" to open the garage. Now that's a geek's dream right there!
I'd appreciate any help you can give to spread the word about TRIGGERcmd.
You seem to be a SmartThings enthusiast like me. Have you tried CoRE yet? I've been meaning to try that with some TRIGGERcmd virtual SmartThings switches, but TRIGGERcmd development has kept me from some of these experiments.
-
I am going to steal "open sesame' Never heard of Core but Im on it!! I put outdoor speakers in the planters by the front door that will (one day soon) turn on when the bell is rang and announce "Welcome to the Hales automated home, this interaction is being recorded for quality assurance, Please hold while I notify the family of your arrival.. If you are a solicitor please move on to the next house as no soliciting is allowed or wait here while I notify the police. Thank you for your cooperation, We will be with you shortly" Haha also I have monoprice rock speakers throughout the yard that will turn on when motion is activated and play a Wav. file of a dog growling and a police radio, saying random things in the distance. I have played it outside and friends in my yard start thinking cops are on the other side of the fence. haahah .
-
Very cool @Nate-Hales, you should do a video when you get it all going. I'd like to see that.
-
i just asked this question under another regarding alexa, but seems appropriate here also.
For the switches, this seems perfect for launching programs on my htpc. for example Kodi. Now the cmd line to launch kodi is very different than the command to kill it, (sorry im pretty basic at cmd line work). When i create a virtual switch, can i pass the correct different kill line to turn the switch (program) "off"?
-
@Neflhiem, good idea - now you can. See this article:
https://www.triggercmd.com/forum/topic/88/alexa-invocation-and-smartthings-switch-questions/17 -
Hi
I ran into a bit of trouble installing/configuring the smart app. Following the instructions, the smart app and device handler installed and both are listed as published. However TRIGGERcmd smart app on the mobile side, returns "Error-bad state. Unable to complete page configuration.", after submitting the email address (username) and password created on TRIGGERcmd's website.
Any ideas on the cause?
Thanks
-
@ou, I think your username or password is bad. I just tried setting mine wrong and I got the same error.
I wonder if you're using a Facebook or Google account to log into TRIGGERcmd, but you haven't set your password in your profile page yet.
SmartThings talks directly to TRIGGERcmd, and TRIGGERcmd doesn't know your Google password, so if you use a Google account you have to give TRIGGERcmd a password for SmartThings to login with.
-
I'm having some issues getting this working. The routine is working fine in Triggercmd, i.e. if I manually run the trigger through the website using parameter on or off, it triggers as it should. If I try triggering through smartthings, it doesn't trigger and I get no error.
The only thing I can see from the debug logs in smartthings, is the token it's returning from triggercmd is not my actual token.
-
@Reddog176, please try deleting and re-creating your virtual switch. I wonder if your command changed after you created your SmartThings virtual switch. If your command changes, your virtual switch has to be re-created.
- Go into SmartThings
- Tap your virtual switch (not the ON or OFF button but to the left of it)
- Tap the little gear in the upper-right
- Tap the red Remove button
- Go into the TRIGGERcmd SmartApps and re-check the checkbox to re-create your virtual switch.
- Test again
-
Russ,
Russ I just followed these instructions. I've actually done this before at my house and I'm trying to set up at my office as well. However, this time around I created the Triggercmd app in smartthings and I created the Device Handler (different smart things account than my home account) and published them. I can seem the both in the smartthings dash board, but when I open smartthings on my phone or tablet and try to add the app it is not there in the Automation/smart apps/add a smart app/my apps. I've tried deleting and recreating it a couple of times in the smart things api and still no go. Any idea what might be going on here? -
@dhking, all I can think of is maybe you're logged into your SmartThings app with one account, but you added the smartapp and device handler to the other account?
-
Any way to simply pass arguments directly to a command in the triggerCMD commands.json (linux)? I'd rather not have to write scripts for all of these just to parse "on" and "off" if possible.
-
@dctrbanner, you can include parameters in the commands.json file. Here's an example that uses two parameters:
-
-y
-
update
{"trigger":"apt update","command":"apt-get -y update","ground":"background","voice":"update"},
BTW, if you leave allowParams out, or use "allowParams": "false", then SmartThings won't append on or off when you flip the switch - it will just run the command without the extra parameter when you flip it on or off.
-
-
Thanks for the reply - I meant is there any way to parse "on" or "off" in the commands.json in place of where it would be in the command. For example, I have a heyu command to turn lights on that is formatted as such:
Turn lights on: heyu fon Kitchen
Turn lights off: heyu foff KitchenWhat I am hoping is that there is something similar to %1, %2, etc in a batch file so that I can write:
heyu f%1 Kitchen
and pass on or off that way, to make the virtual switch work. AFAIK it can only be done with a script, but if there is a simpler way I'd love it since I would only need to edit the json (although a script to parse the on/off along with the device name would be more elegant).
EDIT: Disregard, I'm going to go with a script after all, my OCD wants the most elegant solution.
-
@russ I am trying to trigger a command with parameters, but I I'm running into a wall.
My script is as follows:
array=( $1 $2 ) some_command ${array[1]} ${array[0]}
I used an array because I needed to reverse the order of the parameters. Now my commands.json has a trigger configured as such:
{"trigger":"Test","command":"sudo -u pi -H ~/Smartthings/TriggerCMD/Scripts/Myscript.sh first_arg " ","ground":"background","voice":"Test","allowParams": "true"}
I'm expecting TriggerCMD to pass the "on" or "off" as the second argument, but for some reason, it doesn't seem to be doing so when I test from the website. Am I doing something wrong? I even tried to make a script specifically for the first argument so the only argument needed from TriggerCMD is the on / off, but it still doesn't work.
-
@dctrbanner, I think I found the problem.
This is what I got when I ran it your way:
sudo -u pi ~/Smartthings/TriggerCMD/Scripts/Myscript.sh sudo: /root/Smartthings/TriggerCMD/Scripts/Myscript.sh: command not found
Notice it's translating the ~ to /root before the command runs as pi.
This works though:
{"trigger":"Test","command":"sudo -u pi -H \/home\/pi\/Smartthings\/TriggerCMD\/Scripts\/Myscript.sh first_arg ","ground":"background","voice":"Test","allowParams": "true"},
This is my test script:
#!/bin/sh echo $2 $1 >> /tmp/log.txt
This is the output:
$ tail -f /tmp/log.txt on first_arg
-
Hello,
I'm trying to get this setup to put my display to sleep, but the commands don't seem to be reaching SmartThings. If I manually fire the TriggerCMD from my phone browser it works perfectly, but SmartThings doesn't seem to be communicating correctly despite the lack of any error. TriggerCMD also doesn't report receiving any requests except the ones I performed from the browser. I don't think there's an authentication issue since the SmartApp is reading my commands fine. I'm not sure what else to check. Here's a snip from the SmartThings log:
57bb48b4-bb6a-48d0-8938-e085928b86e6 4:47:54 PM: debug OFF result: [response:done] 57bb48b4-bb6a-48d0-8938-e085928b86e6 4:47:54 PM: debug Return Code = 200 = Command Succeeded. 57bb48b4-bb6a-48d0-8938-e085928b86e6 4:47:54 PM: debug In apiPost with data: [token:(token), uri:/api/run/triggerByID, body:trigger=[5c61df9baa745900163af4dd-5c64b9eb3b309f00167a06eb]¶ms=off] 57bb48b4-bb6a-48d0-8938-e085928b86e6 4:47:54 PM: debug Off request from child device 57bb48b4-bb6a-48d0-8938-e085928b86e6 4:47:54 PM: debug ON result: [response:done] 57bb48b4-bb6a-48d0-8938-e085928b86e6 4:47:54 PM: debug Return Code = 200 = Command Succeeded. 57bb48b4-bb6a-48d0-8938-e085928b86e6 4:47:54 PM: debug In apiPost with data: [token:(token), uri:/api/run/triggerByID, body:trigger=[5c61df9baa745900163af4dd-5c64b9eb3b309f00167a06eb]¶ms=on] 57bb48b4-bb6a-48d0-8938-e085928b86e6 4:47:54 PM: debug On request from child device script_dth_cd2efee0eca44de1d6ceeb8c9ede43c0f5239b6c1e6e37c4e674414c2538f18d@574ae66b
-
@mthiel, just to make sure, I just tested this in my SmartThings app and it worked for me.
I recommend you try this:
Go to Marketplace, SmartApps, My Apps, TRIGGERcmd, Next.
Uncheck all of our commands, and click Done, Save.
Go to Home, and if you have any TRIGGERcmd switches left, delete them.
Go to Marketplace, SmartApps, My Apps, TRIGGERcmd, Next again.
Check the commands you and to be switches.
Test your switch again.BTW, I removed your token from the output you pasted.