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

    How to run commands from Home Assistant

    Home Assistant
    6
    15
    12.5k
    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.
    • blizzrdof77B
      blizzrdof77 @Russ
      last edited by

      @russ Thanks for this, by the way!

      For anyone else using TriggerCMD with Home Assistant, I wrote this helper script with a rest_command that I have found very useful for running commands with parameters (or without parameters).

      Just be sure to change "ADD.YOUR.TRIGGERCMD.TOKEN.HERE" to your token.

      The Script:

      ## -- RUN TRIGGERCMD REST COMMAND
      script:
        run_triggercmd_rest_command:
          alias: Run TriggerCMD REST Command
          description: Execute a RESTful command with params and a device using triggercmd.
          icon: mdi:apple-keyboard-command
          variables:
            params: ''
            token: 'ADD.YOUR.TRIGGERCMD.TOKEN.HERE'
          fields:
            trigger:
              description: The name of the trigger
              example: Exit Windows Program
              required: true
            computer:
              description: The name of the computer as shown in your computer list on triggercmd.com.
              example: My Computer Name
              required: true
            params:
              description: Optional args string to pass with the trigger, using a space for multiple params [optional].
              example: ''
              required: false
          sequence:
          - service: rest_command.tcmd_run_command
            data:
              trigger: "{{ trigger }}"
              computer: "{{ computer }}"
              params: "{{ params }}"
              token: "{{ token }}"
      

      The Rest Command

      ## -- RUN TRIGGERCMD COMMAND
      rest_command:
        tcmd_run_command:
          url: 'https://www.triggercmd.com/api/run/triggerSave'
          method: POST
          content_type: 'application/x-www-form-urlencoded'
          payload: 'trigger={{trigger|replace(" ","%20")}}&computer={{computer|replace(" ","-")}}&params=+{{params}}&token={{token}}'
      

      Example Usage

      service: script.run_triggercmd_rest_command
      data:
        trigger: This Is The Trigger Name                 # Literally the name of the command
        computer: My Computer                             # (will render as 'My-Computer')
        params: '--female "Shutdown request confirmed"'   # This has 3 params
      
      A 1 Reply Last reply Reply Quote 1
      • RussR Russ referenced this topic on
      • RussR Russ referenced this topic on
      • A
        AZRushFan @blizzrdof77
        last edited by

        @blizzrdof77 @Russ I am new to HA and trying to get this working but not sure if my issue is related to possible syntax changes since 2021. Does this format still apply? Thanks.

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

          @AZRushFan, yes, I just tried it. It worked for me with this text at the end of my configuration.yaml:

          rest_command:
            triggercmd_calculator:
              url: 'https://www.triggercmd.com/api/run/triggerSave'
              method: "post"
              content_type: "application/x-www-form-urlencoded"
              payload: "trigger=calculator&computer=russfam&token=(my token)"
          

          7c976f0e-b70c-45b1-a3be-418b63a118c2-image.png

          That said, would it help if I built an official Home Assistant integration?

          EDIT 9/15/24: The official TRIGGERcmd integration will be available in next Home Assistant version (2024.10). It's due to be released on 10/2/2024. Please try using it instead of the "RESTful Command" method described above.

          Russell VanderMey

          1 Reply Last reply Reply Quote 0
          • RussR Russ referenced this topic on
          • RussR Russ referenced this topic on
          • RussR Russ moved this topic from Instructions on
          • RussR Russ pinned this topic on
          • RussR Russ referenced this topic on
          • A
            AZRushFan
            last edited by

            @Russ I am testing out the HA integration for TRIGGERcmd and curious on the best practice when using the switch functionality when triggering a script. In my instance it is a single instance AutoHotkey script so by definition there is no "off"; however, it doesn't trigger the next time I try to run it as the switch is still in the on position in HA. What do you suggest? Thank you.

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

              @AZRushFan, in my experience I've been able to trigger the ON switch many times in a row even though the HA virtual switch status is ON. Are you saying you can't trigger the ON command if the switch is already ON?

              Russell VanderMey

              A 1 Reply Last reply Reply Quote 0
              • A
                AZRushFan @Russ
                last edited by

                @Russ well as you mentioned it does indeed. I think I had another issue that was preventing the trigger in HA. Thank you.

                1 Reply Last reply Reply Quote 0
                • RussR Russ referenced this topic on
                • R
                  rdaraujo
                  last edited by

                  Hello guys,

                  Does Home Assistant integration run commands locally?
                  Is it still limited to 1 command per minute in the free tier?

                  Thanks

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

                    @rdaraujo, yes, it runs the commands locally without the 1 command per minute limit even if you're not subscribed.

                    Russell VanderMey

                    1 Reply Last reply Reply Quote 0
                    • AndruA
                      Andru
                      last edited by

                      @Russ, thank you for HA integration, would be really great if it also showed "offline" PC's entities as "unavailable".

                      It would be also very helpful for automations.

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

                        @Andru, thanks for the idea. I'll look into it.

                        Russell VanderMey

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