Group Details Private

administrators

Member List
  • RE: How to create a trigger

    @gigaboy, thanks for sharing that link. I'm loving the fact that Google gave you that answer - to use TRIGGERcmd via IFTTT.

    If your server doesn't have a GUI, you'll have to edit your ~/.TRIGGERcmdData/commands.json file manually, using a text editor like vi (aka vim) or pico, nano etc.

    On Linux, your default ~/.TRIGGERcmdData/commands.json file includes the first 5 commands. I added the 6th command you could use to restart mysql, like Google says.

    [
      {"trigger":"Reboot","command":"shutdown -r","ground":"background","voice":"reboot","allowParams": "false"},
      {"trigger":"Gnome Editor","command":"gedit","ground":"foreground","voice":"notepad","allowParams": "false"},
      {"trigger":"Calculator","command":"gnome-calculator","ground":"foreground","voice":"calculator","allowParams": "false"},
      {"trigger":"yum update","command":"yum -y update","ground":"background","voice":"yum update","allowParams": "false"},
      {"trigger":"apt update","command":"apt-get -y update","ground":"background","voice":"update","allowParams": "false"},
      {
        "trigger": "Restart MySQL",
        "command": "sudo systemctl restart mysql",
        "offCommand": "",
        "ground": "background",
        "voice": "restart",
        "voiceReply": "",
        "allowParams": "false"
      }
    ]
    

    Notice I made "ground" = "background" because without a GUI, you probably installed the background agent (with installdaemon.sh) which runs the TRIGGERcmd agent in background mode as service.

    posted in General Discussion
  • RE: Ubuntu 22 - Installation throws permission denied, no prompt for token

    @gigaboy the errors you see here:

    Computer name for Local Home Assistant listener: null
    Error fetching computer name: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received null
        at Object.writeFile (node:fs:2311:5)
        at /usr/lib/triggercmdagent/resources/app/src/ha.js:120:10
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
      code: 'ERR_INVALID_ARG_TYPE'
    }
    

    Those errors are actually what I want to fix in the next version of the agent. The errors are related to the new Home Assistant integration. It errors like that on first run because it can't fetch the computer name. If you don't use Home Assistant you can ignore it, and if you do, just restart the agent.

    Anyway, to solve your problem, please try this:

    systemctl restart triggercmdagent
    

    Then check the status again with this:

    systemctl status triggercmdagent
    

    That will restart it and if it can find node 20, it should work. It just has to be above node 12, so 16 could work too.

    Let me know how goes please. Also, what method did you use the install nodejs? nvm or apt?

    posted in Linux
  • RE: Ubuntu 22 - Installation throws permission denied, no prompt for token

    @gigaboy, you're welcome. I found a separate problem I'd like to solve in a new version, but since then I also found the specific problem you ran into.

    I found the latest version of the triggercmd agent doesn't work with node version 12, and node version 12 gets installed by default on ubuntu 22 when you install nodejs. It worked fine for me on my ubuntu 24 because it installed node version 18 when I ran apt install nodejs.

    On your ubuntu 22 you could use nvm (node version manager) to install node version 16 (or greater) like this:

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
    nvm install 16
    

    In case it got bad data from a previous failed run, you should delete your ~/.TRIGGERcmdData folder like this:

    rm -rf ~/.TRIGGERcmdData
    

    Then run the agent again like this:

    node /usr/lib/triggercmdagent/resources/app/src/agent.js --console
    

    I like the flexibility of nvm, but here's another option for installing nodejs version 16:

    apt remove nodejs -y
    curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
    apt install -y nodejs
    

    Thank you for reporting your issue btw, and thank you for your patience.

    posted in Linux
  • RE: Ubuntu 22 - Installation throws permission denied, no prompt for token

    @gigaboy, looking into this now.

    EDIT: @gigaboy , I re-read your post. I see you're trying to use the agent on a server without X-Windows. I just tried that and I see I need to fix some things so give me some time to produce a new version.

    posted in Linux
  • RE: Ubuntu 22 - Installation throws permission denied, no prompt for token

    @gigaboy, I see your background agent is running with /root/.TRIGGERcmdData as its data directory, so please switch to root with sudo su - then run this command to enter your token:

    node /usr/lib/triggercmdagent/resources/app/src/agent.js --console
    

    Then restart the agent with this command:

    systemctl restart triggercmdagent
    

    Then, you can put your commands in your /root/.TRIGGERcmdData/commands.json file with ground=background.

    I'll have more time to run through the ubuntu instructions later today, but if you see this before then, please try the above and let me know how it goes.

    EDIT: I tried it on Ubuntu 24 and I got that same error but it worked fine.

    N: Download is performed unsandboxed as root as file '/home/gigaboy/triggercmdagent_1.0.1_amd64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
    

    d592e631-c3cc-4693-ae64-33365f10516a-image.png

    posted in Linux
  • Download a Youtube video by passing the URL as a parameter

    I made this YouTube video to show how this works.

    Make sure to adjust the folder paths. I doubt you'll put your script in d:\appdev\triggercmd\youtube-dl or put your downloaded files in m:\videos\youtube like I did.

    Create a folder, open a cmd window in that folder, and type these to create the virtual environment with the yt_dlp python module:

    python3 -m venv myenv
    myenv\Scripts\activate.bat
    pip3 install yt_dlp
    

    youtube-dl.bat contents:

    setlocal enabledelayedexpansion
    
    :: This version of the script differs from the one in the Youtube video in that it handles any of these Youtube URL formats:
    :: https://www.youtube.com/watch?v=KqfRiPy5gFs
    :: https://youtu.be/KqfRiPy5gFs
    :: KqfRiPy5gFs
    
    :: Combine all arguments into a single string
    set "input="
    for %%A in (%*) do (
        set "input=!input! %%A"
    )
    
    :: Remove leading spaces
    set "input=%input:~1%"
    
    :: Check if the input contains "youtu.be" format and extract the video ID
    echo %input% | findstr /C:"youtu.be" >nul
    if not errorlevel 1 (
        set "id=%input:~17%"  :: Strip "https://youtu.be/"
    )
    
    :: Check if the input contains "youtube.com/watch?v=" format and extract the video ID
    if not defined id (
        echo %input% | findstr /C:"youtube.com/watch?v=" >nul
        if not errorlevel 1 (
            set "id=%input:~32%"  :: Strip "https://www.youtube.com/watch?v="
        )
    )
    
    :: If input is just the ID, no need for stripping
    if not defined id (
        set "id=%input%"
    )
    
    :: Ensure the ID is exactly 11 characters long
    set "id=%id:~0,11%"
    
    echo YouTube Video ID: %id%
    
    :: Go to the folder where I want the files to be created
    cd /d m:\videos\youtube
    
    :: Activate the Python virtual environment that has the yt_dlp module installed
    call d:\appdev\triggercmd\youtube-dl\myenv\Scripts\activate.bat
    
    :: Run the python script to download the video and metadata
    python d:\appdev\triggercmd\youtube-dl\youtube-dl.py %id%  > debug.log 2>&1
    

    youtube-dl.py contents:

    import yt_dlp
    import json, uuid, sys
    
    def download_video_metadata(video_url):
        ydl_opts = {
            'quiet': True,
            'skip_download': True,
            'force_generic_extractor': False,
        }
        
        with yt_dlp.YoutubeDL(ydl_opts) as ydl:
            try:
                info_dict = ydl.extract_info(video_url, download=False)
                return info_dict
            except Exception as e:
                print(f"Error: {e}")
                return None
    
    def download_video(video_url):
        ydl_opts = {
            'quiet': False,
            'outtmpl': '%(title)s.%(ext)s',
        }
        
        with yt_dlp.YoutubeDL(ydl_opts) as ydl:
            try:
                ydl.download([video_url])
            except Exception as e:
                print(f"Error: {e}")
    
    if __name__ == "__main__":
        if len(sys.argv) != 2:
            print("Usage: python3 youtube-dl.py <YouTube Video URL>")
            sys.exit(1)
    
        video_url = sys.argv[1]
        metadata = download_video_metadata(video_url)
        
        if metadata:
            print("Metadata:")
    
            filename=metadata.get('title', uuid.uuid4()) + ".json"
            with open(filename, "w") as file:
                json.dump(metadata, file, indent=4)
    
            print("Downloading video...")
            download_video(video_url)
    

    Make sure you enable parameters:
    9f121796-6f1f-4241-9d2e-c0e83a221fc2-image.png

    If you want to create a panel, you can use this regex to accept any text: ^.*$
    8ac7a7eb-9e94-44e6-b259-93c72efd841c-image.png

    posted in Windows panel parameter python
  • RE: Command ran with error code 1 trying shutdown command

    @vitormbn , if you run the same command from a CMD window does it work? Error code 1 means it's running the command but it's failing. Ideally it will fail in the same way so you can see the error. One possible reason for the failure might be you don't have admin access on your machine.

    posted in General Discussion
  • RE: TriggerCMD throws an Application Error upon computer shutdown.

    @Paul-Kelly, please upgrade to the new version (1.0.46) I just published. I wasn't able to reproduce the error, but it's an intermittent problem, so I'm not sure this will fix it. Please let me know if you see it again after you upgrade.

    posted in General Discussion
  • RE: Cant Get Background Services to Work anymore

    @Tony-Seaback

    I replied to you here, but basically I broke the background service in version 1.0.45. I just need to upgrade the node version and update the agent. I'll do that today. Stay tuned.

    https://www.triggercmd.com/forum/topic/3227/background-agent-commands-not-syncing-or-service-not-starting-please-assist-please-thank-you

    EDIT: Please upgrade to version 1.0.46. It should fix the windows background service. Sorry about the bug.

    posted in General Discussion
  • RE: Background service

    @Tony-Seaback, I replied to you here, but basically I broke the background service. I just need to upgrade the node version and update the agent. I'll do that today. Stay tuned.

    https://www.triggercmd.com/forum/topic/3227/background-agent-commands-not-syncing-or-service-not-starting-please-assist-please-thank-you

    EDIT: Please upgrade to version 1.0.46. It should fix the windows background service. Sorry about the bug.

    posted in General Discussion