# Version 1.0 # first take device's ip and id # pip3 install msmart; midea-discover import sys import logging import ast from msmart.device import device as midea_device from msmart.device import air_conditioning_device as ac def parse(string): d = {'True': True, 'False': False} return d.get(string, string) logging.basicConfig(level=logging.DEBUG) #logging.basicConfig(level=logging.INFO) for i in range(len(sys.argv)): if i == 0: print ("Funktionsname: %s" % sys.argv[0]) else: #print ("%d. Argument: %s" % (i,sys.argv[i])) if i == 1: ipaddr=sys.argv[i] print ("IP Adresse= %s" % (ipaddr)) if i == 2: id=int(sys.argv[i]) print ("ID= %s" % (id)) if i == 3: power=parse(sys.argv[i]) print ("Power= %s" % (power)) if i == 4: mod=int(sys.argv[i]) print ("Modus= %s" % (mod)) if i == 5: ton=parse(sys.argv[i]) print ("Tone= %s" % (ton)) if i == 6: solltemp=float(sys.argv[i]) print ("Solltemp= %s" % (solltemp)) if i == 7: fan=int(sys.argv[i]) print ("Fan= %s" % (fan)) if i == 8: swing=int(sys.argv[i]) print ("Swing= %s" % (swing)) if i == 9: eco=parse(sys.argv[i]) print ("Eco= %s" % (eco)) if i == 10: turbo=parse(sys.argv[i]) print ("Turbo= %s" % (turbo)) if i == 11: ipsmaster=parse(sys.argv[i]) print ("IPSMaster= %s" % (ipsmaster)) c = midea_device(ipaddr, id) device = c.setup() # Refresh the object with the actual state by querying it device.refresh() #DirtyPatch für Fan, Mode und Swing-Mode #print ({"fan_speed unpatched:",device.fan_speed}) fanstring = str(device.fan_speed) if ("Auto" in fanstring): fan_speed_p=102; elif ("High" in fanstring): fan_speed_p=80; elif ("Medium" in fanstring): fan_speed_p=60; elif ("Low" in fanstring): fan_speed_p=40; elif ("Silent" in fanstring): fan_speed_p=20; else: print ("fan_speed=unbekannt"); print ("fan_speed gefunden:", fan_speed_p) #print ({"operational_mode unpatched:",device.operational_mode}) modestring = str(device.operational_mode) if ("auto" in modestring): op_mode_p=1; elif ("cool" in modestring): op_mode_p=2; elif ("dry" in modestring): op_mode_p=3; elif ("heat" in modestring): op_mode_p=4; elif ("fan_only" in modestring): op_mode_p=5; else: print ("OperationMode=unbekannt"); print ("OperationMode gefunden:", op_mode_p) #print ({"swing_mode unpatched:",device.swing_mode}) swingstring = str(device.swing_mode) if ("Off" in swingstring): swing_mode_p=0; elif ("Vertical" in swingstring): swing_mode_p=1; elif ("Horizontal" in swingstring): swing_mode_p=2; elif ("Both" in swingstring): swing_mode_p=3; else: print ("SwingMode=unbekannt"); print ("SwingMode gefunden:", swing_mode_p) print({ 'id': device.id, 'ipaddr': device.ip, 'power_state': device.power_state, 'prompt_tone': device.prompt_tone, 'target_temperature': device.target_temperature, #'operational_mode': device.operational_mode, 'operational_mode': op_mode_p, #'fan_speed': device.fan_speed, 'fan_speed': fan_speed_p, #'swing_mode': device.swing_mode, 'swing_mode': swing_mode_p, 'eco_mode': device.eco_mode, 'turbo_mode': device.turbo_mode, 'indoor_temperature': device.indoor_temperature, 'outdoor_temperature': device.outdoor_temperature }) #print('Anzahl der übergebenen Variablen: ', len(sys.argv), 'Variablen') #print('Inhalt der Variablen: ', str(sys.argv)) # Set the state of the device and #device.power_state = True #device.prompt_tone = False #device.target_temperature = 25 #device.operational_mode = ac.operational_mode_enum.cool changed = None if ipsmaster == True: if solltemp != device.target_temperature: print ("Solltemp ändern= %s" % (solltemp)) if (device.power_state == False and power == False): print ("Solltemp Änderung nicht sinnvoll da Klimagerät aus ist") elif device.power_state == False: print ("Schalte Klimagerät ein, setze neue Solltemp") device.power_state = True device.target_temperature = solltemp changed = True else: print ("Klimagerät ist schon ein, setze neue Solltemp") device.target_temperature = solltemp changed = True elif power != device.power_state: if power == True: print ("Schalte Klimagerät ein, behalte Solltemp bei") device.power_state = True changed = True else: print ("Schalte Klimagerät aus") device.power_state = False changed = True if fan != fan_speed_p: if fan == 102: print ("Fan auf Auto stellen") device.fan_speed = ac.fan_speed_enum.Auto changed = True if fan == 80: print ("Fan auf High stellen") device.fan_speed = ac.fan_speed_enum.High changed = True if fan == 60: print ("Fan auf Medium stellen") device.fan_speed = ac.fan_speed_enum.Medium changed = True if fan == 40: print ("Fan auf Low stellen") device.fan_speed = ac.fan_speed_enum.Low changed = True if fan == 20: print ("Fan auf Silent stellen") device.fan_speed = ac.fan_speed_enum.Silent changed = True if swing != swing_mode_p: if swing == 0: print ("Swing auf Off stellen") device.swing_mode = ac.swing_mode_enum.Off changed = True if swing == 1: print ("Swing auf Vertical stellen") device.swing_mode = ac.swing_mode_enum.Vertical changed = True if swing == 2: print ("Swing auf Horizontal stellen") device.swing_mode = ac.swing_mode_enum.Horizontal changed = True if swing == 3: print ("Swing auf Both stellen") device.swing_mode = ac.swing_mode_enum.Both changed = True if mod != op_mode_p: if mod == 1: print ("Mode auf Auto stellen") device.operational_mode = ac.operational_mode_enum.auto changed = True if mod == 2: print ("Mode auf Cool stellen") device.operational_mode = ac.operational_mode_enum.cool changed = True if mod == 3: print ("Mode auf Dry stellen") device.operational_mode = ac.operational_mode_enum.dry changed = True if mod == 4: print ("Mode auf Heath stellen") device.operational_mode = ac.operational_mode_enum.heat changed = True if mod == 5: print ("Mode auf fan_only stellen") device.operational_mode = ac.operational_mode_enum.fan_only changed = True if eco != device.eco_mode: if device.eco_mode == False: print ("Schalte Eco ein") device.eco_mode = True changed = True else: print ("Schalte Eco aus") device.eco_mode = False changed = True if turbo != device.turbo_mode: if device.turbo_mode == False: print ("Schalte Turbo ein") device.turbo_mode = True changed = True else: print ("Schalte Turbo aus") device.turbo_mode = False changed = True if ton != device.prompt_tone: if device.prompt_tone == False: print ("Schalte Ton ein") device.prompt_tone = True changed = True else: print ("Schalte Ton aus") #Funktion unnötig da nur kurzer Ton device.prompt_tone = False changed = True if changed == None: print ("Keine notwendigen Befehle erkannt") print ("Befehlsverarbeitung durchlaufen") else: print ("IPS Master nicht aktiv - keine Befehlsverarbeitung") # commit the changes with apply() #device.apply() if changed == True: device.apply() print ("Befehle gesandt - device.apply")