add multidimension dict

This commit is contained in:
Robert 2024-02-01 23:48:39 +01:00
parent 3084422a9f
commit eb48c868c6
5 changed files with 63 additions and 32 deletions

View File

@ -28,16 +28,43 @@ mqtt_broker = "openwb-2" # broker address, usually your HASS IP address
port = 1883
#set topics
topic_house_battery_soc = "openWB/bat/get/soc"
topic_house_battery_power = "openWB/bat/get/power"
topic0 = {
"topic" : "openWB/bat/get/soc",
"line" : "0",
"value" : ""
}
topic1 = {
"topic" : "openWB/bat/get/power",
"line" : "1",
"value" : ""
}
topic2 = {
"topic" : "openWB/counter/7/get/power",
"line" : "2",
"value" : ""
}
topic3 = {
"topic" : "openWB/pv/8/get/power",
"line" : "3",
"value" : ""
}
topic4 = {
"topic" : "openWB/graph/lastlivevaluesJson", #house-power
"line" : "4",
"value" : ""
}
topic5 = {
"topic" : "openWB/vehicle/4/get/soc",
"line" : "5",
"value" : ""
}
topic6 = {
"topic" : "openWB/internal_chargepoint/0/get/powers",
"line" : "6",
"value" : ""
}
topic_power_import_export = "openWB/counter/7/get/power"
topic_pv_power = "openWB/pv/8/get/power"
topic_house_power = "openWB/graph/lastlivevaluesJson" #house-power
topic_car_soc = "openWB/vehicle/4/get/soc"
topic_charge_point_power = "openWB/internal_chargepoint/0/get/powers"
topics = {0:topic0,1:topic1,2:topic2,3:topic3,4:topic4,5:topic5,6:topic6}
def connect_mqtt():
@ -63,7 +90,7 @@ def subscribe(client: mqtt_client, topic):
client.on_message = on_message
client.loop_stop()
def monitor(pv_power,house_power,power_import_export,house_battery_soc,house_battery_power,charge_point_power,car_soc):
def monitor(topics):
logging.info("epd2in13b_V3 Demo")
logging.info(libdir)
@ -93,14 +120,19 @@ def monitor(pv_power,house_power,power_import_export,house_battery_soc,house_bat
drawblack.text((2, 64), 'Batterie Entladen', font = font16, fill = 0)
drawblack.text((2, 80), 'Auto Laden', font = font16, fill = 0)
drawblack.text((160, 0), str(pv_power), font = font16, fill = 0)
drawblack.text((160, 16), str(house_power), font = font16, fill = 0)
drawblack.text((160, 32), str(power_import_export), font = font16, fill = 0)
drawblack.text((160, 48), str(house_battery_soc), font = font16, fill = 0)
drawblack.text((160, 64), str(house_battery_power), font = font16, fill = 0)
drawblack.text((160, 80), str(charge_point_power), font = font16, fill = 0)
for topic_id, topic_info in topics.items():
print("\nTopic ID:", topic_id)
for key in topic_info:
print(key + ':', topic_info[key])
drawblack.text((160, int(topic_info["line"])*16), topic_info["value"], font = font16, fill = 0)
topic_info["value"] = subscribe(client, topic_info["topic"])
#drawblack.text((160, 16), str(house_power), font = font16, fill = 0)
#drawblack.text((160, 32), str(power_import_export), font = font16, fill = 0)
#drawblack.text((160, 48), str(house_battery_soc), font = font16, fill = 0)
#drawblack.text((160, 64), str(house_battery_power), font = font16, fill = 0)
#drawblack.text((160, 80), str(charge_point_power), font = font16, fill = 0)
epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRYimage))
@ -124,23 +156,16 @@ def monitor(pv_power,house_power,power_import_export,house_battery_soc,house_bat
def run():
client = connect_mqtt()
house_battery_soc = subscribe(client, topic_house_battery_soc)
house_battery_power = subscribe(client, topic_house_battery_power)
power_import_export = subscribe(client, topic_power_import_export)
pv_power = subscribe(client, topic_pv_power)
house_power = subscribe(client, topic_house_power)
car_soc = subscribe(client, topic_car_soc)
charge_point_power = subscribe(client, topic_charge_point_power)
logging.info("house battery soc: " + str(house_battery_soc))
logging.info("house battery power: " + str(house_battery_power))
logging.info("power import export: " + str(power_import_export))
logging.info("pv power: " + str(pv_power))
logging.info("house power: " + str(house_power))
logging.info("car soc: " + str(car_soc))
logging.info("charge point power: " + str(charge_point_power))
for topic_id, topic_info in topics.items():
print("\nTopic ID:", topic_id)
for key in topic_info:
print(key + ':', topic_info[key])
topic_info["value"] = subscribe(client, topic_info["topic"])
try:
monitor(pv_power,house_power,power_import_export,house_battery_soc,house_battery_power,charge_point_power,car_soc)
monitor(topics)
except IOError as e:
logging.info(e)

View File

@ -39,4 +39,10 @@ topics = {0:topic0,1:topic1,2:topic2,3:topic3,4:topic4,5:topic5,6:topic6}
topics[3]['value'] = '20'
print(topics[3]["line"])
print(topics[3]["line"])
for topic_id, topic_info in topics.items():
print("\nTopic ID:", topic_id)
for key in topic_info:
print(key + ':', topic_info[key])

Binary file not shown.