Push Hubitat Groovy

VérifiéPrudence

Pousse un fichier Groovy local vers un concentrateur Hubitat, le compile et rapporte le statut de compilation. Il identifie le type de fichier (application ou pilote), extrait le nom, trouve ou crée l'entité sur le concentrateur, met à jour le code et liste les appareils ou applications qui l'utilisent.

Spar Skills Guide Bot
DeveloppementIntermédiaire
7002/06/2026
Claude Code
#hubitat#groovy#iot#home-automation#push-code

Recommandé pour

Notre avis

Pousse un fichier Groovy local (app ou driver) vers un hub Hubitat, le compile et rapporte le résultat.

Points forts

  • Automatise le déploiement de code sur un hub Hubitat sans interface web
  • Détecte automatiquement le type (app/driver) et le nom à partir du fichier
  • Gère la mise à jour incrémentale via l'API Hubitat (version)
  • Rapporte les erreurs de compilation et affiche les appareils/instances utilisant le code

Limites

  • Nécessite un fichier de configuration .hubitat.json présent à la racine du projet
  • Ne crée pas automatiquement un nouveau code s'il n'existe pas encore sur le hub (délègue à une autre compétence)
  • Dépend de l'API HTTP du hub sans authentification (sécurité limitée)
Quand l'utiliser

Quand vous développez des applications ou pilotes Groovy pour Hubitat et que vous voulez déployer rapidement les modifications sur le hub local.

Quand l'éviter

Si le hub n'est pas sur le réseau local ou si vous avez besoin de gérer plusieurs hubs simultanément (la compétence ne gère qu'un seul hub par projet).

Analyse de sécurité

Prudence
Score qualité95/100

The skill uses bash and curl to communicate with a local Hubitat hub on the network, which is legitimate but involves network operations and file system reads. No destructive or exfiltrating actions are present.

Aucun point d'attention détecté

Exemples

Push latest Groovy driver
Push the most recently modified .groovy driver file to the Hubitat hub.
Push specific app file
Push the file apps/my-app.groovy to the Hubitat hub and show me the compilation status.
Push all updated drivers
Find all .groovy files modified in the last hour and push them to the hub.

name: hubitat-push description: Push Groovy app or driver code to Hubitat hub and report compile status argument-hint: "[filepath]" allowed-tools: Bash, Read, Glob, Grep

Hubitat Push Skill

Push a local Groovy file to the Hubitat hub, compile it, and report the result.

Instructions

Follow these steps exactly:

Step 1: Read Configuration

Read .hubitat.json from the project root to get hub_ip.

Step 2: Identify the File

  • If $ARGUMENTS contains a filepath, use that file.
  • Otherwise, find the most recently modified .groovy file using: ls -t apps/*.groovy drivers/**/*.groovy 2>/dev/null | head -1
  • Confirm the file exists and read its contents.

Step 3: Determine Type (App vs Driver)

  • If the file path contains apps/ → it's an app
  • If the file path contains drivers/ → it's a driver
  • This determines the API endpoints to use:
    • Driver: /hub2/userDeviceTypes, /driver/ajax/code, /driver/ajax/update
    • App: /hub2/userAppTypes, /app/ajax/code, /app/ajax/update

Step 4: Extract Name from Source

Read the file and extract the name value from the definition() block. The format looks like:

definition(
    name: "My Driver Name",
    namespace: "iamtrep",
    ...
)

Extract the name string (the value after name:).

Step 5: Find the Hub ID

Query the hub for the list of user code to find the matching ID:

  • Drivers: curl -s "http://{hub_ip}/hub2/userDeviceTypes"
  • Apps: curl -s "http://{hub_ip}/hub2/userAppTypes"

The response is a JSON array. Find the entry where name matches the name extracted in Step 4. Get the id field. Also note the usedBy field for later.

If no match is found, the code is not yet on the hub. Use the /hubitat-install skill to create it, then stop (install will handle creation and report the result). Tell the user you are invoking /hubitat-install.

Step 6: Get Current Version

Fetch the current version number (required for the update API):

  • Drivers: curl -s "http://{hub_ip}/driver/ajax/code?id={ID}"
  • Apps: curl -s "http://{hub_ip}/app/ajax/code?id={ID}"

Extract the version field from the JSON response.

Step 7: Push the Code

POST the updated source to the hub:

  • Drivers: POST http://{hub_ip}/driver/ajax/update
  • Apps: POST http://{hub_ip}/app/ajax/update

Use curl with:

curl -s -X POST "http://{hub_ip}/{type}/ajax/update" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  --data-urlencode "id={ID}" \
  --data-urlencode "version={VERSION}" \
  --data-urlencode "source@{FILEPATH}"

Where {type} is driver or app.

Note: --data-urlencode "source@{FILEPATH}" reads and URL-encodes the file contents automatically.

Step 8: Report Result

Parse the JSON response:

  • On success: {"id":..., "version":..., "status":"success"}
    • Report: "Successfully pushed {name} to hub (version {new_version})"
  • On error: The response will contain error/status details
    • Report the compilation errors clearly so the user can fix them

Step 9: Show Usage

From the data retrieved in Step 5, show which devices or app instances use this code:

  • For drivers: list the devices using this driver (from usedBy in the userDeviceTypes response)
  • For apps: list the installed instances (from usedBy in the userAppTypes response)

Format as a simple list with device/app IDs and names.

Skills similaires