Python plugin: Daikin BRP069A42 WiFi adapter

Python and python framework
videodrome
Posts: 59
Joined: Wednesday 11 May 2016 16:11
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Daikin BRP069A42 WiFi adapter

Post by videodrome » Friday 22 December 2017 16:39

Anyone could help me?

Inviato dal mio HUAWEI CRR-L09 utilizzando Tapatalk


spiderjn
Posts: 20
Joined: Wednesday 27 December 2017 14:37
Target OS: Raspberry Pi
Domoticz version: 3.8834
Contact:

Re: Python plugin: Daikin BRP069A42 WiFi adapter

Post by spiderjn » Wednesday 27 December 2017 15:27

hi,

first thank's for this good job.

it is a very interesting plugin for my installation, I tried to install it on my raspberry and unfortunately as soon as I configure a new hardware, it crashes Domoticz and I must go remove the python file in plugin folder.

i search any information on how investigate this point without success.

Any help for start this configuration or how to test this plugin outside of domoticz ?

i've installed domoticz beta.

Best regards

spiderjn
Posts: 20
Joined: Wednesday 27 December 2017 14:37
Target OS: Raspberry Pi
Domoticz version: 3.8834
Contact:

Re: Python plugin: Daikin BRP069A42 WiFi adapter

Post by spiderjn » Sunday 07 January 2018 12:18

hi all

finally i prefer update hardware plugin.

See : https://www.domoticz.com/forum/viewtopi ... 34&t=21126

best regards

leejoow
Posts: 12
Joined: Saturday 05 November 2016 18:30
Target OS: Linux
Domoticz version:
Contact:

Re: Python plugin: Daikin BRP069A42 WiFi adapter

Post by leejoow » Friday 06 July 2018 19:41

Updated the git plugin to work with new Domoticz version. Stability seems to be improved after removing some imports.

Prutsium
Posts: 70
Joined: Monday 18 June 2018 11:31
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Germany / Netherlands
Contact:

Re: Python plugin: Daikin BRP069A42 WiFi adapter

Post by Prutsium » Saturday 07 July 2018 10:38

Just installed it and works great. Added the first Aircon (1 of 3) and no issues with setup.

Prutsium
Posts: 70
Joined: Monday 18 June 2018 11:31
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Germany / Netherlands
Contact:

Re: Python plugin: Daikin BRP069A42 WiFi adapter

Post by Prutsium » Wednesday 18 July 2018 8:43

Prutsium wrote:
Saturday 07 July 2018 10:38
Just installed it and works great. Added the first Aircon (1 of 3) and no issues with setup.
Seems some settings always revert back to some previous settings for example i set Airco to FAN but jumps back to cool after a minute.
Whats wrong here ?

Prutsium
Posts: 70
Joined: Monday 18 June 2018 11:31
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Germany / Netherlands
Contact:

Re: Python plugin: Daikin BRP069A42 WiFi adapter

Post by Prutsium » Wednesday 18 July 2018 9:44

Seems with the new firmware of the Wifi adapter some commands are not accepted anymore.

Below i try to switch to FAN mode got the following result:

Code: Select all

2018-07-18 10:39:22.576  (Airco - Living) Processing 'ReadEvent' message
2018-07-18 10:39:22.576  (Airco - Living) Received 84 bytes of data
2018-07-18 10:39:22.576  (Airco - Living)     48 54 54 50 2f 31 2e 30 20 32 30 30 20 4f 4b 0d 0a 43 6f 6e     HTTP/1.0.200.OK..Con
2018-07-18 10:39:22.576  (Airco - Living)     74 65 6e 74 2d 4c 65 6e 67 74 68 3a 20 31 39 0d 0a 43 6f 6e     tent-Length:.19..Con
2018-07-18 10:39:22.576  (Airco - Living)     74 65 6e 74 2d 54 79 70 65 3a 20 74 65 78 74 2f 70 6c 61 69     tent-Type:.text/plai
2018-07-18 10:39:22.576  (Airco - Living)     6e 0d 0a 0d 0a 72 65 74 3d 50 41 52 41 4d 20 4e 47 2c 61 64     n....ret=PARAM.NG,ad
2018-07-18 10:39:22.576  (Airco - Living)     76 3d 31 33 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..     v=13
2018-07-18 10:39:22.576  (Airco - Living) Pushing 'onMessageCallback' on to queue
2018-07-18 10:39:22.576  (Airco - Living) Processing 'DisconnectedEvent' message
2018-07-18 10:39:22.576  (Airco - Living) Disconnect event received for '192.168.199.106:80'.
2018-07-18 10:39:22.577  (Airco - Living) Pushing 'onDisconnectCallback' on to queue
2018-07-18 10:39:22.577  (Airco - Living) Processing 'onMessageCallback' message
2018-07-18 10:39:22.577  (Airco - Living) Calling message handler 'onMessage'.
2018-07-18 10:39:22.577  (Airco - Living) onMessage called
2018-07-18 10:39:22.577  (Airco - Living) Received data from connection Set Control: ret=PARAM NG,adv=13


Prutsium
Posts: 70
Joined: Monday 18 June 2018 11:31
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Germany / Netherlands
Contact:

Re: Python plugin: Daikin BRP069A42 WiFi adapter

Post by Prutsium » Wednesday 18 July 2018 12:45

Prutsium wrote:
Wednesday 18 July 2018 9:44
Seems with the new firmware of the Wifi adapter some commands are not accepted anymore.

Below i try to switch to FAN mode got the following result:

Code: Select all

2018-07-18 10:39:22.576  (Airco - Living) Processing 'ReadEvent' message
2018-07-18 10:39:22.576  (Airco - Living) Received 84 bytes of data
2018-07-18 10:39:22.576  (Airco - Living)     48 54 54 50 2f 31 2e 30 20 32 30 30 20 4f 4b 0d 0a 43 6f 6e     HTTP/1.0.200.OK..Con
2018-07-18 10:39:22.576  (Airco - Living)     74 65 6e 74 2d 4c 65 6e 67 74 68 3a 20 31 39 0d 0a 43 6f 6e     tent-Length:.19..Con
2018-07-18 10:39:22.576  (Airco - Living)     74 65 6e 74 2d 54 79 70 65 3a 20 74 65 78 74 2f 70 6c 61 69     tent-Type:.text/plai
2018-07-18 10:39:22.576  (Airco - Living)     6e 0d 0a 0d 0a 72 65 74 3d 50 41 52 41 4d 20 4e 47 2c 61 64     n....ret=PARAM.NG,ad
2018-07-18 10:39:22.576  (Airco - Living)     76 3d 31 33 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..     v=13
2018-07-18 10:39:22.576  (Airco - Living) Pushing 'onMessageCallback' on to queue
2018-07-18 10:39:22.576  (Airco - Living) Processing 'DisconnectedEvent' message
2018-07-18 10:39:22.576  (Airco - Living) Disconnect event received for '192.168.199.106:80'.
2018-07-18 10:39:22.577  (Airco - Living) Pushing 'onDisconnectCallback' on to queue
2018-07-18 10:39:22.577  (Airco - Living) Processing 'onMessageCallback' message
2018-07-18 10:39:22.577  (Airco - Living) Calling message handler 'onMessage'.
2018-07-18 10:39:22.577  (Airco - Living) onMessage called
2018-07-18 10:39:22.577  (Airco - Living) Received data from connection Set Control: ret=PARAM NG,adv=13

After digging in your Python script i found the whole FAN mode missing.

After adding:

Code: Select all

           elif (mode == "6"):
                sValueNew = "40" #Fan
and

Code: Select all

        elif (Devices[4].sValue == "40"):
            requestUrl = requestUrl + "6"
The Fan mode works again seems you missed this somehow.
(Ps me proud of myself never worked with Python but just looked at the logic and noticed something missing :))

Prutsium
Posts: 70
Joined: Monday 18 June 2018 11:31
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Germany / Netherlands
Contact:

Re: Python plugin: Daikin BRP069A42 WiFi adapter

Post by Prutsium » Tuesday 24 July 2018 14:48

I noticed that also the calculation of the FAN levels did not work perfectly as often a setting above L3 reverted back to Auto.
So added all the fan levels manually and now it also works normal again.

Still figuring out how to implement the Wind Direction got some ideas but as the f_dir is also a mandatory command in the string i fixed it now on 3 (hor / ver)

Code: Select all

# Basic Python Plugin Example
#
# Author: GizMoCuz
#
"""
<plugin key="BRP069A42" name="Daikin Airconditioning (BRP069A42)" author="leejoow" version="1.1.0" externallink="https://www.daikin.nl/nl_nl/products/BRP069A42.html">
    <params>
        <param field="Address" label="IP Address" width="200px" required="true" default=""/>
        <param field="Port" label="Port" width="30px" required="true" default="80"/>
        <param field="Mode1" label="Update every x seconds" width="75px">
            <options>
                <option label="30" value="3" />
                <option label="60" value="6" default="true" />
                <option label="90" value="9" />
                <option label="120" value="12" />
                <option label="150" value="15" />
                <option label="180" value="18" />
                <option label="210" value="21" />
                <option label="240" value="24" />
            </options>
        </param>
        <param field="Mode2" label="Debug" width="75px">
            <options>
                <option label="True" value="Debug"/>
                <option label="False" value="Normal"  default="true" />
            </options>
        </param>
        
    </params>
</plugin>
"""
import Domoticz
from datetime import datetime 

class BasePlugin:
    enabled = True
    powerOn = 0
    runCounter = 0
    httpConnSensorInfo = None
    httpConnControlInfo = None
    httpConnSetControl = None

    def __init__(self):
        #self.var = 123
        return

    def onStart(self):
        Domoticz.Log("onStart called")

        if Parameters["Mode2"] == "Debug":
            Domoticz.Debugging(1)
            
        if (len(Devices) == 0):
            Domoticz.Device(Name="Power", Unit=1, Image=16, TypeName="Switch", Used=1).Create()
            Domoticz.Device(Name="Temp IN", Unit=2, TypeName="Temperature", Used=1).Create()
            Domoticz.Device(Name="Temp OUT", Unit=3, TypeName="Temperature",Used=1).Create()

            Options = {"LevelActions" : "|||||",
                       "LevelNames" : "|Auto|Cool|Heat|Fan|Dry",
                       "LevelOffHidden" : "true",
                       "SelectorStyle" : "1"}
            
            Domoticz.Device(Name="Mode", Unit=4, TypeName="Selector Switch", Image=16, Options=Options, Used=1).Create()
            
            Options = {"LevelActions" : "|||||||",
                       "LevelNames" : "|Auto|Silent|L1|L2|L3|L4|L5",
                       "LevelOffHidden" : "true",
                       "SelectorStyle" : "1"}
            
            Domoticz.Device(Name="Fan Rate", Unit=5, TypeName="Selector Switch", Image=7, Options=Options, Used=1).Create()
            Domoticz.Device(Name="Temp TARGET", Unit=6, Type=242, Subtype=1, Image=16, Used=1).Create()
            
            Domoticz.Log("Device created.")
        
        DumpConfigToLog()
        
        Domoticz.Heartbeat(10)
        
        self.httpConnSensorInfo = Domoticz.Connection(Name="Sensor Info", Transport="TCP/IP", Protocol="HTTP", Address=Parameters["Address"], Port=Parameters["Port"])
        self.httpConnSensorInfo.Connect()    

        self.httpConnControlInfo = Domoticz.Connection(Name="Control Info", Transport="TCP/IP", Protocol="HTTP", Address=Parameters["Address"], Port=Parameters["Port"])
        self.httpConnControlInfo.Connect() 
        
        self.httpConnSetControl = Domoticz.Connection(Name="Set Control", Transport="TCP/IP", Protocol="HTTP", Address=Parameters["Address"], Port=Parameters["Port"])

        self.runCounter = int(Parameters["Mode1"])
    def onStop(self):
        Domoticz.Log("onStop called")

    def onConnect(self, Connection, Status, Description):
        if (Status == 0):
            Domoticz.Debug("Connection successful")
            
            data = ''
            headers = { 'Content-Type': 'text/xml; charset=utf-8', \
                        'Connection': 'keep-alive', \
                        'Accept': 'Content-Type: text/html; charset=UTF-8', \
                        'Host': Parameters["Address"]+":"+Parameters["Port"], \
                        'User-Agent':'Domoticz/1.0', \
                        'Content-Length' : "%d"%(len(data)) }

            if (Connection == self.httpConnSensorInfo):
                Domoticz.Debug("Sensor connection created")
                requestUrl = "/aircon/get_sensor_info"
            elif (Connection == self.httpConnControlInfo):
                Domoticz.Debug("Control connection created")
                requestUrl = "/aircon/get_control_info"
            elif (Connection == self.httpConnSetControl):
                Domoticz.Debug("Set connection created")
                requestUrl = self.buildCommandString()
                
            Connection.Send({"Verb":"GET", "URL":requestUrl, "Headers": headers})
        else:
            Domoticz.Debug("Connection failed")

    def onMessage(self, Connection, Data):
        Domoticz.Log("onMessage called")
        
        dataDecoded = Data["Data"].decode("utf-8", "ignore")
            
        Domoticz.Debug("Received data from connection " + Connection.Name + ": " + dataDecoded)
        
        if (Connection == self.httpConnControlInfo):       
            position = dataDecoded.find("pow=")
            power = dataDecoded[position + 4 : position + 5]
            
            position = dataDecoded.find("mode=")
            mode = dataDecoded[position + 5 : position + 6]
            
            position = dataDecoded.find("f_rate=")
            f_rate = dataDecoded[position + 7 : position + 8]
            
            position = dataDecoded.find("stemp=")
            stemp = dataDecoded[position + 6 : position + 8]
            
            Domoticz.Debug("Power: " + power + "; Mode: " + mode + "; FanRate: " + f_rate + "; Target temperature: " + stemp)
            
            self.powerOn = int(power)     
            
            # Power
            if (power == "0"):
                if (Devices[1].nValue != 0):
                    Devices[1].Update(nValue = 0, sValue ="0") 
            else: 
                if (Devices[1].nValue != 1):
                    Devices[1].Update(nValue = 1, sValue ="100") 
             
            # Mode
            if (mode == "0"):
                sValueNew = "10" #Auto
            elif (mode == "2"):
                sValueNew = "50" #Dry
            elif (mode == "3"):
                sValueNew = "20" #Cool
            elif (mode == "4"):
                sValueNew = "30" #Warm
            elif (mode == "6"):
                sValueNew = "40" #Fan
         
            if (Devices[4].nValue != self.powerOn or Devices[4].sValue != sValueNew):
                Devices[4].Update(nValue = self.powerOn, sValue = sValueNew)
         
            # Fan rate
            if (f_rate == "A"):
                sValueNew = "10" # Auto
            elif (f_rate == "B"):
                sValueNew = "20" # Silent
#Manual f_rate
            elif (f_rate == "3"):
                sValueNew = "30" # L1
            elif (f_rate == "4"):
                sValueNew = "40" # L2
            elif (f_rate == "5"):
                sValueNew = "50" # L3
            elif (f_rate == "6"):
                sValueNew = "60" # L4
            elif (f_rate == "7"):
                sValueNew = "70" # L5

#            else:
#                sValueNew = str(int(f_rate) * 10)
                           
            if (Devices[5].nValue != self.powerOn or Devices[5].sValue != sValueNew):
                Devices[5].Update(nValue = self.powerOn, sValue = sValueNew)

            #lastUpdate = datetime.strptime(Devices[6].LastUpdate, "%Y-%m-%d %H:%M:%S")
            #delta = datetime.now() - lastUpdate
                
            # Setpoint temperature, update once per 30 minutes if no changes
            #if (Devices[6].nValue != self.powerOn or Devices[6].sValue != stemp or delta.total_seconds() > 1800):
            #    Devices[6].Update(nValue = self.powerOn, sValue = stemp)
        
        elif (Connection == self.httpConnSensorInfo):        
            position = dataDecoded.find("htemp=")
            htemp = dataDecoded[position + 6 : position + 10]
                        
            position = dataDecoded.find("otemp=")
            otemp = dataDecoded[position + 6 : position + 10]
            
            Domoticz.Debug("Internal temperature: " + htemp + "; Outside temperature: " + otemp)
            
            Devices[2].Update(nValue = 0, sValue = htemp)
            Devices[3].Update(nValue = 0, sValue = otemp)
        
        #Force disconnect, in case the Daikin unit doesn't disconnect
        if (Connection.Connected()):
            Domoticz.Debug("Close connection")
            Connection.Disconnect()

    def onCommand(self, Unit, Command, Level, Hue):
        Domoticz.Debug("Command received U="+str(Unit)+" C="+str(Command)+" L= "+str(Level)+" H= "+str(Hue))
        
        if (Unit == 1):
            if(Command == "On"):
                self.powerOn = 1
                Devices[1].Update(nValue = 1, sValue ="100") 
            else:
                self.powerOn = 0
                Devices[1].Update(nValue = 0, sValue ="0") 
            
            #Update state of all other devices
            Devices[4].Update(nValue = self.powerOn, sValue = Devices[4].sValue)
            Devices[5].Update(nValue = self.powerOn, sValue = Devices[5].sValue)
            Devices[6].Update(nValue = self.powerOn, sValue = Devices[6].sValue)
        
        if (Unit == 4):
            Devices[4].Update(nValue = self.powerOn, sValue = str(Level))
            
        if (Unit == 5):
            Devices[5].Update(nValue = self.powerOn, sValue = str(Level))
        
        if (Unit == 6):
            Devices[6].Update(nValue = self.powerOn, sValue = str(Level))
            
        self.httpConnSetControl.Connect()
        
    def onNotification(self, Name, Subject, Text, Status, Priority, Sound, ImageFile):
        Domoticz.Log("Notification: " + Name + "," + Subject + "," + Text + "," + Status + "," + str(Priority) + "," + Sound + "," + ImageFile)

    def onDisconnect(self, Connection):
        Domoticz.Debug("Connection " + Connection.Name + " closed.")

    def onHeartbeat(self):
        self.runCounter = self.runCounter - 1
        if self.runCounter <= 0:
            Domoticz.Debug("Poll unit")
            self.runCounter = int(Parameters["Mode1"])
            
            if (self.httpConnSensorInfo.Connected() == False):
                self.httpConnSensorInfo.Connect()
            
            if (self.httpConnControlInfo.Connected() == False):
                self.httpConnControlInfo.Connect()
            
        else:
            Domoticz.Debug("Polling unit in " + str(self.runCounter) + " heartbeats.")

    def buildCommandString(self):
        #Minimal string: pow=1&mode=1&stemp=26&shum=0&f_rate=B&f_dir=3
        
        requestUrl = "/aircon/set_control_info?shum=0&f_dir=3&pow="
    
        if (self.powerOn):
            requestUrl = requestUrl + "1"
        else:
            requestUrl = requestUrl + "0"
        
        requestUrl = requestUrl + "&mode="
        
        if (Devices[4].sValue == "10"):
            requestUrl = requestUrl + "0"
        elif (Devices[4].sValue == "20"):
            requestUrl = requestUrl + "3"
        elif (Devices[4].sValue == "30"):
            requestUrl = requestUrl + "4"
        elif (Devices[4].sValue == "40"):
            requestUrl = requestUrl + "6"
        elif (Devices[4].sValue == "50"):
            requestUrl = requestUrl + "2"
                
        requestUrl = requestUrl + "&f_rate="
        
        if (Devices[5].sValue == "10"):
            requestUrl = requestUrl + "A"
        elif (Devices[5].sValue == "20"):
            requestUrl = requestUrl + "B"
        elif (Devices[5].sValue == "30"):
            requestUrl = requestUrl + "3"
        elif (Devices[5].sValue == "40"):
            requestUrl = requestUrl + "4"
        elif (Devices[5].sValue == "50"):
            requestUrl = requestUrl + "5"
        elif (Devices[5].sValue == "60"):
            requestUrl = requestUrl + "6"
        elif (Devices[5].sValue == "70"):
            requestUrl = requestUrl + "7"
		
			#        else:
#            requestUrl = requestUrl + str(int(int(Devices[5].sValue) / 10))
    
        requestUrl = requestUrl + "&stemp=" + Devices[6].sValue
    
        return requestUrl
            
global _plugin
_plugin = BasePlugin()

def onStart():
    global _plugin
    _plugin.onStart()

def onStop():
    global _plugin
    _plugin.onStop()

def onConnect(Connection, Status, Description):
    global _plugin
    _plugin.onConnect(Connection, Status, Description)

def onMessage(Connection, Data):
    global _plugin
    _plugin.onMessage(Connection, Data)

def onCommand(Unit, Command, Level, Hue):
    global _plugin
    _plugin.onCommand(Unit, Command, Level, Hue)

def onNotification(Name, Subject, Text, Status, Priority, Sound, ImageFile):
    global _plugin
    _plugin.onNotification(Name, Subject, Text, Status, Priority, Sound, ImageFile)

def onDisconnect(Connection):
    global _plugin
    _plugin.onDisconnect(Connection)

def onHeartbeat():
    global _plugin
    _plugin.onHeartbeat()

    # Generic helper functions
def DumpConfigToLog():
    for x in Parameters:
        if Parameters[x] != "":
            Domoticz.Debug( "'" + x + "':'" + str(Parameters[x]) + "'")
    Domoticz.Debug("Device count: " + str(len(Devices)))
    for x in Devices:
        Domoticz.Debug("Device:           " + str(x) + " - " + str(Devices[x]))
        Domoticz.Debug("Device ID:       '" + str(Devices[x].ID) + "'")
        Domoticz.Debug("Device Name:     '" + Devices[x].Name + "'")
        Domoticz.Debug("Device nValue:    " + str(Devices[x].nValue))
        Domoticz.Debug("Device sValue:   '" + Devices[x].sValue + "'")
        Domoticz.Debug("Device LastLevel: " + str(Devices[x].LastLevel))
    return


Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest