diff --git a/DataPoints.py b/DataPoints.py old mode 100644 new mode 100755 index 2431c82..6ce07b6 --- a/DataPoints.py +++ b/DataPoints.py @@ -14,7 +14,7 @@ class Pulse: "power": float(power), "lastMeterConsumption": float(lastMeterConsumption) } - if cost is not None: + if cost is not None and float(cost) > 0: fields.update({'accumulatedCost':cost}) self.datapoint = {"fields": fields, "tags": tags, diff --git a/Dockerfile b/Dockerfile index dd424f4..6c3aebe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,6 @@ FROM python:3.12-slim-bookworm WORKDIR /app LABEL MAINTAINER="Jan-Ole Hübner " -RUN apt-get update && apt-get install -y cron - ADD requirements.txt /app RUN pip3 install -r /app/requirements.txt @@ -11,15 +9,6 @@ ENV PYTHONIOENCODING=utf-8 ADD . /app - -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 +RUN chmod 755 /app/pulse.py /app/get_price.py /app/start.sh CMD ["/app/start.sh"] diff --git a/delay_price.sh b/delay_price.sh deleted file mode 100644 index 2515c71..0000000 --- a/delay_price.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -source /app/env -printenv -sleep 2 - -python3 /app/get_price.py >> /var/log/cron.log 2>&1 \ No newline at end of file diff --git a/get_price.py b/get_price.py old mode 100644 new mode 100755 index 56d9aca..5fa5fe8 --- a/get_price.py +++ b/get_price.py @@ -21,7 +21,7 @@ ch.setFormatter(formatter) logger.addHandler(ch) logger.setLevel(logging.INFO) -__version__ = "v0.3.0" +__version__ = "v0.4.2" logger.info(__version__) client = InfluxDBClient(url=URL, token=TOKEN, org=ORG) diff --git a/pulse.py b/pulse.py old mode 100644 new mode 100755 index 94d812e..97c18f7 --- a/pulse.py +++ b/pulse.py @@ -1,7 +1,8 @@ - +import asyncio import os import signal import sys +import time import tibber from influxdb_client import InfluxDBClient @@ -24,7 +25,7 @@ ch.setFormatter(formatter) logger.addHandler(ch) logger.setLevel(logging.INFO) -__version__ = "v0.3.5_debug" +__version__ = "v0.4.3" logger.info(__version__) @@ -60,7 +61,7 @@ def stop(home): try: signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(15) - home.start_live_feed(user_agent="pulse.py/0.3.5",exit_condition=stop(home),retries=2,retry_interval=3.0) + home.start_live_feed(user_agent="pulse.py/0.4.3",exit_condition=stop(home),retries=4,retry_interval=5.0) except TypeError: logger.exception("Timeout occurred while executing start_live_feed()") client.close() diff --git a/start.sh b/start.sh index 6632127..1ac5d74 100644 --- a/start.sh +++ b/start.sh @@ -1,11 +1,16 @@ #!/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 & -# Keep the container running and output both cron logs and pulse.py output -tail -f /var/log/cron.log & +# 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 +) & + wait -n