TRIGGERcmd
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    SmartThings integration - flip a virtual switch to run a command

    Instructions
    14
    38
    18.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ?
      A Former User
      last edited by

      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.

      RussR 1 Reply Last reply Reply Quote 0
      • RussR
        Russ @A Former User
        last edited by

        @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

        Russell VanderMey

        1 Reply Last reply Reply Quote 0
        • ?
          A Former User
          last edited by

          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?

          RussR 1 Reply Last reply Reply Quote 0
          • RussR
            Russ @A Former User
            last edited by

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

            Russell VanderMey

            1 Reply Last reply Reply Quote 0
            • ?
              A Former User
              last edited by

              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.

              RussR 1 Reply Last reply Reply Quote 0
              • RussR
                Russ @A Former User
                last edited by Russ

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

                Russell VanderMey

                ? 1 Reply Last reply Reply Quote 0
                • ?
                  A Former User
                  last edited by A Former User

                  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. πŸ˜„

                  1 Reply Last reply Reply Quote 0
                  • ?
                    A Former User @Russ
                    last edited by A Former User

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

                    RussR 1 Reply Last reply Reply Quote 0
                    • RussR
                      Russ @A Former User
                      last edited by

                      @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
                      

                      Russell VanderMey

                      1 Reply Last reply Reply Quote 0
                      • M
                        mthiel
                        last edited by Russ

                        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]&params=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]&params=on]
                        57bb48b4-bb6a-48d0-8938-e085928b86e6  4:47:54 PM: debug On request from child device script_dth_cd2efee0eca44de1d6ceeb8c9ede43c0f5239b6c1e6e37c4e674414c2538f18d@574ae66b
                        
                        RussR 1 Reply Last reply Reply Quote 0
                        • RussR
                          Russ @mthiel
                          last edited by Russ

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

                          Russell VanderMey

                          M 1 Reply Last reply Reply Quote 0
                          • M
                            mthiel @Russ
                            last edited by

                            @russ Thanks for checking! Unfortunately, re-creating the device via the SmartApp didn't make a difference. Turns out MY problem is that I only have one trigger I'm testing on...

                            I spent a few hours troubleshooting the SmartApp code and found the root cause around line 249. When a single trigger comes back from the api, the conditional looks like it assumes the type will be a Map, but it actually just returns a List with a single item at index 0. Changing the "devices?.name" and "devices?did" to "devices[0].name" and "devices[0].did" fixes the issue for me. I only realized the problem because the trigger list kept creating devices with brackets around the name, making me expect a typing problem.

                            It's working great for me now, hope my digging helps!

                            RussR 1 Reply Last reply Reply Quote 0
                            • RussR
                              Russ @mthiel
                              last edited by Russ

                              @mthiel, wow, that's interesting. I'm glad you found that. you send me the code snippet you changed? I want to test it myself, then I'll update the code. Sorry for the trouble, and thank you for finding a fix.

                              EDIT:
                              I was able to reproduce the problem. I tested the change and updated the code. Thanks @mthiel for the fix!

                              // deviceList += ["name" : "${roomName} ${devices?.name}", "did" : "${devices?.did}", "type" : "bulb"]  <- this logic doesn't work when there's only 1 command
                              // Thanks to mthiel for finding this fix. 
                              deviceList += ["name" : "${roomName} ${devices[0].name}", "did" : "${devices[0].did}", "type" : "bulb"]
                              

                              Russell VanderMey

                              1 Reply Last reply Reply Quote 0
                              • P
                                putefabio
                                last edited by

                                hello guys can you please give me some help

                                i have triggercmd installed in my pc so i can open kodi, but i have a 32bit version so thats why (i suppose) i dont have the option to parse a cmd so the smartthings switch knows when its on or off.

                                that beeing said when i press the switch it open kodi but it stays on (green), then if i close but manually it stays green forever, if i flip it again it goes off but it opens kodi, cause im not using the script.

                                well what i want is, can i switch the smartthings switch to a switch that doesnt stay on, it just pushes and goes back to initial state?

                                thanks in advance

                                RussR 1 Reply Last reply Reply Quote 0
                                • RussR
                                  Russ @putefabio
                                  last edited by Russ

                                  @putefabio, checkout this post:

                                  https://www.triggercmd.com/forum/topic/86/actiontiles-tile-with-triggercmd-bookmark-url/14

                                  It says you can make a small modification to the SmartThings code to make it so the switch goes back off after you flip it on.

                                  Russell VanderMey

                                  1 Reply Last reply Reply Quote 0
                                  • P
                                    putefabio
                                    last edited by

                                    thanks a lot for a so quick awnser, that did the trick πŸ™‚

                                    1 Reply Last reply Reply Quote 0
                                    • RussR
                                      Russ
                                      last edited by Russ

                                      @TigoleBitties, I just tried it and it's working for me. Can you verify your phone has Internet access?

                                      Also, you installed both the SmartApp and the Device Handler, correct?

                                      Russell VanderMey

                                      1 Reply Last reply Reply Quote 0
                                      • George HatzisymeonG
                                        George Hatzisymeon
                                        last edited by

                                        I am getting an Error saving unnamed page when I click Done on last page.
                                        Also I am using an account from Google, how shall I skip entering the credentials as you propose?

                                        RussR 1 Reply Last reply Reply Quote 0
                                        • RussR
                                          Russ @George Hatzisymeon
                                          last edited by

                                          @George-Hatzisymeon, you mentioned you're using an account from Google. If you do that, then before you can log SmartThings into your TRIGGERcmd account you also need to set your password in your profile in your TRIGGERcmd account. To get to your profile, click your name in the upper-right.

                                          You installed the device handler and SmartApp, correct?

                                          Here's a video showing the process: https://www.youtube.com/watch?v=dq-loAiKAgo

                                          If you still get that error, please post a screenshot. It might help me understand what's happening.

                                          Russell VanderMey

                                          1 Reply Last reply Reply Quote 0
                                          • ipaivaipI
                                            ipaivaip
                                            last edited by

                                            @Russ said in SmartThings integration - flip a virtual switch to run a command:

                                            Handler

                                            It works like a charm!
                                            I have just follow the instructions, and had it immediately working. Still good at 2021

                                            1 Reply Last reply Reply Quote 1
                                            • First post
                                              Last post