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

How to run commands from Home Assistant

Home Assistant
4
11
10.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.
  • R
    Russ
    last edited by Russ May 29, 2025, 9:50 PM Jun 17, 2018, 7:49 PM

    Home Assistant (aka Hass.io) is a popular automation system sort of like SmartThings but it's open source and works offline (without Internet).

    EDIT 10/6/2024: The official TRIGGERcmd integration is now available in Home Assistant version 2024.10+. This Youtube video shows how it works.

    You can click the little lightning bolts to run on and off commands.

    ed2c23f6-ea3e-418d-b4d5-913d0e216907-image.png

    EDIT 12/24/2024:
    Now you can connect the TRIGGERcmd agent to Home Assistant directly, so if the Internet goes out, your commands will still run if you trigger them from Home Assistant. Add the TRIGGERcmd HA integration, then right-click the agent icon and click "Home Assistant Config" to configure it to listen for trigger events.

    ed56b300-abaa-4cae-9ac9-9f2a6e3cf785-image.png

    090870b1-cbac-4a24-881b-dd7b3bed471e-image.png

    Go here to generate your long-lived access token: http://homeassistant.local:8123/profile/security

    The following is the old method that uses the "RESTful Command" to call the TRIGGERcmd api:

    Here's how you trigger commands on your computers from Home Assistant using a RESTful Command.

    Add this to the end of your configuration.yaml file:

    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=(your token from Instructions page)"
    

    You can test it by clicking the little cell phone icon in the lower left under Developer tools, then select rest_command.triggercmd_calculator in the Service field, then click CALL SERVICE. This is what it should look like:

    TRIGGERcmd with Home Assistant

    I installed Home Assistant on my QNAP nas as a Docker container. If you do that, I recommend these two settings:

    1. Create a folder you have access to, and mount it as /config in your container. That will give you easy access to the configuration files, and when you upgrade the container, you can re-mount this folder to /config.
    2. Use HOST networking, so you can access Home Assistant at a URL like http://homeassistant.local:8123.

    Russell VanderMey

    1 Reply Last reply Reply Quote 0
    • R
      rafastanger
      last edited by Dec 15, 2020, 11:41 PM

      I can get the commands to be executed by Alexa, but when I try to make the call directly through the Home Assistant, I get the error: Status Code 400

      Does the call syntax remain the same?

      R 1 Reply Last reply Dec 16, 2020, 1:55 AM Reply Quote 0
      • R
        Russ @rafastanger
        last edited by Russ Dec 16, 2020, 1:56 AM Dec 16, 2020, 1:55 AM

        @rafastanger, that should still work, but you can also use this "get" method below. One thing to note - your trigger and computer values can be different from your voice words you'd use with Alexa.

        rest_command:
          triggercmd_calculator:
            url: 'https://www.triggercmd.com/api/run/triggerSave?trigger=calculator&computer=russhp&token=(your token)'
            method: "get"
        

        Russell VanderMey

        1 Reply Last reply Reply Quote 0
        • B
          blizzrdof77
          last edited by Feb 9, 2021, 5:52 PM

          Is it possible to pass arguments via this method?

          R 1 Reply Last reply Feb 9, 2021, 11:22 PM Reply Quote 0
          • R
            Russ @blizzrdof77
            last edited by Feb 9, 2021, 11:22 PM

            @blizzrdof77, good question. Yes, you can add this to your URL or payload to pass parameters:

            &params=(yourParams)

            You can use a space or %20 between parameters if you have multiple parameters to pass, like this:

            &params=(param1)%20(param2)

            Russell VanderMey

            B 1 Reply Last reply Dec 4, 2021, 1:12 AM Reply Quote 1
            • B
              blizzrdof77 @Russ
              last edited by Dec 4, 2021, 1:12 AM

              @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 Jun 21, 2024, 10:03 PM Reply Quote 1
              • R Russ referenced this topic on Jan 5, 2022, 10:39 PM
              • R Russ referenced this topic on Jan 5, 2022, 10:40 PM
              • A
                AZRushFan @blizzrdof77
                last edited by Jun 21, 2024, 10:03 PM

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

                R 1 Reply Last reply Jun 22, 2024, 12:23 AM Reply Quote 0
                • R
                  Russ @AZRushFan
                  last edited by Russ Sep 15, 2024, 4:21 PM Jun 22, 2024, 12:23 AM

                  @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
                  • R Russ referenced this topic on Jul 29, 2024, 10:41 PM
                  • R Russ referenced this topic on Dec 25, 2024, 1:11 AM
                  • R Russ moved this topic from Instructions on Dec 28, 2024, 12:27 AM
                  • R Russ pinned this topic on Dec 28, 2024, 2:43 AM
                  • R Russ referenced this topic on Dec 28, 2024, 2:45 AM
                  • A
                    AZRushFan
                    last edited by May 12, 2025, 10:08 PM

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

                    R 1 Reply Last reply May 12, 2025, 10:42 PM Reply Quote 0
                    • R
                      Russ @AZRushFan
                      last edited by May 12, 2025, 10:42 PM

                      @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 May 13, 2025, 8:59 PM Reply Quote 0
                      • A
                        AZRushFan @Russ
                        last edited by May 13, 2025, 8:59 PM

                        @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
                        • R Russ referenced this topic on May 29, 2025, 4:23 PM
                        • First post
                          Last post