diff --git a/examples/solar-monitoring.py b/examples/solar-monitoring.py index 7804ab3..04e381b 100644 --- a/examples/solar-monitoring.py +++ b/examples/solar-monitoring.py @@ -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) diff --git a/examples/test.py b/examples/test.py index 2f7719a..f66ceca 100644 --- a/examples/test.py +++ b/examples/test.py @@ -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"]) \ No newline at end of file +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]) \ No newline at end of file diff --git a/lib/waveshare_epd/__pycache__/__init__.cpython-310.pyc b/lib/waveshare_epd/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..070aeb0 Binary files /dev/null and b/lib/waveshare_epd/__pycache__/__init__.cpython-310.pyc differ diff --git a/lib/waveshare_epd/__pycache__/epd2in13b_V3.cpython-310.pyc b/lib/waveshare_epd/__pycache__/epd2in13b_V3.cpython-310.pyc new file mode 100644 index 0000000..7875a13 Binary files /dev/null and b/lib/waveshare_epd/__pycache__/epd2in13b_V3.cpython-310.pyc differ diff --git a/lib/waveshare_epd/__pycache__/epdconfig.cpython-310.pyc b/lib/waveshare_epd/__pycache__/epdconfig.cpython-310.pyc new file mode 100644 index 0000000..cbcd738 Binary files /dev/null and b/lib/waveshare_epd/__pycache__/epdconfig.cpython-310.pyc differ