SmartThings integration - flip a virtual switch to run a command


  • administrators

    @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.


  • administrators

    @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?


  • administrators

    @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.


  • administrators

    @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 Kitchen

    What 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. :D



  • @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.


  • administrators

    @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

Log in to reply
 

Looks like your connection to TRIGGERcmd Forum was lost, please wait while we try to reconnect.