Files

110 lines
3.5 KiB
Markdown

---
name: tasmota
description: Use when controlling Tasmota WiFi plugs.
version: 1.0.0
author: user
license: MIT
platforms: [linux, macos, windows]
metadata:
hermes:
tags: [Smart-Home, Tasmota, IoT, WiFi, Automation]
homepage: https://tasmota.github.io/
---
# Tasmota Remote Control
## Always-on Rules
### 1. Network discovery first
Before any command, discover the plug's current IP. Methods:
- Router client list (web UI)
- `ping 192.168.1.XXX` sweep from your LAN subnet
- Tailscale IP if Tailscale is running (`tailscale ip list`)
- Never guess an IP — verify first.
### 2. Local HTTP before MQTT
Start with plain HTTP commands (`http://<ip>/?cmnd=...`). Only fall back to MQTT if the app you used before required it.
### 3. Tailscale for remote access (preferred)
Since Tailscale is installed on this system, the recommended remote path is:
1. `tailscale up` on the controlling device
2. `tailscale ip list` to find the plug's Tailscale IP
3. Send HTTP commands to `http://<tailscale-ip>/` as if on LAN
4. No port forwarding, no router reconfiguration needed.
### 4. Command syntax
Use the standard Tasmota HTTP API:
- `Power ON` / `Power OFF`
- `Power TOGGLE`
- `Status 1` to read current state
- Full list at `http://<ip>/` → `cmnd` section
### 5. Verify before acting
After sending a command, immediately read back status:
- `http://<ip>/` → `Status 1`
- Or `http://<ip>/cmnd?Power` to see the last sent command acknowledged
## Pitfalls (generalizable rules + why)
- **Pitfall: Stale IP after DHCP renewal** — Why: Tasmota retains its last static IP config but may rejoin DHCP. Always re-discover after network restarts.
- **Pitfall: MQTT broker not reachable** — Why: Tasmota's built-in MQTT requires a running broker; if you haven't configured one, HTTP is the reliable fallback.
- **Pitfall: Tailscale not running on both sides** — Why: Remote access via Tailscale requires Tailscale active on the controlling device AND the network where the plug lives.
## When to Use
- "Turn on/off the Tasmota plug"
- "Is the plug on or off?"
- "Set the plug to a specific state"
- "Check plug status"
## Common Commands
### List/Verify
```bash
# Discover plug IP first (replace subnet)
python3 -c "import ipaddress, subprocess; [print(ip) for ip in ipaddress.IPv4Network('192.168.1.0/24') if subprocess.run(['ping', '-c', '1', '-W', '1', str(ip)], capture_output=True).returncode == 0]"
# Check if Tailscale is active
tailscale status
tailscale ip list
```
### Control
```bash
# Turn on
curl -s 'http://192.168.1.42/?cmnd=Power%20ON'
# Turn off
curl -s 'http://192.168.1.42/?cmnd=Power%20OFF'
# Toggle
curl -s 'http://192.168.1.42/?cmnd=Power%20TOGGLE'
# Read status
curl -s 'http://192.168.1.42/'
```
### Via Tailscale (remote)
```bash
# Replace with Tailscale IP
curl -s 'http://100.103.XX.XX/?cmnd=Power%20ON'
```
## References (depth for sometimes-needed detail)
- `references/api.md` — Tasmota HTTP API command reference (full cmnd list)
- `references/mqtt.md` — Tasmota MQTT topic structure and broker setup
- `references/tailscale.md` — Tailscale setup for Tasmota remote access
## Quick Probe Script
The following script verifies the plug is reachable before sending commands. Save as `scripts/verify_tasmota.sh` and make executable.
```bash
#!/usr/bin/env bash
# Verify Tasmota plug reachable via HTTP
set -e
IP="${1:-192.168.1.42}" # override via $1 or default
timeout 2 curl -s -o /dev/null -w '%{http_code}' "http://$IP/" | grep -q '^2' && echo "OK: $IP reachable" || echo "FAIL: $IP not reachable (check IP, Tailscale, or network)"
```
```