smart.py aktualisiert
This commit is contained in:
57
smart.py
57
smart.py
@@ -9,7 +9,7 @@ from bs4 import BeautifulSoup
|
|||||||
import urllib3
|
import urllib3
|
||||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||||
import random
|
import random
|
||||||
from paho.mqtt import client as mqtt_client
|
import paho.mqtt.publish as publish
|
||||||
|
|
||||||
# General config
|
# General config
|
||||||
user= '1707910897002706169923_ECPR0002108185'
|
user= '1707910897002706169923_ECPR0002108185'
|
||||||
@@ -20,7 +20,7 @@ meter-id= '1EFR2375175891'
|
|||||||
|
|
||||||
# MQTT config
|
# MQTT config
|
||||||
broker= 'homeassistant'
|
broker= 'homeassistant'
|
||||||
port= 1883
|
mqttport= 1883
|
||||||
mqttuser= 'mqtt'
|
mqttuser= 'mqtt'
|
||||||
mqttpass= 'mqtt1234'
|
mqttpass= 'mqtt1234'
|
||||||
|
|
||||||
@@ -51,14 +51,51 @@ res= s.post(url, data=post_data,cookies=cookies,verify=False)
|
|||||||
|
|
||||||
soup = BeautifulSoup(res.content, 'html.parser')
|
soup = BeautifulSoup(res.content, 'html.parser')
|
||||||
table_data = soup.find('table', id="metervalue")
|
table_data = soup.find('table', id="metervalue")
|
||||||
result_data = {
|
|
||||||
'value': table_data.find(id="table_metervalues_col_wert").string,
|
# Listen, um die Daten zu speichern
|
||||||
'unit': table_data.find(id="table_metervalues_col_einheit").string,
|
results = []
|
||||||
'timestamp': table_data.find(id="table_metervalues_col_timestamp").string,
|
|
||||||
'isvalid': table_data.find(id="table_metervalues_col_istvalide").string,
|
# Alle Zeilen der Tabelle finden (außer der Kopfzeile)
|
||||||
'name': table_data.find(id="table_metervalues_col_name").string,
|
rows = table_data.find_all('tr')[1:] # Überspringe die erste Zeile, da es eine Kopfzeile gibt
|
||||||
'obis': table_data.find(id="table_metervalues_col_obis").string
|
|
||||||
|
for row in rows:
|
||||||
|
result_data = {
|
||||||
|
'value': table_data.find(id="table_metervalues_col_wert").string,
|
||||||
|
'unit': table_data.find(id="table_metervalues_col_einheit").string,
|
||||||
|
'timestamp': table_data.find(id="table_metervalues_col_timestamp").string,
|
||||||
|
'isvalid': table_data.find(id="table_metervalues_col_istvalide").string,
|
||||||
|
'name': table_data.find(id="table_metervalues_col_name").string,
|
||||||
|
'obis': table_data.find(id="table_metervalues_col_obis").string
|
||||||
|
}
|
||||||
|
msgs = [
|
||||||
|
{
|
||||||
|
'topic': f"homeassistant/sensor/{meter_id}_{result_data['obis']}_value",
|
||||||
|
'payload': result_data['value'], 'qos':1, 'retain': False
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'topic': f"homeassistant/sensor/{meter_id}_{result_data['obis']}_unit",
|
||||||
|
'payload': result_data['unit'], 'qos':1, 'retain': False
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'topic': f"homeassistant/sensor/{meter_id}_{result_data['obis']}_timestamp",
|
||||||
|
'payload': result_data['timestamp'], 'qos':1, 'retain': False
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'topic': f"homeassistant/sensor/{meter_id}_{result_data['obis']}_isvalid",
|
||||||
|
'payload': result_data['isvalid'], 'qos':1, 'retain': False
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'topic': f"homeassistant/sensor/{meter_id}_{result_data['obis']}_name",
|
||||||
|
'payload': result_data['name'], 'qos':1, 'retain': False
|
||||||
}
|
}
|
||||||
print(result_data['timestamp']+ " " + result_data['value']+ " " + result_data['unit'])
|
]
|
||||||
|
results.append(result_data)
|
||||||
|
publish.multiple(msgs, hostname= broker, port= mqttport,retained=False, auth={'username': mqttuser, 'password':mqttpass})
|
||||||
|
|
||||||
|
# Ergebnisse ausgeben
|
||||||
|
for result in results:
|
||||||
|
print(result['timestamp']+ " " + result['value']+ " " + result['unit'])
|
||||||
|
|
||||||
|
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user