first change
This commit is contained in:
		
							parent
							
								
									1184fcbeef
								
							
						
					
					
						commit
						5255f319f1
					
				@ -14,56 +14,11 @@ import time
 | 
				
			|||||||
from PIL import Image,ImageDraw,ImageFont
 | 
					from PIL import Image,ImageDraw,ImageFont
 | 
				
			||||||
import traceback
 | 
					import traceback
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Import MQTT client.
 | 
					 | 
				
			||||||
from paho.mqtt import client as mqtt_client
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
logging.basicConfig(level=logging.DEBUG)
 | 
					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
 | 
					#Define Display
 | 
				
			||||||
epd = epd2in13b_V3.EPD()
 | 
					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)
 | 
					drawblack = ImageDraw.Draw(HBlackimage)
 | 
				
			||||||
#drawry = ImageDraw.Draw(HRYimage)
 | 
					#drawry = ImageDraw.Draw(HRYimage)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def connect_mqtt():
 | 
					#!/usr/bin/env python3
 | 
				
			||||||
    def on_connect(client, userdata, flags, rc):
 | 
					# -*- coding: utf-8 -*-
 | 
				
			||||||
        if rc == 0:
 | 
					 | 
				
			||||||
            logging.info("Connected to MQTT Broker!")
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            logging.info("Failed to connect, return code %d\n", rc)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    client = mqtt_client.Client(client_id)
 | 
					import time
 | 
				
			||||||
    # client.username_pw_set(username, password)
 | 
					import datetime
 | 
				
			||||||
    client.on_connect = on_connect
 | 
					import locale
 | 
				
			||||||
    client.connect(mqtt_broker, port)
 | 
					 | 
				
			||||||
    return client
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					loc = locale.getlocale()
 | 
				
			||||||
 | 
					print (loc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def subscribe(client: mqtt_client, topic):
 | 
					datum = input('Datum: ')
 | 
				
			||||||
    def on_message(client, userdata, msg):
 | 
					td = datetime.timedelta(int(input('Abstand: ')))
 | 
				
			||||||
        print(f"Received `{msg.payload.decode()}` from `{msg.topic}` topic")
 | 
					datum1 = time.strptime(datum, '%Y-%m-%d')
 | 
				
			||||||
 | 
					datum2 = (datetime.datetime.fromtimestamp(time.mktime(datum1)) - td)
 | 
				
			||||||
    client.loop_start()
 | 
					print(datum2.strftime('%Y-%m-%d'))
 | 
				
			||||||
    client.subscribe(topic)
 | 
					  
 | 
				
			||||||
    client.on_message = on_message
 | 
					print(datum2.strftime('Der Wochentag ist %A'))
 | 
				
			||||||
    client.loop_stop()
 | 
					locale.setlocale(locale.LC_ALL, ('de_DE', 'UTF-8'))
 | 
				
			||||||
 | 
					print(datum2.strftime('Der Wochentag ist %A'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def init_monitor(topics):
 | 
					def init_monitor(topics):
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user