Skip to content

Commit 821c078

Browse files
eelmafiareedy
andauthored
Refactor code and add web UI (#128)
* Refactor * Update dockerfile and use switch threshold * Add webserver * Add timestamp to pre-start message * Cancel run if consumption data is 0 * Refresh jwt token correctly * Fix running multiple scheduled runs in a day * Log config updates from web ui * Add basic auth to webserver * Update README * Log threshold and improve message * bot_orchestrator.py: Fix call to accept_new_agreement (#131) * config.html: Associate labels to inputs (#130) * Make port configurable * config.yaml: Add ingress configuration (#132) * Improve some messages * update user agent --------- Co-authored-by: Sam Reed <sam@reedyboy.net>
1 parent aab34d3 commit 821c078

26 files changed

Lines changed: 1360 additions & 490 deletions

README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,23 @@ I created this because I've been a long-time Agile customer who got tired of the
99

1010
I personally have this running automatically every day at 11 PM inside a Raspberry Pi Docker container, but you can run it wherever you want. It sends notifications and updates to a variety of services via [Apprise](https://github.com/caronc/apprise), but that's not required for it to work.
1111

12+
## Web Dashboard
13+
14+
After starting the bot you can access the web dashboard on `localhost:5050`
15+
16+
- Make changes to your config through the dashboard without needing to restart
17+
- Access and read logs
18+
- See graph of savings (coming soon)
19+
1220
## How to Use
1321

1422
### Requirements
15-
- An Octopus Energy Account
23+
- An Octopus Energy Account
1624
- In case you don't have one, we both get £50 for using my referral: https://share.octopus.energy/coral-lake-50
1725
- Get your API key [here](https://octopus.energy/dashboard/new/accounts/personal-details/api-access)
1826
- A smart meter
1927
- Be on a supported Octopus Smart Tariff (see tariffs below)
20-
- An Octopus Home Mini for real-time usage (**Important**). Get one for free [here](https://octopus.energy/blog/octopus-home-mini/).
28+
- An Octopus Home Mini for real-time usage (**Important**). Request one from Octopus Energy for free [here](https://octopus.energy/blog/octopus-home-mini/).
2129

2230
### HomeAssistant Addon
2331

@@ -37,13 +45,15 @@ https://github.com/eelmafia/octopus-minmax
3745
### Running Manually
3846
1. Install the Python requirements.
3947
2. Configure the environment variables.
40-
3. Schedule this to run once a day with a CRON job or Docker. I recommend running it at 11 PM to leave yourself an hour as a safety margin in case Octopus takes a while to generate your new agreement.
48+
3. Run `main.py`. I recommend scheduling it to run it at 11 PM in order to leave yourself an hour as a safety margin in case Octopus takes a while to generate your new agreement.
4149

4250
### Running using Docker
4351
Docker run command:
4452
```
4553
docker run -d \
4654
--name MinMaxOctopusBot \
55+
-p 5001:5001 \
56+
-v ./logs:/app/logs \
4757
-e ACC_NUMBER="<your_account_number>" \
4858
-e API_KEY="<your_api_key>" \
4959
-e EXECUTION_TIME="23:00" \
@@ -54,7 +64,8 @@ docker run -d \
5464
-e TARIFFS=go,agile,flexible \
5565
-e TZ=Europe/London \
5666
-e BATCH_NOTIFICATIONS=false \
57-
--restart unless-stopped \
67+
-e WEB_USERNAME="<whatever_you_want>" \
68+
-e WEB_PASSWORD="<whatever_you_want>" \
5869
eelmafia/octopus-minmax-bot
5970
```
6071
or use the docker-compose.yaml **Don't forget to add your environment variables**
@@ -66,13 +77,18 @@ Note : Remove the --restart unless line if you set the ONE_OFF variable or it wi
6677
|-----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
6778
| `ACC_NUMBER` | Your Octopus Energy account number. |
6879
| `API_KEY` | API token for accessing your Octopus Energy account. |
69-
| `TARIFFS` | A list of tariffs to compare against. Default is go,agile,flexible |
80+
| `TARIFFS` | A list of tariffs to compare against. Default is go,agile,flexible |
7081
| `EXECUTION_TIME` | (Optional) The time (HH:MM) when the script should execute. Default is `23:00` (11 PM). |
7182
| `SWITCH_THRESHOLD` | A value (in pence) which the saving must be before the switch occurs. Default is `2` (2p). |
7283
| `NOTIFICATION_URLS` | (Optional) A comma-separated list of [Apprise](https://github.com/caronc/apprise) notification URLs for sending logs and updates. See [Apprise documentation](https://github.com/caronc/apprise/wiki) for URL formats. |
7384
| `ONE_OFF` | (Optional) A flag for you to simply trigger an immediate execution instead of starting scheduling. |
74-
| `DRY_RUN` | (optional) A flag to compare but not switch tariffs. |
75-
| `BATCH_NOTIFICATIONS` | (optional) A flag to send messages in one batch rather than individually. |
85+
| `DRY_RUN` | (Optional) A flag to compare but not switch tariffs. |
86+
| `BATCH_NOTIFICATIONS` | (Optional) A flag to send messages in one batch rather than individually. |
87+
| `WEB_USERNAME` | (Optional) Defaults to `admin`. Auth for the web dashboard.
88+
| `WEB_PASSWORD` | (Optional) Defaults to `admin`. Auth for the web dashboard.
89+
| `WEB_PORT` | (Optional) Defaults to `5050`.
90+
91+
*Reminder: Change the password to something else other than default. It's not meant to be secure, it's just there to stop others on your network from accessing the dashboard and your API key. If they have access to your compose/config files you're already cooked.*
7692

7793
#### Supported Tariffs
7894

docker-compose.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ services:
55
container_name: MinMaxOctopusBot
66
image: eelmafia/octopus-minmax-bot
77
restart: unless-stopped
8+
ports:
9+
- "5050:5050"
10+
volumes:
11+
- ./logs:/app/logs
812
environment:
913
- TZ=Europe/London
1014
- ACC_NUMBER=<your_account_number>
@@ -15,3 +19,5 @@ services:
1519
- ONE_OFF=false
1620
- DRY_RUN=false
1721
- TARIFFS=go,agile,flexible
22+
- WEB_USERNAME=admin
23+
- WEB_PASSWORD=admin # not meant to be secure

dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ FROM python:3.9-slim
33
WORKDIR /app
44
COPY . /app
55
RUN pip install --no-cache-dir -r requirements.txt
6+
RUN mkdir -p /app/logs
7+
EXPOSE 5050
68

7-
CMD ["python", "-u", "scheduler.py"]
9+
CMD ["python", "-u", "src/main.py"]

0 commit comments

Comments
 (0)