diff --git a/CONSOLE_COMMANDS.md b/CONSOLE_COMMANDS.md
new file mode 100644
index 0000000..0f050cd
--- /dev/null
+++ b/CONSOLE_COMMANDS.md
@@ -0,0 +1,84 @@
+# Tasmota Console Commands Documentation
+
+This document provides detailed information about the console commands used in the `network_configuration.json` file, particularly focusing on the SetOptions commands.
+
+## Console Section in network_configuration.json
+
+The `console` section in the `network_configuration.json` file allows you to configure various Tasmota device settings through the TasmotaManager script. These settings are applied to all devices during the version check process.
+
+```json
+"console": {
+ "SwitchRetain": "Off",
+ "ButtonRetain": "Off",
+ "PowerOnState": "3",
+ "PowerRetain": "On",
+ "SetOption1": "0",
+ "SetOption3": "1",
+ "SetOption13": "0",
+ "SetOption19": "0",
+ "SetOption32": "8",
+ "SetOption53": "1",
+ "SetOption73": "1",
+ "rule1": "on button1#state=10 do power0 toggle endon",
+ "rule2": "1"
+}
+```
+
+## MQTT Retain Settings
+
+| Command | Values | Description |
+|---------|--------|-------------|
+| `SwitchRetain` | `On`, `Off` | Controls whether MQTT retain flag is used on switch press messages. Default: `Off` |
+| `ButtonRetain` | `On`, `Off` | Controls whether MQTT retain flag is used on button press messages. Default: `Off` |
+| `PowerRetain` | `On`, `Off` | Controls whether MQTT retain flag is used on power state messages. Default: `Off` |
+
+## Power Settings
+
+| Command | Values | Description |
+|---------|--------|-------------|
+| `PowerOnState` | `0` to `4` | Controls the power state when the device is powered up:
`0` = Off
`1` = On
`2` = Toggle
`3` = Last state (default)
`4` = Turn on if off after restart |
+
+## SetOptions
+
+SetOptions are special commands that control various aspects of Tasmota device behavior. Below are the SetOptions currently used in the configuration:
+
+| Command | Values | Description |
+|---------|--------|-------------|
+| `SetOption1` | `0`, `1` | Controls whether a button press toggles power or sends a MQTT message:
`0` = toggle power (default)
`1` = send MQTT message |
+| `SetOption3` | `0`, `1` | Controls MQTT enabled/disabled:
`0` = disable MQTT
`1` = enable MQTT (default) |
+| `SetOption13` | `0`, `1` | Controls whether a button press clears retained messages:
`0` = disable (default)
`1` = enable |
+| `SetOption19` | `0`, `1` | Controls Home Assistant auto-discovery:
`0` = disable (default)
`1` = enable |
+| `SetOption32` | `1` to `250` | Time in minutes to hold relay latching power before reset. Default: `1` |
+| `SetOption53` | `0`, `1` | Controls display of hostname and IP address in GUI:
`0` = disable (default)
`1` = enable |
+| `SetOption73` | `0`, `1` | Controls whether HTTP cross-origin resource sharing is enabled:
`0` = disable (default)
`1` = enable |
+
+## Additional SetOptions
+
+Here are some other useful SetOptions that can be added to the configuration:
+
+| Command | Values | Description |
+|---------|--------|-------------|
+| `SetOption0` | `0`, `1` | Save power state and use after restart:
`0` = disable
`1` = enable (default) |
+| `SetOption4` | `0`, `1` | Return MQTT response as RESULT or %COMMAND%:
`0` = RESULT (default)
`1` = %COMMAND% |
+| `SetOption8` | `0`, `1` | Show temperature in Celsius or Fahrenheit:
`0` = Celsius (default)
`1` = Fahrenheit |
+| `SetOption10` | `0`, `1` | When the device restarts, the LWT message is sent:
`0` = disable (default)
`1` = enable |
+| `SetOption11` | `0`, `1` | Swap button single and double press functionality:
`0` = disable (default)
`1` = enable |
+| `SetOption20` | `0`, `1` | Update of Hass discovery messages:
`0` = disable (default)
`1` = enable |
+| `SetOption30` | `0`, `1` | Enforce Home Assistant auto-discovery as light:
`0` = disable (default)
`1` = enable |
+| `SetOption31` | `0`, `1` | Disable status LED blinking during Wi-Fi and MQTT connection issues:
`0` = LED enabled (default)
`1` = LED disabled |
+| `SetOption36` | `0` to `255` | Boot loop control:
`0` = disable (default)
`1` to `200` = enable with number of boot loops before entering safe mode |
+| `SetOption52` | `0`, `1` | Control display of optional time offset from UTC in JSON messages:
`0` = disable (default)
`1` = enable |
+| `SetOption65` | `0`, `1` | Device recovery using fast power cycle detection:
`0` = disable (default)
`1` = enable |
+| `SetOption80` | `0`, `1` | Enable Alexa support for devices with an ESP8266 over 1M flash:
`0` = disable
`1` = enable (default) |
+| `SetOption82` | `0`, `1` | Reduce the CT range from 153..500 to 200..380 to accommodate with Alexa:
`0` = CT ranges from 153 to 500 (default)
`1` = CT ranges from 200 to 380 (Alexa compatible) |
+
+## Rules
+
+Rules allow you to create simple automations directly on the Tasmota device.
+
+| Command | Values | Description |
+|---------|--------|-------------|
+| `rule1` | Rule expression | Defines the first rule. Example: `on button1#state=10 do power0 toggle endon` |
+| `rule2` | `0`, `1` | Enables or disables rule2:
`0` = disable (default)
`1` = enable |
+
+For more information about Tasmota commands, visit the [official Tasmota documentation](https://tasmota.github.io/docs/Commands/).
\ No newline at end of file
diff --git a/README.md b/README.md
index 666282d..b84b8bc 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ A Python utility for discovering, monitoring, and managing Tasmota devices on a
## Features
- Discovers Tasmota devices on the network via UniFi Controller API
-- Tracks device changes over time (new, moved, deprecated devices)
+- Track device changes over time (new, moved, deprecated devices)
- Checks and updates MQTT settings on Tasmota devices
- Generates detailed device information including firmware versions
- Processes unknown devices (matching unknown_device_patterns) to set up names and MQTT
@@ -107,7 +107,7 @@ The script can process devices that match patterns in the `unknown_device_patter
1. Identify devices matching the unknown device patterns
2. Check if each device has a toggle button (indicating it's a light switch or power plug)
-3. Toggle the button at 1/2Hz (on/off every two seconds) to help identify the physical device
+3. Toggle the button at 1/2 Hz (on/off every two seconds) to help identify the physical device
4. **How to enter the hostname:**
- The script will display a clear prompt in the console showing the current device name and IP address
- While the device is toggling, you'll see a prompt asking for a new name for the device
@@ -133,6 +133,16 @@ The script supports setting Tasmota console parameters via the `console` section
Each parameter is sent as a command to the device using the Tasmota HTTP API. The device details in `TasmotaDevices.json` will include a `console_status` field indicating whether console parameters were updated.
+For detailed documentation of all available SetOptions and other console commands, please refer to the [CONSOLE_COMMANDS.md](CONSOLE_COMMANDS.md) file. This documentation includes:
+
+- Explanations of all SetOptions currently used in the configuration
+- Additional useful SetOptions that can be added
+- MQTT retain settings
+- Power settings
+- Rules configuration
+
+The documentation is based on the official [Tasmota Commands Reference](https://tasmota.github.io/docs/Commands/#setoptions).
+
## Output Files
The script generates several output files:
diff --git a/TasmotaManager.py b/TasmotaManager.py
index 87d41b0..1ccef3b 100644
--- a/TasmotaManager.py
+++ b/TasmotaManager.py
@@ -724,7 +724,38 @@ class TasmotaDiscovery:
console_params = mqtt_config.get('console', {})
if console_params:
self.logger.info(f"{name}: Setting console parameters from configuration")
+
+ # Special handling for ButtonRetain - need to send "On" first, then "Off" to clear MQTT broker retain settings
+ try:
+ # First ButtonRetain command (On)
+ url = f"http://{ip}/cm?cmnd=ButtonRetain%20On"
+ response = requests.get(url, timeout=5)
+ if response.status_code == 200:
+ self.logger.debug(f"{name}: Set ButtonRetain to On (step 1 of 2 to clear MQTT broker retain settings)")
+ console_updated = True
+ else:
+ self.logger.error(f"{name}: Failed to set ButtonRetain to On")
+
+ # Small delay to ensure commands are processed in order
+ time.sleep(0.5)
+
+ # Second ButtonRetain command (Off)
+ url = f"http://{ip}/cm?cmnd=ButtonRetain%20Off"
+ response = requests.get(url, timeout=5)
+ if response.status_code == 200:
+ self.logger.debug(f"{name}: Set ButtonRetain to Off (step 2 of 2 to clear MQTT broker retain settings)")
+ console_updated = True
+ else:
+ self.logger.error(f"{name}: Failed to set ButtonRetain to Off")
+ except requests.exceptions.RequestException as e:
+ self.logger.error(f"{name}: Error setting ButtonRetain commands: {str(e)}")
+
+ # Process all other console parameters
for param, value in console_params.items():
+ # Skip ButtonRetain as it's handled specially above
+ if param == "ButtonRetain":
+ continue
+
try:
url = f"http://{ip}/cm?cmnd={param}%20{value}"
response = requests.get(url, timeout=5)
diff --git a/network_configuration.json b/network_configuration.json
index 194220b..21b1dc8 100644
--- a/network_configuration.json
+++ b/network_configuration.json
@@ -31,8 +31,8 @@
"console": {
"SwitchRetain": "Off",
"ButtonRetain": "Off",
- "PowerOnState": "3",
"PowerRetain": "On",
+ "PowerOnState": "3",
"SetOption1": "0",
"SetOption3": "1",
"SetOption13": "0",
@@ -41,7 +41,7 @@
"SetOption53": "1",
"SetOption73": "1",
"rule1": "on button1#state=10 do power0 toggle endon",
- "rule1": "1"
+ "rule2": "1"
}
}
}
\ No newline at end of file