add multidimension dict
This commit is contained in:
parent
3084422a9f
commit
eb48c868c6
@ -28,16 +28,43 @@ mqtt_broker = "openwb-2" # broker address, usually your HASS IP address
|
|||||||
port = 1883
|
port = 1883
|
||||||
|
|
||||||
#set topics
|
#set topics
|
||||||
topic_house_battery_soc = "openWB/bat/get/soc"
|
topic0 = {
|
||||||
topic_house_battery_power = "openWB/bat/get/power"
|
"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"
|
topics = {0:topic0,1:topic1,2:topic2,3:topic3,4:topic4,5:topic5,6:topic6}
|
||||||
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"
|
|
||||||
|
|
||||||
|
|
||||||
def connect_mqtt():
|
def connect_mqtt():
|
||||||
@ -63,7 +90,7 @@ def subscribe(client: mqtt_client, topic):
|
|||||||
client.on_message = on_message
|
client.on_message = on_message
|
||||||
client.loop_stop()
|
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("epd2in13b_V3 Demo")
|
||||||
logging.info(libdir)
|
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, 64), 'Batterie Entladen', font = font16, fill = 0)
|
||||||
drawblack.text((2, 80), 'Auto Laden', 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)
|
for topic_id, topic_info in topics.items():
|
||||||
drawblack.text((160, 16), str(house_power), font = font16, fill = 0)
|
print("\nTopic ID:", topic_id)
|
||||||
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 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))
|
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():
|
def run():
|
||||||
client = connect_mqtt()
|
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))
|
for topic_id, topic_info in topics.items():
|
||||||
logging.info("house battery power: " + str(house_battery_power))
|
print("\nTopic ID:", topic_id)
|
||||||
logging.info("power import export: " + str(power_import_export))
|
|
||||||
logging.info("pv power: " + str(pv_power))
|
for key in topic_info:
|
||||||
logging.info("house power: " + str(house_power))
|
print(key + ':', topic_info[key])
|
||||||
logging.info("car soc: " + str(car_soc))
|
topic_info["value"] = subscribe(client, topic_info["topic"])
|
||||||
logging.info("charge point power: " + str(charge_point_power))
|
|
||||||
try:
|
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:
|
except IOError as e:
|
||||||
logging.info(e)
|
logging.info(e)
|
||||||
|
@ -40,3 +40,9 @@ 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])
|
BIN
lib/waveshare_epd/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
lib/waveshare_epd/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
lib/waveshare_epd/__pycache__/epd2in13b_V3.cpython-310.pyc
Normal file
BIN
lib/waveshare_epd/__pycache__/epd2in13b_V3.cpython-310.pyc
Normal file
Binary file not shown.
BIN
lib/waveshare_epd/__pycache__/epdconfig.cpython-310.pyc
Normal file
BIN
lib/waveshare_epd/__pycache__/epdconfig.cpython-310.pyc
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user