Compare commits
No commits in common. "336eefb963b87d412a1777d36be9e04dd6f71b25" and "c889c9f6def8a3dde3ce2a925b8338c021de4767" have entirely different histories.
336eefb963
...
c889c9f6de
6 changed files with 29 additions and 18 deletions
2
DataPoints.py
Executable file → Normal file
2
DataPoints.py
Executable file → Normal file
|
@ -14,7 +14,7 @@ class Pulse:
|
|||
"power": float(power),
|
||||
"lastMeterConsumption": float(lastMeterConsumption)
|
||||
}
|
||||
if cost is not None and float(cost) > 0:
|
||||
if cost is not None:
|
||||
fields.update({'accumulatedCost':cost})
|
||||
self.datapoint = {"fields": fields,
|
||||
"tags": tags,
|
||||
|
|
13
Dockerfile
13
Dockerfile
|
@ -2,6 +2,8 @@ FROM python:3.12-slim-bookworm
|
|||
WORKDIR /app
|
||||
LABEL MAINTAINER="Jan-Ole Hübner <huebner@jan-ole.de>"
|
||||
|
||||
RUN apt-get update && apt-get install -y cron
|
||||
|
||||
ADD requirements.txt /app
|
||||
RUN pip3 install -r /app/requirements.txt
|
||||
|
||||
|
@ -9,6 +11,15 @@ ENV PYTHONIOENCODING=utf-8
|
|||
|
||||
ADD . /app
|
||||
|
||||
RUN chmod 755 /app/pulse.py /app/get_price.py /app/start.sh
|
||||
|
||||
RUN echo "SHELL=/bin/bash\nBASH_ENV=/app/env\n* * * * * root /app/delay_price.sh >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price
|
||||
|
||||
RUN chmod 0644 /etc/cron.d/get_price
|
||||
|
||||
RUN crontab /etc/cron.d/get_price
|
||||
|
||||
RUN touch /var/log/cron.log
|
||||
|
||||
RUN chmod 755 /app/pulse.py /app/get_price.py /app/start.sh /app/delay_price.sh
|
||||
|
||||
CMD ["/app/start.sh"]
|
||||
|
|
6
delay_price.sh
Normal file
6
delay_price.sh
Normal file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
source /app/env
|
||||
printenv
|
||||
sleep 2
|
||||
|
||||
python3 /app/get_price.py >> /var/log/cron.log 2>&1
|
2
get_price.py
Executable file → Normal file
2
get_price.py
Executable file → Normal file
|
@ -21,7 +21,7 @@ ch.setFormatter(formatter)
|
|||
logger.addHandler(ch)
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
__version__ = "v0.4.2"
|
||||
__version__ = "v0.3.0"
|
||||
logger.info(__version__)
|
||||
|
||||
client = InfluxDBClient(url=URL, token=TOKEN, org=ORG)
|
||||
|
|
7
pulse.py
Executable file → Normal file
7
pulse.py
Executable file → Normal file
|
@ -1,8 +1,7 @@
|
|||
import asyncio
|
||||
|
||||
import os
|
||||
import signal
|
||||
import sys
|
||||
import time
|
||||
|
||||
import tibber
|
||||
from influxdb_client import InfluxDBClient
|
||||
|
@ -25,7 +24,7 @@ ch.setFormatter(formatter)
|
|||
logger.addHandler(ch)
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
__version__ = "v0.4.3"
|
||||
__version__ = "v0.3.5_debug"
|
||||
logger.info(__version__)
|
||||
|
||||
|
||||
|
@ -61,7 +60,7 @@ def stop(home):
|
|||
try:
|
||||
signal.signal(signal.SIGALRM, timeout_handler)
|
||||
signal.alarm(15)
|
||||
home.start_live_feed(user_agent="pulse.py/0.4.3",exit_condition=stop(home),retries=4,retry_interval=5.0)
|
||||
home.start_live_feed(user_agent="pulse.py/0.3.5",exit_condition=stop(home),retries=2,retry_interval=3.0)
|
||||
except TypeError:
|
||||
logger.exception("Timeout occurred while executing start_live_feed()")
|
||||
client.close()
|
||||
|
|
17
start.sh
17
start.sh
|
@ -1,16 +1,11 @@
|
|||
#!/bin/bash
|
||||
printenv > /app/env
|
||||
# Start the cron service
|
||||
service cron start
|
||||
|
||||
# Run your main application script (pulse.py) in the background
|
||||
python3 /app/pulse.py &
|
||||
|
||||
# Run the other script at 0, 15, 30, 45, and 60 minutes
|
||||
(
|
||||
while true; do
|
||||
current_minute=$(date +'%M')
|
||||
if [[ "$current_minute" == "00" || "$current_minute" == "15" || "$current_minute" == "30" || "$current_minute" == "45" || "$current_minute" == "00" ]]; then
|
||||
python3 /app/get_price.py
|
||||
fi
|
||||
sleep 60 # Check every minute
|
||||
done
|
||||
) &
|
||||
|
||||
# Keep the container running and output both cron logs and pulse.py output
|
||||
tail -f /var/log/cron.log &
|
||||
wait -n
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue