first change

This commit is contained in:
Borzutzki Robert 2024-11-25 22:07:51 +01:00
parent 1184fcbeef
commit 5255f319f1
2 changed files with 16 additions and 64 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@ -14,56 +14,11 @@ import time
from PIL import Image,ImageDraw,ImageFont
import traceback
# Import MQTT client.
from paho.mqtt import client as mqtt_client
logging.basicConfig(level=logging.DEBUG)
# MQTT credentials
#mqtt_username = 'homeassistant' # MQTT client username
#mqtt_password = '3355' # MQTT client password
client_id = 'solarmonitor' # unique client_id
mqtt_broker = "openwb-2" # broker address, usually your HASS IP address
port = 1883
#set topics
topic0 = {
"topic" : "openWB/bat/get/soc",
"line" : "0",
"value" : ""
}
topic1 = {
"topic" : "openWB/bat/get/power",
"line" : "16",
"value" : ""
}
topic2 = {
"topic" : "openWB/counter/7/get/power",
"line" : "32",
"value" : ""
}
topic3 = {
"topic" : "openWB/pv/8/get/power",
"line" : "48",
"value" : ""
}
topic4 = {
"topic" : "openWB/graph/lastlivevaluesJson", #house-power
"line" : "64",
"value" : ""
}
topic5 = {
"topic" : "openWB/vehicle/4/get/soc",
"line" : "80",
"value" : ""
}
topic6 = {
"topic" : "openWB/internal_chargepoint/0/get/powers",
"line" : "80",
"value" : ""
}
topics = {0:topic0,1:topic1,2:topic2,3:topic3,4:topic4,5:topic5,6:topic6}
#Define Display
epd = epd2in13b_V3.EPD()
@ -79,28 +34,25 @@ HRYimage = Image.new('1', (epd.height, epd.width), 255) # 298*126 ryimage: red
drawblack = ImageDraw.Draw(HBlackimage)
#drawry = ImageDraw.Draw(HRYimage)
def connect_mqtt():
def on_connect(client, userdata, flags, rc):
if rc == 0:
logging.info("Connected to MQTT Broker!")
else:
logging.info("Failed to connect, return code %d\n", rc)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
client = mqtt_client.Client(client_id)
# client.username_pw_set(username, password)
client.on_connect = on_connect
client.connect(mqtt_broker, port)
return client
import time
import datetime
import locale
loc = locale.getlocale()
print (loc)
def subscribe(client: mqtt_client, topic):
def on_message(client, userdata, msg):
print(f"Received `{msg.payload.decode()}` from `{msg.topic}` topic")
client.loop_start()
client.subscribe(topic)
client.on_message = on_message
client.loop_stop()
datum = input('Datum: ')
td = datetime.timedelta(int(input('Abstand: ')))
datum1 = time.strptime(datum, '%Y-%m-%d')
datum2 = (datetime.datetime.fromtimestamp(time.mktime(datum1)) - td)
print(datum2.strftime('%Y-%m-%d'))
print(datum2.strftime('Der Wochentag ist %A'))
locale.setlocale(locale.LC_ALL, ('de_DE', 'UTF-8'))
print(datum2.strftime('Der Wochentag ist %A'))
def init_monitor(topics):