diff --git a/DataPoints.py b/DataPoints.py old mode 100755 new mode 100644 index 6ce07b6..2431c82 --- a/DataPoints.py +++ b/DataPoints.py @@ -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, diff --git a/Dockerfile b/Dockerfile index 6c3aebe..dd424f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,8 @@ 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 @@ -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"] diff --git a/delay_price.sh b/delay_price.sh new file mode 100644 index 0000000..2515c71 --- /dev/null +++ b/delay_price.sh @@ -0,0 +1,6 @@ +#!/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 100755 new mode 100644 index 5fa5fe8..56d9aca --- a/get_price.py +++ b/get_price.py @@ -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) diff --git a/pulse.py b/pulse.py old mode 100755 new mode 100644 index 97c18f7..94d812e --- a/pulse.py +++ b/pulse.py @@ -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() diff --git a/start.sh b/start.sh index 1ac5d74..6632127 100644 --- a/start.sh +++ b/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