119 lines
3.7 KiB
Markdown
119 lines
3.7 KiB
Markdown
# TasmotaManager
|
|
|
|
A Python utility for discovering, monitoring, and managing Tasmota devices on a network using UniFi Controller.
|
|
|
|
## Features
|
|
|
|
- Discovers Tasmota devices on the network via UniFi Controller API
|
|
- Tracks 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
|
|
|
|
## Requirements
|
|
|
|
- Python 3.6+
|
|
- UniFi Controller with API access
|
|
- Network with Tasmota devices
|
|
|
|
## Dependencies
|
|
|
|
- requests
|
|
- urllib3
|
|
- Standard library modules (json, logging, os, sys, datetime, re, time, argparse)
|
|
|
|
## Installation
|
|
|
|
1. Clone this repository
|
|
2. Install required packages:
|
|
```bash
|
|
pip install requests urllib3
|
|
```
|
|
3. Create a configuration file (see below)
|
|
|
|
## Configuration
|
|
|
|
Create a `network_configuration.json` file with the following structure:
|
|
|
|
```json
|
|
{
|
|
"unifi": {
|
|
"host": "https://your-unifi-controller.local",
|
|
"username": "your-username",
|
|
"password": "your-password",
|
|
"site": "default",
|
|
"network_filter": {
|
|
"network_name": {
|
|
"name": "Human-readable name",
|
|
"subnet": "192.168.1",
|
|
"exclude_patterns": [
|
|
"device-to-exclude*"
|
|
],
|
|
"unknown_device_patterns": [
|
|
"tasmota*",
|
|
"ESP-*"
|
|
]
|
|
}
|
|
}
|
|
},
|
|
"mqtt": {
|
|
"Host": "mqtt-broker.local",
|
|
"Port": 1883,
|
|
"User": "mqtt-user",
|
|
"Password": "mqtt-password",
|
|
"Topic": "%hostname_base%",
|
|
"FullTopic": "%prefix%/%topic%/",
|
|
"NoRetain": false
|
|
}
|
|
}
|
|
```
|
|
|
|
## Usage
|
|
|
|
Basic usage:
|
|
```bash
|
|
python TasmotaManager.py
|
|
```
|
|
|
|
With options:
|
|
```bash
|
|
python TasmotaManager.py --config custom_config.json --debug --skip-unifi
|
|
```
|
|
|
|
Command-line options:
|
|
- `--config`: Path to configuration file (default: network_configuration.json)
|
|
- `--debug`: Enable debug logging
|
|
- `--skip-unifi`: Skip UniFi discovery and use existing current.json
|
|
- `--process-unknown`: Process unknown devices (matching unknown_device_patterns) to set up names and MQTT
|
|
|
|
## Unknown Device Processing
|
|
|
|
The script can process devices that match patterns in the `unknown_device_patterns` list (like "tasmota_" or "ESP-" prefixed devices). When using the `--process-unknown` flag, the script will:
|
|
|
|
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
|
|
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
|
|
- Type the new hostname directly in the console and press Enter
|
|
- All debug messages are completely suppressed during this process to keep the console clear
|
|
5. Once a hostname is entered, the script will:
|
|
- Configure the "Friendly Name 1" field with the new hostname
|
|
- Enable MQTT if not already enabled
|
|
- Configure MQTT settings from the configuration file
|
|
- Save the configuration and reboot the device
|
|
6. Move on to the next unknown device
|
|
|
|
This feature helps automate the setup of new Tasmota devices that haven't been properly named yet.
|
|
|
|
## Output Files
|
|
|
|
The script generates several output files:
|
|
- `current.json`: List of currently active Tasmota devices
|
|
- `deprecated.json`: Devices that were previously active but are no longer present
|
|
- `TasmotaDevices.json`: Detailed information about each device
|
|
|
|
## License
|
|
|
|
This project is licensed under the MIT License - see the LICENSE file for details. |