Implement console parameters feature to set Tasmota device settings

This commit is contained in:
Mike Geppert 2025-08-05 01:13:43 -05:00
parent 3d2afbd248
commit d566a7fdbb
3 changed files with 46 additions and 3 deletions

View File

@ -63,7 +63,22 @@ Create a `network_configuration.json` file with the following structure:
"Password": "mqtt-password", "Password": "mqtt-password",
"Topic": "%hostname_base%", "Topic": "%hostname_base%",
"FullTopic": "%prefix%/%topic%/", "FullTopic": "%prefix%/%topic%/",
"NoRetain": false "NoRetain": false,
"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"
}
} }
} }
``` ```
@ -107,12 +122,23 @@ The script can process devices that match patterns in the `unknown_device_patter
This feature helps automate the setup of new Tasmota devices that haven't been properly named yet. This feature helps automate the setup of new Tasmota devices that haven't been properly named yet.
## Console Parameters
The script supports setting Tasmota console parameters via the `console` section in the MQTT configuration. After verifying and updating MQTT settings, the script will apply all console parameters to each device. This allows you to:
- Configure device behavior (PowerOnState, SetOptions, etc.)
- Set up rules for button actions
- Configure retain flags for various message types
- Apply any other Tasmota console commands
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.
## Output Files ## Output Files
The script generates several output files: The script generates several output files:
- `current.json`: List of currently active Tasmota devices - `current.json`: List of currently active Tasmota devices
- `deprecated.json`: Devices that were previously active but are no longer present - `deprecated.json`: Devices that were previously active but are no longer present
- `TasmotaDevices.json`: Detailed information about each device - `TasmotaDevices.json`: Detailed information about each device, including MQTT and console parameter status
## License ## License

View File

@ -718,6 +718,23 @@ class TasmotaDiscovery:
# Check and update MQTT settings if needed # Check and update MQTT settings if needed
mqtt_updated = check_mqtt_settings(ip, name, mqtt_data) mqtt_updated = check_mqtt_settings(ip, name, mqtt_data)
# Set console parameters from config
console_updated = False
console_params = mqtt_config.get('console', {})
if console_params:
self.logger.info(f"{name}: Setting console parameters from configuration")
for param, value in console_params.items():
try:
url = f"http://{ip}/cm?cmnd={param}%20{value}"
response = requests.get(url, timeout=5)
if response.status_code == 200:
self.logger.debug(f"{name}: Set console parameter {param} to {value}")
console_updated = True
else:
self.logger.error(f"{name}: Failed to set console parameter {param}")
except requests.exceptions.RequestException as e:
self.logger.error(f"{name}: Error setting console parameter {param}: {str(e)}")
device_detail = { device_detail = {
"name": name, "name": name,
@ -726,6 +743,7 @@ class TasmotaDiscovery:
"version": status_data.get("StatusFWR", {}).get("Version", "Unknown"), "version": status_data.get("StatusFWR", {}).get("Version", "Unknown"),
"hostname": network_data.get("StatusNET", {}).get("Hostname", "Unknown"), "hostname": network_data.get("StatusNET", {}).get("Hostname", "Unknown"),
"mqtt_status": "Updated" if mqtt_updated else "Verified", "mqtt_status": "Updated" if mqtt_updated else "Verified",
"console_status": "Updated" if console_updated else "Verified",
"last_checked": time.strftime("%Y-%m-%d %H:%M:%S"), "last_checked": time.strftime("%Y-%m-%d %H:%M:%S"),
"status": "online" "status": "online"
} }

View File

@ -30,7 +30,6 @@
"NoRetain": false, "NoRetain": false,
"console": { "console": {
"SwitchRetain": "Off", "SwitchRetain": "Off",
"ButtonRetain": "On",
"ButtonRetain": "Off", "ButtonRetain": "Off",
"PowerOnState": "3", "PowerOnState": "3",
"PowerRetain": "On", "PowerRetain": "On",