Last active
January 8, 2026 15:35
-
-
Save soundstorm/802986cebd52d9b4a3985879e1f514c1 to your computer and use it in GitHub Desktop.
AHA Hannover MQTT Abholtermine (Abfallwirtschaft Hannover)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import re, requests | |
| import paho.mqtt.client as mqtt | |
| import time, datetime | |
| data = { | |
| 'gemeinde': 'Hannover', | |
| 'strasse': '00590@Burgweg@', # Wert des Dropdowns | |
| 'hausnr': '5', | |
| 'hausnraddon': '', | |
| 'ladeort': '' | |
| } | |
| base_topic = "paul-dohrmann-schule/abfall/" | |
| hass_topic = "homeassistant" # if set to None Home Assistant Auto Discovery is disabled | |
| client = mqtt.Client("aha-abfall") | |
| client.username_pw_set("user", "password") | |
| client.connect("host", port=1883, keepalive=60) | |
| morgen = (datetime.date.today() + datetime.timedelta(days=1)).strftime('%d.%m.%Y') | |
| abfallarten = ['Restabfall', 'Bioabfall', 'Papier', 'Leichtverpackungen'] | |
| req = requests.post("https://www.aha-region.de/abholtermine/abfuhrkalender/", data=data) | |
| for abfall in abfall_types: | |
| try: | |
| beg = req.text.index('<strong>' + abfall['type']) | |
| end = req.text.index('colspan="3"', beg) | |
| termine = re.findall("\w{2}, (\d{2}\.\d{2}\.\d{4})", req.text[beg:end]) | |
| client.publish("homeassistant/binary_sensor/%s/config" % (abfall['type'],), '{"stat_t":"%s/%s/morgen", "uniq_id": "%s%s%s", "dev": {"ids":["ahaahaaha"], "name":"Abfall", "mf": "aha", "mdl":"Abfall","sw":"Ich bin Müll"}, "json_attr_t":"%s/%s/att", "name": "%s", "pl_on": 1, "pl_off": 0}' % (base_topic, abfall['type'], data['strasse'], data['hausnr'], abfall['type'], base_topic, abfall['type'], abfall['type']), retain=True) | |
| client.publish("%s/%s" % (base_topic, abfall['type']), termine[0], retain=True) | |
| client.publish("%s/%s/att" % (base_topic, abfall['type']), '{"next":"%s"}' % (termine[0],), retain=True) | |
| client.publish("%s/%s/morgen" % (base_topic, abfall['type']), '1' if (morgen == termine[0]) else '0' , retain=True) | |
| except(ValueError): | |
| print("Abfallart nicht gefunden") | |
| client.wait_for_publish() | |
| client.disconnect() |
Author
Klasse, werde ich ausprobieren. Ich hatte es zwischenzeitlich über NodeRed http_request -> MQTT implementiert und auf einer LED matrix Anzeige ausgegeben. Dein neuer Ansatz gefällt mir aber gut.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@DonKracho https://github.com/soundstorm/aha_trash sollte das jetzt ablösen können ohne zusätzliche Abhängigkeiten