Mr.Servo hat geschrieben:Danke Di sehr für den Tip! Hast Du evtl. ein einfaches Beispiel für so ein Script, was Du als Musterbeispiel hier posten magst / könntest?
Ds würde sicher den einen oder anderen inspirieren da mal auf eigene Faust loszulegen
Danke & Gruß.....Mr.Servo
Das ist wirklich nur ein Beispiel und läuft hier auf einem Raspberry3
Python Script alle 5min per Crontab.
*/5 * * * * sleep 80; /home/pi/vaillant/vaillant.py >> /var/log/vaillant.log 2>&1
Ja das Script benötigt weitere imports, aber die "dm920" (lcd4linux) Parts kann man sich ansehen (Text/Kreis) .Wird auch was in eine SQL Datenbank geschrieben und auch in Domoticz eingestellt. Aber ich wollte das jetzt nicht zusammenhangslos zerpflücken.
Code: Alles auswählen
#!/usr/bin/python3
# -*- coding: utf-8 -*-#
import MySQLdb
from datetime import datetime, timedelta
import time
import ping
from vr900connector.systemmanager import SystemManager
from vr900connector.api.payloads import Payloads
from vr900connector.api.urls import Urls
from vr900connector.api.apiconnector import ApiConnector
# Datenbank Verbindung
def connection():
conn = MySQLdb.connect(host="localhost", user = "loginuser", passwd = "loginpass", db = "vaillant", charset="utf8", use_unicode=True)
c = conn.cursor()
return c, conn
# Daten in SQL Datenbank schreiben date vorlauf wasser druck mode temp timestamp
def WriteLive(vorlauf,wasser,druck,mode,temp,timestamp):
YearBack=datetime.today() - timedelta(730) # 365
print(time.strftime('%Y-%m-%d %H:%M:%S'))
c,conn = connection()
data = c.execute("INSERT INTO daten (date,vorlauf,wasser,druck,mode,temp,timestamp) VALUES('%s',%s,%s,%s,'%s',%s,'%s')" % (time.strftime('%Y-%m-%d %H:%M:%S'),vorlauf,wasser,druck,mode,temp,timestamp))
# data = c.execute("delete FROM log WHERE time < '%s'" % YearBack.strftime("%Y-%m-%d 00:00"))
conn.commit()
c.close()
conn.close()
try:
import sys
x=ApiConnector("vaillantlogin","vaillantpass!")
a=x.get(Urls._LIVE_REPORT)
vorlauf=a["body"]["devices"][0]["reports"][0]["value"]
wasser=a["body"]["devices"][1]["reports"][0]["value"]
druck=a["body"]["devices"][2]["reports"][0]["value"]
timestamp=datetime.fromtimestamp(a["meta"]["resourceState"][0]["timestamp"])
a=x.get(Urls.zone_heating_configuration("Control_ZO1"))
mode=a["body"]["operation_mode"]
a=x.get(Urls._SYSTEM)
temp=a["body"]["zones"][0]["configuration"]["inside_temperature"]
active=a["body"]["zones"][0]["configuration"]["active_function"]
print(vorlauf,wasser,druck,mode,temp,timestamp)
WriteLive(vorlauf,wasser,druck,mode,temp,timestamp)
##### DM920
import pings
p = pings.Ping()
r = p.ping("DM920",1)
print("Ping:",str(r.is_reached()))
import urllib3
from time import strftime
timeout = urllib3.util.Timeout(connect=3.0, read=3.0, total=10.0)
http = urllib3.PoolManager(timeout=timeout)
if r.is_reached():
print("write Dream...")
DreamUrl = "http://dm920/lcd4linux/config"
q = {'cmd':'add', 'ex':"Vaillant.txt1, {'Mode':'OnMediaIdle', 'Typ':'txt','Align':'2','Lcd':3,'Screen':'12345','Color':'orange','Pos':50,'Size':13,'Text':'%s'}" % (str(vorlauf)+'°')}
response = http.request("GET",DreamUrl, fields=q)
q = {'cmd':'add', 'ex':"Vaillant.txt2, {'Mode':'OnMediaIdle', 'Typ':'txt','Align':'2','Lcd':3,'Screen':'12345','Color':'cyan','Pos':65,'Size':13,'Text':'%s'}" % (str(wasser)+'°')}
response = http.request("GET",DreamUrl, fields=q)
q = {'cmd':'add', 'ex':"Vaillant.txt3, {'Mode':'OnMediaIdle', 'Typ':'txt','Align':'2','Lcd':3,'Screen':'12345','Color':'lightyellow','Pos':80,'Size':13,'Text':'%s'}" % (str(druck)+'bar')}
response = http.request("GET",DreamUrl, fields=q)
q = {'cmd':'delete', 'ex':"Vaillant.circle1"}
response = http.request("GET",DreamUrl, fields=q)
q = {'cmd':'refresh'}
response = http.request("GET",DreamUrl, fields=q)
print("write Raspberry...")
DomoticzUrl = "http://raspberry3:8080/json.htm?type=command¶m=updateuservariable&vname=Vaillant&vtype=string&vvalue=%s" % "OK"
response = http.request("GET",DomoticzUrl)
http.clear()
except Exception as e:
from traceback import format_exc
print("Error: ",time.strftime('%Y-%m-%d %H:%M:%S'),e)
print("Error: ",format_exc() )
try:
import urllib3
from time import strftime
timeout = urllib3.util.Timeout(connect=3.0, read=3.0, total=10.0)
http = urllib3.PoolManager(timeout=timeout)
print("Put Raspberry")
DomoticzUrl = "http://raspberry3:8080/json.htm?type=command¶m=updateuservariable&vname=Vaillant&vtype=string&vvalue=%s" % "Error"
response = http.request("GET",DomoticzUrl)
print("Put Dream" )
DreamUrl = "http://dm920/lcd4linux/config"
q = {'cmd':'add', 'ex':"Vaillant.circle1, {'Mode':'OnMediaIdle','Typ':'circle','Color':'red','Lcd':3,'Screen':'12345','Color':'red','Size':15,'PosX':320,'PosY':0}"}
response = http.request("GET",DreamUrl, fields=q)
http.clear()
except:
print("Error: ",e)
print("Error: ",format_exc() )
Hier noch ein anderer Part in dem Bilddateien (müssen schon auf der Box im angegebenen Verzeichnis liegen) zur Anzeige gebracht werden.
Code: Alles auswählen
timeout = urllib3.util.Timeout(connect=3.0, read=3.0, total=10.0)
http = urllib3.PoolManager(timeout=timeout)
if ModeID == 0: # OFF
q = {'cmd':'delete', 'ex':"Vaillant.p"}
response = http.request("GET","http://dm920/lcd4linux/config", fields=q)
elif ModeID == 10: # TIME_CONTROLLED
q = {'cmd':'add', 'ex':"Vaillant.pic1, {'Mode':'OnMediaIdle', 'Typ':'pic','File':'/data/eigene/heizung.png','Size':30,'Pos':0,'Align':'2','Transp':True,'Lcd':3,'Screen':'12345'}"}
response = http.request("GET","http://dm920/lcd4linux/config", fields=q)
q = {'cmd':'add', 'ex':"Vaillant.pic2, {'Mode':'OnMediaIdle', 'Typ':'pic','File':'/data/eigene/timer.png','Size':20,'Pos':25,'Align':'2','Transp':True,'Lcd':3,'Screen':'12345'}"}
response = http.request("GET","http://dm920/lcd4linux/config", fields=q)
elif ModeID == 20: # MANUELL
q = {'cmd':'add', 'ex':"Vaillant.pic1, {'Mode':'OnMediaIdle', 'Typ':'pic','File':'/data/eigene/heizung.png','Size':30,'Pos':0,'Align':'2','Transp':True,'Lcd':3,'Screen':'12345'}"}
response = http.request("GET","http://dm920/lcd4linux/config", fields=q)
q = {'cmd':'delete', 'ex':"Vaillant.pic2"}
response = http.request("GET","http://dm920/lcd4linux/config", fields=q)
http.clear()
Natürlich könnte man auch normale Shell-Scripte nutzen und dann mit "wget" den http-Request "auslösen". Ich finde man hat in Python bessere Möglichkeiten der Programmierung.
Weitere Infos in der ExternalElements.txt aus dem L4L-Heimat-Forum.
Der Bildausschnitt auf dem LCD schaut dann so aus:
Der Dateianhang vaillant.PNG existiert nicht mehr.