Compare commits
12 commits
c889c9f6de
...
336eefb963
Author | SHA1 | Date | |
---|---|---|---|
336eefb963 | |||
b13d3e6857 | |||
9d3afcd801 | |||
9fa7581574 | |||
877cda9640 | |||
d5fce90b8d | |||
83a23b3c1b | |||
043170481a | |||
610cdd6a65 | |||
fdad6c3d72 | |||
cd4819252d | |||
4a716859b0 |
6 changed files with 18 additions and 29 deletions
2
DataPoints.py
Normal file → Executable file
2
DataPoints.py
Normal file → Executable file
|
@ -14,7 +14,7 @@ class Pulse:
|
||||||
"power": float(power),
|
"power": float(power),
|
||||||
"lastMeterConsumption": float(lastMeterConsumption)
|
"lastMeterConsumption": float(lastMeterConsumption)
|
||||||
}
|
}
|
||||||
if cost is not None:
|
if cost is not None and float(cost) > 0:
|
||||||
fields.update({'accumulatedCost':cost})
|
fields.update({'accumulatedCost':cost})
|
||||||
self.datapoint = {"fields": fields,
|
self.datapoint = {"fields": fields,
|
||||||
"tags": tags,
|
"tags": tags,
|
||||||
|
|
13
Dockerfile
13
Dockerfile
|
@ -2,8 +2,6 @@ FROM python:3.12-slim-bookworm
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
LABEL MAINTAINER="Jan-Ole Hübner <huebner@jan-ole.de>"
|
LABEL MAINTAINER="Jan-Ole Hübner <huebner@jan-ole.de>"
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y cron
|
|
||||||
|
|
||||||
ADD requirements.txt /app
|
ADD requirements.txt /app
|
||||||
RUN pip3 install -r /app/requirements.txt
|
RUN pip3 install -r /app/requirements.txt
|
||||||
|
|
||||||
|
@ -11,15 +9,6 @@ ENV PYTHONIOENCODING=utf-8
|
||||||
|
|
||||||
ADD . /app
|
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"]
|
CMD ["/app/start.sh"]
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
source /app/env
|
|
||||||
printenv
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
python3 /app/get_price.py >> /var/log/cron.log 2>&1
|
|
2
get_price.py
Normal file → Executable file
2
get_price.py
Normal file → Executable file
|
@ -21,7 +21,7 @@ ch.setFormatter(formatter)
|
||||||
logger.addHandler(ch)
|
logger.addHandler(ch)
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
__version__ = "v0.3.0"
|
__version__ = "v0.4.2"
|
||||||
logger.info(__version__)
|
logger.info(__version__)
|
||||||
|
|
||||||
client = InfluxDBClient(url=URL, token=TOKEN, org=ORG)
|
client = InfluxDBClient(url=URL, token=TOKEN, org=ORG)
|
||||||
|
|
7
pulse.py
Normal file → Executable file
7
pulse.py
Normal file → Executable file
|
@ -1,7 +1,8 @@
|
||||||
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
import tibber
|
import tibber
|
||||||
from influxdb_client import InfluxDBClient
|
from influxdb_client import InfluxDBClient
|
||||||
|
@ -24,7 +25,7 @@ ch.setFormatter(formatter)
|
||||||
logger.addHandler(ch)
|
logger.addHandler(ch)
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
__version__ = "v0.3.5_debug"
|
__version__ = "v0.4.3"
|
||||||
logger.info(__version__)
|
logger.info(__version__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ def stop(home):
|
||||||
try:
|
try:
|
||||||
signal.signal(signal.SIGALRM, timeout_handler)
|
signal.signal(signal.SIGALRM, timeout_handler)
|
||||||
signal.alarm(15)
|
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:
|
except TypeError:
|
||||||
logger.exception("Timeout occurred while executing start_live_feed()")
|
logger.exception("Timeout occurred while executing start_live_feed()")
|
||||||
client.close()
|
client.close()
|
||||||
|
|
17
start.sh
17
start.sh
|
@ -1,11 +1,16 @@
|
||||||
#!/bin/bash
|
#!/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 &
|
python3 /app/pulse.py &
|
||||||
|
|
||||||
# Keep the container running and output both cron logs and pulse.py output
|
# Run the other script at 0, 15, 30, 45, and 60 minutes
|
||||||
tail -f /var/log/cron.log &
|
(
|
||||||
|
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
|
wait -n
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue