Skip to content

Instantly share code, notes, and snippets.

@RJ
Created October 4, 2025 20:05
Show Gist options
  • Select an option

  • Save RJ/24caaa2eb306d3b634d6c3a3adddd37b to your computer and use it in GitHub Desktop.

Select an option

Save RJ/24caaa2eb306d3b634d6c3a3adddd37b to your computer and use it in GitHub Desktop.
Set a load of shelly settings via curl
#!/usr/bin/env bash
# Usage: ./shelly-setup.sh <IP> <DEVICE_NAME>
set -euo pipefail
IP="${1:-}"
NAME="${2:-}"
if [[ -z "$IP" || -z "$NAME" ]]; then
echo "Usage: $0 <IP> <DEVICE_NAME>" >&2
exit 64
fi
jq --version >/dev/null 2>&1 || { echo "This script requires 'jq'." >&2; exit 69; }
rpc() {
local method="$1" payload="$2"
echo "$IP $method --> $payload"
local url="http://${IP}/rpc"
local resp
local wrapped_payload="{\"id\":1,\"method\":\"$method\",\"params\":{\"config\":$payload }}"
resp=$(curl -sS --fail-with-body -m 15 \
-H "Content-Type: application/json" \
-X POST "$url" -d "$wrapped_payload") \
|| { echo "HTTP error calling ${method}" >&2; exit 1; }
# Ensure JSON and no RPC error
echo "$resp" | jq -e . >/dev/null 2>&1 \
|| { echo "Non-JSON response from ${method}: $resp" >&2; exit 1; }
if echo "$resp" | jq -e 'has("error")' >/dev/null; then
echo "RPC ${method} failed: $(echo "$resp" | jq -r '.error.message // "unknown error"')" >&2
exit 1
fi
}
# 1) Wi-Fi: set STA SSID/PASS and disable AP
rpc "WiFi.SetConfig" "$(jq -n \
--arg ssid "SSID GOES HERE" \
--arg pass "PASS GOES HERE" \
'{sta:{ssid:$ssid, pass:$pass, enable:true}, ap:{enable:false}}')"
# 2) Disable Bluetooth
rpc "BLE.SetConfig" '{"enable":false}'
# 3) System: set SNTP server and device name
rpc "Sys.SetConfig" "$(jq -n \
--arg name "$NAME" \
--arg server "10.0.1.1" \
'{device:{name:$name}, sntp:{server:$server}}')"
# 4) Thermostat service: set temperature range (service id 0)
rpc "Service.SetConfig" '{"temp_range":[15,27]}, "id": 0'
# 5) Disable Shelly Cloud
rpc "Cloud.SetConfig" '{"enable":false}'
#rpc "Shelly.CheckForUpdate" ""
rpc "Shelly.Update" '{"stage":"stable"}'
@RJ
Copy link
Author

RJ commented Oct 4, 2025

About to install a lot of shelly linkedgo thermostats.

here's how to send a load of api commands via script. i'll automate the setup as best i can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment