This project provides an integration with the Homgar API, allowing you to monitor and manage devices associated with your Homgar account. The code is designed to run as an Azure Function, triggered by a timer, which periodically checks the status of devices and sends alerts when necessary.
The integration is structured into two main components:
- HomgarApi: A class that handles the interaction with the Homgar API, including authentication, retrieving device status, and managing temperature alerts.
- Azure Function: An Azure Function app that triggers the API calls at regular intervals, checks the devices' statuses, and logs the results.
- Scheduled Execution: The Azure Function is scheduled to run 30 minutes to ensure timely updates.
- Temperature Monitoring: The system checks if the temperature of connected devices exceeds a predefined threshold and sends an email alert if necessary.
- Logging: Extensive logging is implemented to track the flow of operations and handle errors effectively.
- Python 3.8 or higher
- Azure Functions Core Tools (for local development)
- Access to the Azure portal to deploy and manage the function
git clone https://github.com/restoore/fcn-homegarapi-003.git
cd fcn-homegarapi-003It is recommended to use a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
pip install -r requirements.txtThe application requires a configuration file named config.yml at the root of the project. This file should contain your API credentials, Redis configuration, and email service connection strings.
Rename config.sample.yml to config.yml
api-homegar:
email: "[email protected]"
password: "your-password"
notification:
- to: '[email protected]'
displayName: 'User One'
- to: '[email protected]'
displayName: 'User Two'
redis:
host: "your-redis-host"
acces-key: "your-redis-access-key"
azure-mail:
connection-string: "your-azure-connection-string"
sender: "[email protected]"
# Param pour les capteurs : température max à surveiller, cadence des alertes en heure
# exemple si alert-frequency est fixé à 24, la notification ne sera envoyée qu'une fois toutes les 24h en cas de dépassement
sensors:
- name: 'extérieur '
max-temperature: 40
alert-frequency: 24
- name: 'cage '
max-temperature: 25
alert-frequency: 2
- name: 'congélo '
max-temperature: -10
alert-frequency: 24To run the Azure Function locally:
func startThis will start the Azure Function runtime and execute the scheduled function every minute.
To deploy the function to Azure, use the following commands:
func azure functionapp publish <YourFunctionAppName>Replace <YourFunctionAppName> with the name of your Azure Function App.
Logging is extensively used throughout the project to monitor execution and diagnose issues. Logs are classified into different levels:
INFO: General information about the execution flow.DEBUG: Detailed information useful for debugging.WARNING: Indications of potential problems or unusual conditions.ERROR: Errors that prevent the operation from proceeding as expected.
By default, logs are configured to output to the console. You can adjust the logging level and handlers in the logutil.py file.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature). - Make your changes.
- Commit your changes (
git commit -am 'Add new feature'). - Push to the branch (
git push origin feature/your-feature). - Create a pull request.
Please make sure to update tests as appropriate.
This project is licensed under the MIT License. See the LICENSE file for details.