So, nachdem ich meinen Hardwareaufbau gepostet habe komme ich jetzt zur Software (vielen Dank nochmal an Tombra).
Ich habe die Software etwas angepasst (ich brauche kein Homebridgemapping) und habe zudem den Vorschlag aufgenommen den aktuellen Kanal in einer Datei zwischenzuspeichern, dadurch geht das Schalten schneller.
Hier die Konfig in FHEM:
Code
define RolladenKueche ROLLO
attr RolladenKueche alias Rolladen Fenster
attr RolladenKueche autoStop 0
attr RolladenKueche devStateIcon open:fts_shutter_10:closed closed:fts_shutter_100:open half:fts_shutter_50:closed drive-up:fts_shutter_up@red:stop drive-down:fts_shutter_down@red:stop position-100:fts_shutter_100:open position-90:fts_shutter_80:closed position-80:fts_shutter_80:closed position-70:fts_shutter_70:closed position-60:fts_shutter_60:closed position-50:fts_shutter_50:closed position-40:fts_shutter_40:open position-30:fts_shutter_30:open position-20:fts_shutter_20:open position-10:fts_shutter_10:open position-0:fts_shutter_10:closed
attr RolladenKueche excessBottom 0
attr RolladenKueche excessTop 0
attr RolladenKueche group Küche
attr RolladenKueche resetTime 0
attr RolladenKueche room Rolläden
attr RolladenKueche secondsDown 15
attr RolladenKueche secondsUp 15
attr RolladenKueche switchTime 1
attr RolladenKueche type normal
attr RolladenKueche webCmd open:closed:half:stop:position
define RolladenKueche_drive_up notify RolladenKueche:drive-up {system('python /opt/fhem/jarolift.py 1 drive-up&');;;;}
define RolladenKueche_drive_down notify RolladenKueche:drive-down {system('python /opt/fhem/jarolift.py 1 drive-down&');;;;}
define RolladenKueche_stop notify RolladenKueche:position-10|RolladenKueche:position-20|RolladenKueche:position-30|RolladenKueche:position-40|RolladenKueche:half|RolladenKueche:position-60|RolladenKueche:position-70|RolladenKueche:position-80|RolladenKueche:position-90 {system('python /opt/fhem/jarolift.py 1 stop&');;;;}
Alles anzeigen
Hier meine Datei Namens jarolift.py:
Code
import time
import RPi.GPIO as GPIO
import sys
import pickle
# RPi.GPIO Layout verwenden (wie Pin-Nummern)
GPIO.setmode(GPIO.BOARD)
# Pin 22 (GPIO 25) auf Output setzen
GPIO.setup(22, GPIO.OUT)
position = int(sys.argv[1])
richtung = str(sys.argv[2])
print "Rolladen neuer Kanal "+ str(position)
print "Rolladen neue Richtung "+ str(richtung)
px = position
p0 = 16 -px
# WARTEN bis GPIO frei
while GPIO.input(22) == GPIO.HIGH:
time.sleep(0.5)
print "GPIO blockiert"
# Pin 22 auf HIGH setzen
GPIO.output(22, GPIO.HIGH)
# Pin 11 (GPIO 17) auf Output setzen
GPIO.setup(11, GPIO.OUT)
# Pin 12 (GPIO 18) auf Output setzen
GPIO.setup(12, GPIO.OUT)
# Pin 13 (GPIO 27) auf Output setzen
GPIO.setup(13, GPIO.OUT)
# Pin 15 (GPIO 22) auf Output setzen
GPIO.setup(15, GPIO.OUT)
# Pin 16 (GPIO 23) auf Output setzen
GPIO.setup(16, GPIO.OUT)
# Position aus Datei ruecklesen
pkl_file = open('position.pkl', 'rb')
data_old = pickle.load(pkl_file)
print "Rolladen aktueller Kanal "+ str(data_old)
pkl_file.close()
# POSITION einstellen
print "Rolladen Kanal "+ str(px) +" einstellen"
i = data_old
GPIO.output(11, GPIO.LOW)
print "11 Off!"
GPIO.output(16, GPIO.LOW)
print "16 Off!"
time.sleep(0.1)
while i < px:
GPIO.output(11, GPIO.HIGH)
print "11 On!"
time.sleep(0.1)
GPIO.output(11, GPIO.LOW)
print "11 Off!"
time.sleep(0.1)
i = i + 1
while i > px:
GPIO.output(16, GPIO.HIGH)
print "16 On!"
time.sleep(0.1)
GPIO.output(16, GPIO.LOW)
print "16 Off!"
time.sleep(0.1)
i = i - 1
# SCHALTER schalten
if richtung == 'drive-up':
print "Rolladen Kanal "+ str(px) +" hochfahren"
GPIO.output(12, GPIO.LOW)
print "12 Off!"
time.sleep(0.1)
GPIO.output(12, GPIO.HIGH)
print "12 On!"
time.sleep(1.4)
GPIO.output(12, GPIO.LOW)
print "12 Off!"
# SCHALTER schalten
if richtung == 'stop':
print "Rolladen Kanal "+ str(px) +" stoppen"
GPIO.output(13, GPIO.LOW)
print "13 Off!"
time.sleep(0.1)
GPIO.output(13, GPIO.HIGH)
print "13 On!"
time.sleep(1.4)
GPIO.output(13, GPIO.LOW)
print "13 Off!"
# SCHALTER schalten
if richtung == 'drive-down':
print "Rolladen Kanal "+ str(px) +" runterfahren"
GPIO.output(15, GPIO.LOW)
print "15 Off!"
time.sleep(0.1)
GPIO.output(15, GPIO.HIGH)
print "15 On!"
time.sleep(1.4)
GPIO.output(15, GPIO.LOW)
print "15 Off!"
# Position in Datei schreiben
data = px
output = open('position.pkl', 'wb')
pickle.dump(data, output)
output.close()
# Pin 22 auf LOW setzen
GPIO.output(22, GPIO.LOW)
GPIO.cleanup()
Alles anzeigen
Und die noch benötigte Datei zum zwischenspeichern Namens Position.pkl:
Hoffe ihr könnt damit was anfangen und ich hoffe Tombra kann das mit dem zwischenspeichern für sich übernehmen.
Gruß
Markus