- About
- Features
- Architecture
- Technologies Used
- Prerequisites
- Installation
- Configuration
- Usage
- Project Structure
- Documentation
- Contributing
- License
TempoBot is a complete solution for intelligently managing your electrical device consumption by leveraging the EDF Tempo calendar. The project combines:
- π€ A Python bot/server : Automates control of smart plugs via Tasmota, MQTT, and Firebase
- π± A native iOS application : SwiftUI interface to configure and monitor your plugs in real-time
The system automatically detects the Tempo day color (blue, white, red) and adjusts electricity consumption based on pricing, while allowing fine-grained schedule customization.
- β Automatic detection of the day's color (blue, white, red)
- β J+1 forecast for optimal planning
- β Remaining days counter per color for the year
- β Automatic on/off based on Tempo color
- β Peak/off-peak hours management per color
- β Custom schedules by day of the week
- β Manual override with one click from the iOS app
- β Remote control via MQTT
- β Real-time synchronization with Firebase
- β Simplified configuration from the iOS app
- β Modern and intuitive SwiftUI interface
- β Secure Firebase authentication
- β Simplified Wi-Fi and MQTT configuration
- β Real-time plug status
- β Complete schedule management
- β Discord integration for alerts and notifications
- β Error and crash handling with retry system
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β TempoBot Ecosystem β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββ β
β β iOS App ββββββββΊβ Firebase ββββββββΊβ Python β β
β β (SwiftUI) β β Realtime DB β β Bot β β
β ββββββββ¬ββββββββ ββββββββ¬ββββββββ βββββββ¬βββββ β
β β β β β
β β β β β
β ββββββββββββββββββββββββΌβββββββββββββββββββββ β
β β β
β ββββββββΌβββββββ β
β β Tasmota β β
β β (MQTT) β β
β βββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- EDF API β Retrieves the day's Tempo color
- Python Bot β Processes and updates Firebase
- Firebase β Synchronizes with the iOS app
- MQTT β Controls Tasmota plugs
- Discord β Notifications and alerts (optional)
| Technology | Version | Usage |
|---|---|---|
| Python | 3.x | Main language |
| Firebase Admin SDK | Latest | Database management |
| Discord.py | Latest | Discord notifications |
| Requests | Latest | EDF Tempo API |
| MQTT | - | Communication with Tasmota |
| miniupnpc | Latest | UPnP port forwarding |
| Technology | Version | Usage |
|---|---|---|
| Swift | 5.0+ | Main language |
| SwiftUI | Latest | User interface |
| Firebase iOS SDK | 9.6.0 | Authentication & Database |
| CocoaAsyncSocket | 7.6.5 | Network communication |
- π₯ Firebase : Authentication, Realtime Database, Analytics
- π‘ MQTT : Communication with Tasmota devices
- π EDF API : Tempo calendar retrieval
- Python 3.x installed
- Access to an MQTT server (Mosquitto)
- Firebase account with Realtime Database enabled
- (Optional) Discord bot for notifications
- Xcode 14.2+ installed
- iOS 16.0+ (simulator or physical device)
- Apple developer account (for device deployment)
- Configured
GoogleService-Info.plistfile
- Tasmota-compatible plug(s)
- Local network access (Wi-Fi)
- UPnP-compatible router (optional, for port forwarding)
git clone https://github.com/votre-user/TempoBot.git
cd TempoBotcd Python
# Create a virtual environment (recommended)
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install requests firebase-admin discord.py miniupnpc-
Create a Firebase project on Firebase Console
-
Enable services :
- β Authentication (Email/Password)
- β Realtime Database
- β Analytics (optional)
-
Download configuration files :
- Python : Service Account JSON β Place in
Python/tempobot-406fc-firebase-adminsdk-....json - iOS :
GoogleService-Info.plistβ Add to Xcode project
- Python : Service Account JSON β Place in
Ensure an MQTT server (Mosquitto) is accessible on your network:
# Install Mosquitto (example on Ubuntu/Debian)
sudo apt-get install mosquitto mosquitto-clients
# Verify the service is active
sudo systemctl status mosquitto-
Open the project in Xcode :
open iOS/TempoBot.xcodeproj
-
Configure the Bundle Identifier in project settings
-
Add
GoogleService-Info.plistto the app :- Drag and drop the file into the Xcode project
- Check "Copy items if needed"
-
Install dependencies (automatically managed by Swift Package Manager)
Edit Python/tasmota.py and adjust parameters:
# MQTT server IP address (if different)
# By default, uses mosquitto_pub command line
# Discord configuration (optional)
DISCORD_TOKEN = "your_discord_token"
CHANNEL_ID = 1120669437528379464 # Your Discord channel IDDatabase structure:
{
"data": {
"date": "2024/01/15",
"dateJ1": "2024/01/16",
"couleurJ": "TEMPO_BLEU",
"couleurJ1": "TEMPO_BLANC",
"Jrest_bleu": 300,
"Jrest_blanc": 43,
"Jrest_rouge": 22,
"Pleines_creuses": "pleines",
"users": {
"<uid>": {
"prises": {
"<id_prise>": {
"nom": "Living Room Plug",
"isOn": false,
"isManualOn": null,
"creuses_bleu": true,
"creuses_blanc": false,
"creuses_rouge": false,
"pleines_bleu": true,
"pleines_blanc": true,
"pleines_rouge": false,
"Lundi": "08:00-12:00",
"Mardi": null,
...
}
}
}
}
}
}Configure security rules in Firebase Console:
{
"rules": {
"data": {
".read": "auth != null",
".write": "auth != null",
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}
}cd Python
python tasmota.pyThe bot will:
- Connect to Firebase
- Retrieve the day's Tempo color from the EDF API
- Update the Firebase database
- Control Tasmota plugs according to configured rules
- Send Discord notifications (if configured)
- Launch the application from Xcode (β+R) or install on a device
- Create an account or sign in with Firebase Auth
- Add a plug :
- Detect the
tasmota-*SSID - Connect to the plug's Wi-Fi
- Configure IP address and MQTT settings
- Detect the
- Configure schedules :
- Choose peak/off-peak periods per Tempo color
- Define custom schedules by day
- Activate manual override if needed
cd Python
python port_forwarding.pycd Python
python testdtata.pyTempoBot/
β
βββ π± iOS/
β βββ TempoBot/
β β βββ π Authentification/
β β β βββ Login.swift
β β β βββ SignUp.swift
β β β βββ CompteView.swift
β β β
β β βββ π Connexion/
β β β βββ ConnexionReseauView.swift
β β β βββ ConnexionReseau2View.swift
β β β βββ NouvellePriseView.swift
β β β
β β βββ π Prise/
β β β βββ HeuresPickerView.swift
β β β βββ IsManualOnView.swift
β β β βββ InfoPriseView.swift
β β β
β β βββ π Reseau/
β β β βββ NetworkDiscovery.swift
β β β βββ ConnectionStateChecker.swift
β β β
β β βββ ContentView.swift
β β βββ MainPage.swift
β β βββ PriseList.swift
β β βββ ReadDatas.swift
β β βββ TempoBotApp.swift
β β
β βββ TempoBot.xcodeproj/
β
βββ π Python/
β βββ tasmota.py # Main bot script
β βββ port_forwarding.py # UPnP port forwarding script
β βββ test.py # Automation example
β βββ testdtata.py # Firebase read/write example
β βββ tempobot-406fc-firebase-adminsdk-....json
β
βββ π README.md
βββ π .deepsource.toml
| File | Description |
|---|---|
Python/tasmota.py |
Main script handling Tempo & Tasmota logic |
iOS/TempoBot/TempoBotApp.swift |
iOS application entry point |
iOS/TempoBot/ContentView.swift |
Authentication and navigation management |
iOS/TempoBot/MainPage.swift |
Main page after authentication |
Python/port_forwarding.py |
UPnP port forwarding script |
The bot uses EDF's public API to retrieve Tempo information:
- Day color :
https://particulier.edf.fr/services/rest/referentiel/searchTempoStore?dateRelevant=YYYY-MM-DD - Remaining days :
https://particulier.edf.fr/services/rest/referentiel/getNbTempoDays?TypeAlerte=TEMPO
The bot uses standard Tasmota MQTT topics:
- Command :
cmnd/<device_id>/power - Status :
stat/<device_id>/POWER
See the Firebase Configuration section for the complete database structure.
Contributions are welcome! To contribute:
- Fork the project
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow existing code conventions
- Add comments for complex code
- Test your changes before submitting a PR
- Update documentation if necessary
This project is licensed under the MIT License. See the LICENSE file for more details.
- Tasmota for the open-source firmware
- EDF for the Tempo API
- Firebase for backend services
- The open-source community
Made with β€οΈ to optimize your electricity consumption