Beispiel #1
0
def setup(hass, config):
    """Establish connection to MAX! Cube."""
    from maxcube.connection import MaxCubeConnection
    from maxcube.cube import MaxCube

    # Read Config
    host = config.get(DOMAIN).get(CONF_HOST)
    port = config.get(DOMAIN).get(CONF_PORT)

    # Assign Cube Handle to global variable
    try:
        cube = MaxCube(MaxCubeConnection(host, port))
    except timeout:
        _LOGGER.error("Connection to Max!Cube could not be established")
        cube = None
        return False

    hass.data[MAXCUBE_HANDLE] = MaxCubeHandle(cube)

    # Load Climate (for Thermostats)
    load_platform(hass, 'climate', DOMAIN)

    # Load BinarySensor (for Window Shutter)
    load_platform(hass, 'binary_sensor', DOMAIN)

    # Initialization successfull
    return True
Beispiel #2
0
 def connect(self):
     if self.__max_cube_connection is None:
         try:
             self.__max_cube_connection = MaxCubeConnection(self.cube_ip_adress, 62910)
             self.logger.info('Connecting to Max!Cube')
         except Exception as e:
             self.logger.error('Problem opening connection')
Beispiel #3
0
def setup(hass, config):
    """Establish connection to MAX! Cube."""
    from maxcube.connection import MaxCubeConnection
    from maxcube.cube import MaxCube
    if DATA_KEY not in hass.data:
        hass.data[DATA_KEY] = {}

    connection_failed = 0
    gateways = config[DOMAIN][CONF_GATEWAYS]
    for gateway in gateways:
        host = gateway[CONF_HOST]
        port = gateway[CONF_PORT]

        try:
            cube = MaxCube(MaxCubeConnection(host, port))
            hass.data[DATA_KEY][host] = MaxCubeHandle(cube)
        except timeout as ex:
            _LOGGER.error("Unable to connect to Max!Cube gateway: %s", str(ex))
            hass.components.persistent_notification.create(
                'Error: {}<br />'
                'You will need to restart Home Assistant after fixing.'
                ''.format(ex),
                title=NOTIFICATION_TITLE,
                notification_id=NOTIFICATION_ID)
            connection_failed += 1

    if connection_failed >= len(gateways):
        return False

    load_platform(hass, 'climate', DOMAIN)
    load_platform(hass, 'binary_sensor', DOMAIN)

    return True
Beispiel #4
0
def setup(hass, config):
    """Establish connection to MAX! Cube."""

    if DATA_KEY not in hass.data:
        hass.data[DATA_KEY] = {}

    connection_failed = 0
    gateways = config[DOMAIN][CONF_GATEWAYS]
    for gateway in gateways:
        host = gateway[CONF_HOST]
        port = gateway[CONF_PORT]
        scan_interval = gateway[CONF_SCAN_INTERVAL].total_seconds()

        try:
            cube = MaxCube(MaxCubeConnection(host, port))
            hass.data[DATA_KEY][host] = MaxCubeHandle(cube, scan_interval)
        except timeout as ex:
            _LOGGER.error("Unable to connect to Max!Cube gateway: %s", str(ex))
            hass.components.persistent_notification.create(
                "Error: {}<br />"
                "You will need to restart Home Assistant after fixing."
                "".format(ex),
                title=NOTIFICATION_TITLE,
                notification_id=NOTIFICATION_ID,
            )
            connection_failed += 1

    if connection_failed >= len(gateways):
        return False

    load_platform(hass, "climate", DOMAIN, {}, config)
    load_platform(hass, "binary_sensor", DOMAIN, {}, config)

    return True
    def onStart(self):
        # Set heartbeat
        self.skipbeats=int(Parameters["Mode5"])/30
        self.beats=self.skipbeats
        Domoticz.Heartbeat(30)

        # Set debugging
        if Parameters["Mode6"]=="True": 
            Domoticz.Debugging(2)
            Domoticz.Debug("Debugging mode activated")

        # Read Cube for intialization of devices
        Domoticz.Debug("Reading e-Q3 MAX! devices from Cube...")
        try:
            cube = MaxCube(MaxCubeConnection(Parameters["Address"], int(Parameters["Port"])))
        except:
            Domoticz.Error("Error connecting to Cube. Other running MAX! programs may block the communication!")
            return
        
        # Check which rooms have a wall mounterd thermostat
        max_room = 0
        for room in cube.rooms:
            if room.id > max_room: max_room = room.id
        Domoticz.Debug("Number of rooms found: " + str((len(cube.rooms))) + " (highest number: " + str(max_room) + ")")
        self.RoomHasThermostat=[False] * (max_room+1)
        for EQ3device in cube.devices:
            if cube.is_wallthermostat(EQ3device):
                self.RoomHasThermostat[EQ3device.room_id] = True
                Domoticz.Debug("Room " + str(EQ3device.room_id) + " (" + cube.room_by_id(EQ3device.room_id).name + ") has a thermostat")

        # Create or delete devices if necessary
        for EQ3device in cube.devices:
            if cube.is_thermostat(EQ3device):
                self.CheckDevice(EQ3device.name, EQ3device.rf_address, "Valve")
                if not self.RoomHasThermostat[EQ3device.room_id]:
                    self.CheckDevice(EQ3device.name, EQ3device.rf_address, "Thermostat")
                    self.CheckDevice(EQ3device.name, EQ3device.rf_address, "Temperature")
                    self.CheckDevice(EQ3device.name, EQ3device.rf_address, "Mode")
            elif cube.is_wallthermostat(EQ3device):
                self.CheckDevice(EQ3device.name, EQ3device.rf_address, "Thermostat")
                self.CheckDevice(EQ3device.name, EQ3device.rf_address, "Temperature")
                self.CheckDevice(EQ3device.name, EQ3device.rf_address, "Mode")
            elif cube.is_windowshutter(EQ3device):
                self.CheckDevice(EQ3device.name, EQ3device.rf_address, "Contact")

        # Create or delete heat demand switch if necessary
        if Parameters["Mode3"] == "True" and 255 not in Devices:
            Domoticz.Device(Name="Heat demand", Unit=255, TypeName="Switch", Image=9, Used=1).Create()
            if 255 not in Devices:
                Domoticz.Error("Heat demand switch could not be created. Is 'Accept new Hardware Devices' enabled under Settings?")
            else:
                Domoticz.Log("Created device '" + Parameters["Name"] + " - Heat demand'") 
                Devices[255].Update(nValue=0, sValue="Off")
        elif Parameters["Mode3"] == "False" and 255 in Devices:
            Devices[255].Delete()
            Domoticz.Log("Deleted heat demand switch")
Beispiel #6
0
 def discover(self):
     try:
         self.cube = MaxCube(MaxCubeConnection(self.address, self.port))
     except socket.timeout:
         logging.error('Could not connect to MAX! cube when setting up the bridge. '
             'Make sure nothing else is connected to the MAX! cube at start up and '
             'try again.')
     for device in self.cube.devices:
         if device.type != MAX_THERMOSTAT:
             logging.info('Discovered non-thermostat')
             continue
         self.add_accessory(Thermostat(self.cube, device, self.driver))
    def onCommand(self, Unit, Command, Level, Hue):
        # Update commands for thermostats
        if Devices[Unit].Type == 242 and Devices[Unit].sValue != str(Level):
            Domoticz.Log("Setpoint changed for " + Devices[Unit].Name + ". New setpoint: " + str(Level))
            try:
                cube = MaxCube(MaxCubeConnection(Parameters["Address"], int(Parameters["Port"])))
            except:
                Domoticz.Error("Error connecting to Cube. Other running MAX! programs may block the communication!")
                return
            for EQ3device in cube.devices:
                if Devices[Unit].DeviceID == EQ3device.rf_address:
                    cube.set_target_temperature(EQ3device, Level)
                    Devices[Unit].Update(nValue=0, sValue=str(Level))
                    Devices[Unit].Refresh()

        # Update commands for mode switches
        if Devices[Unit].Type == 244 and Devices[Unit].SubType == 62 and Devices[Unit].sValue != str(Level):
            if Level == 00:
                mode = 0
                mode_text = "Auto"
            elif Level == 10:
                mode = 1
                mode_text = "Manual"
            elif Level == 20:
                mode = 2
                mode_text = "Vacation"
            elif Level == 30:
                mode = 3
                mode_text = "Boost"
            Domoticz.Log("Mode changed for " + Devices[Unit].Name + ". New mode: " + mode_text)
            try:
                cube = MaxCube(MaxCubeConnection(Parameters["Address"], int(Parameters["Port"])))
            except:
                Domoticz.Error("Error connecting to Cube. Other running MAX! programs may block the communication!")
                return
            for EQ3device in cube.devices:
                if Devices[Unit].DeviceID == EQ3device.rf_address:
                    cube.set_mode(EQ3device, mode)
                    Devices[Unit].Update(nValue=0, sValue=str(Level))
                    Devices[Unit].Refresh()
    def onHeartbeat(self):
        #Cancel the rest of this function if this heartbeat needs to be skipped
        if self.beats < self.skipbeats:
            Domoticz.Debug("Skipping heartbeat: " + str(self.beats))
            self.beats += 1
            return
        self.beats=1

        self.HeatDemand = 0

        # Read data from Cube
        Domoticz.Debug("Reading e-Q3 MAX! devices from Cube...")
        try:
            cube = MaxCube(MaxCubeConnection(Parameters["Address"], int(Parameters["Port"])))
        except:
            Domoticz.Error("Error connecting to Cube. Other running MAX! programs may block the communication!")
            return

        # Update devices in Domoticz
        for EQ3device in cube.devices:
            Domoticz.Debug("Checking device '" + EQ3device.name + "' in room " + str(EQ3device.room_id))
            if cube.is_thermostat(EQ3device):
                # Check if valve requires heat
                if EQ3device.valve_position > int(Parameters["Mode4"]): self.HeatDemand += 1
                # Update Domoticz devices for radiator valves
                self.UpdateDevice(EQ3device, "Valve")
                if not self.RoomHasThermostat[EQ3device.room_id]:
                    self.UpdateDevice(EQ3device, "Thermostat")
                    self.UpdateDevice(EQ3device, "Temperature")
                    self.UpdateDevice(EQ3device, "Mode")

            elif cube.is_wallthermostat(EQ3device):
                # Update Domoticz devices for wall thermostats
                self.UpdateDevice(EQ3device, "Thermostat")
                self.UpdateDevice(EQ3device, "Temperature")
                self.UpdateDevice(EQ3device, "Mode")

            elif cube.is_windowshutter(EQ3device):
                # Look up & update Domoticz device for contact switches
                self.UpdateDevice(EQ3device, "Contact")

        # Update heat demand switch if necessary
        Domoticz.Debug(str(self.HeatDemand) + " valves require heat")
        if self.HeatDemand > 0 and Parameters["Mode3"] == "True" and 255 in Devices and Devices[255].sValue == "Off":
            Devices[255].Update(nValue=1, sValue="On")
            Domoticz.Log("Heat demand switch turned on")
        elif self.HeatDemand == 0 and Parameters["Mode3"] == "True" and 255 in Devices and Devices[255].sValue == "On":
            Devices[255].Update(nValue=0, sValue="Off")
            Domoticz.Log("Heat demand switch turned off")
Beispiel #9
0
    def __init__(self, address, port):

        # connect to the cube
        self.cube = MaxCube(MaxCubeConnection(address, port))

        # setup the output mode on all the pins
        wiringpi.wiringPiSetup()
        wiringpi.pinMode(PIN1, 1)
        wiringpi.pinMode(PIN2, 1)
        wiringpi.pinMode(PIN3, 1)

        # pin_status dict contains the current status of the output pins
        # status 0 means that the pump is operating normally (turned on)
        # status 1 means that the pump is turned off (1 on the GPIO pin opens the relay)
        self.pin_status = {PIN1: 0, PIN2: 0, PIN3: 0}

        # map apartment IDs to the output pins
        self.pin_mapping = {"10": PIN1, "11": PIN2}
Beispiel #10
0
def setup(hass, config):
    """Establish connection to MAX! Cube."""
    from maxcube.connection import MaxCubeConnection
    from maxcube.cube import MaxCube

    host = config.get(DOMAIN).get(CONF_HOST)
    port = config.get(DOMAIN).get(CONF_PORT)

    try:
        cube = MaxCube(MaxCubeConnection(host, port))
    except timeout:
        _LOGGER.error("Connection to Max!Cube could not be established")
        cube = None
        return False

    hass.data[MAXCUBE_HANDLE] = MaxCubeHandle(cube)

    load_platform(hass, 'climate', DOMAIN)
    load_platform(hass, 'binary_sensor', DOMAIN)

    return True
Beispiel #11
0
def check_maxdevices(app):
    if not serverIP:
        return

    # only check every 15 minutes
    global minuteCounter
    minuteCounter = minuteCounter + 1
    if minuteCounter > 15:
        minuteCounter = 0
    if minuteCounter != 0:
        return

    try:
        cube = MaxCube(MaxCubeConnection(serverIP, 62910))
    except socket.timeout:
        print "MAX: Timeout..."
        return

    with app.app_context():
        for device in cube.devices:
            if device.linkStatusError != 0:
                statusOk = False
            else:
                statusOk = True

            record = Hosts.query.filter_by(fqdn=device.name).first()
            if record:  # update if MAX! device already exists
                record.status = statusOk
                record.last_checked = datetime.utcnow()
            else:  # otherwise create a new entry
                host = Hosts(fqdn=device.name,
                             friendly_name=None,
                             status=statusOk,
                             last_checked=datetime.utcnow(),
                             type='MAX',
                             idle_duration=60)
                db.session.add(host)
        db.session.commit()
Beispiel #12
0
        def Connect(self):

            if not cBaseInterFaceSettings.Connect(self):
                return False

            if self.aInterFaceIniSettings.uHost == '':
                return False

            try:
                if self.oDevice is None:
                    # self.oDevice = Cube(address=self.aInterFaceIniSettings.uHost, port=ToInt(self.aInterFaceIniSettings.uPort))
                    self.oDevice = MaxCube(
                        MaxCubeConnection(
                            host=self.aInterFaceIniSettings.uHost,
                            port=ToInt(self.aInterFaceIniSettings.uPort)))

                # self.oDevice.connect()
                self.oInterFace.oInterFaceConfig.WriteDefinitionConfigPar(
                    uSectionName=self.uSection,
                    uVarName=u'OldDiscoveredIP',
                    uVarValue=self.aInterFaceIniSettings.uHost)
                self.bIsConnected = True
                return self.bIsConnected
            except Exception as e:
                if hasattr(e, "errno"):
                    if e.errno == 10051:
                        self.bOnError = True
                        self.ShowWarning(u'Cannot connect (No Network):' +
                                         self.aInterFaceIniSettings.uHost +
                                         ':' +
                                         self.aInterFaceIniSettings.uPort)
                        return False
                self.ShowError(
                    u'Cannot connect:' + self.aInterFaceIniSettings.uHost +
                    ':' + self.aInterFaceIniSettings.uPort, e)
                self.bOnError = True
                return False
Beispiel #13
0
from maxcube.cube import MaxCube
from maxcube.connection import MaxCubeConnection

cube = MaxCube(MaxCubeConnection('192.168.0.20', 62910))

for device in cube.devices:
    print(device.name)
    print(device.actual_temperature)
    print(device.target_temperature)

    cube.set_target_temperature(device, 18)


class MaxcubeMQTT:
Beispiel #14
0
import argparse
import sys

from maxcube.connection import MaxCubeConnection
from maxcube.cube import MaxCube

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description='Set or dump thermostat programmes')
    parser.add_argument('--host', required=True)
    parser.add_argument('--port', required=True, type=int)
    parser.add_argument('cmd', choices=['load', 'dump'])
    args = parser.parse_args()
    cube = MaxCube(MaxCubeConnection(args.host, args.port))
    if args.cmd == 'load':
        cube.set_programmes_from_config(sys.stdin)
    elif args.cmd == 'dump':
        print(cube.devices_as_json())
Beispiel #15
0
        print(i['Name'] + " has a idx " + i['idx'])
        domoticz_props[i['Name']] = [i['idx'], i['LastUpdate'], i['Data']]

#searching for -Sens
url = "http://" + DOMOTICZ_IP + ":" + DOMOTICZ_PORT + "/json.htm?type=devices&filter=temp&used=true&order=Name"

response = urllib.urlopen(url)

data = json.loads(response.read())

for i in data['result']:
    if i['Name'][-5:] == "-Sens":
        #print (i['Name'] + " has a idx " + i['idx'] + " last updated " + i['LastUpdate'])
        domoticz_props[i['Name']] = [i['idx'], i['LastUpdate'], i['Data']]

cube = MaxCube(MaxCubeConnection(IP_CUBE, PORT_CUBE))

for device in cube.devices:
    if device.type != MAX_THERMOSTAT:
        print("Not a thermostat ommiting this device")
    else:
        print("Updating Termostat: " + device.name + 'Read valve open: ' +
              str(device.valve_position) + ' Read temperature: ' +
              str(device.actual_temperature))
        #updating domoticz with the read value
        search_name = device.name[0:-5].encode('ascii', 'ignore')
        url = "http://" + DOMOTICZ_IP + ":" + DOMOTICZ_PORT + "/json.htm?type=command&param=udevice&idx=" + domoticz_props[
            search_name + '-Rad'][0] + "&nvalue=0&svalue=" + str(
                device.valve_position)
        response = urllib.urlopen(url)
        if str(device.actual_temperature) != "None":
Beispiel #16
0
#!/usr/bin/python
from maxcube.cube import MaxCube
from maxcube.connection import MaxCubeConnection
from maxcube.device import \
    MAX_THERMOSTAT, \
    MAX_THERMOSTAT_PLUS, \
    MAX_WINDOW_SHUTTER, \
    MAX_WALL_THERMOSTAT, \
    MAX_DEVICE_MODE_AUTOMATIC, \
    MAX_DEVICE_MODE_MANUAL, \
    MAX_DEVICE_MODE_VACATION, \
    MAX_DEVICE_MODE_BOOST
import logging

cube = MaxCube(MaxCubeConnection('192.168.XXX.XXX', 62910))

for room in cube.rooms:
    print("Room: " + room.name)
    for device in cube.devices_by_room(room):
        print("Device: " + device.name)

print("")

for device in cube.devices:
    if device.type == MAX_THERMOSTAT:
        type = "MAX_THERMOSTAT"
    elif device.type == MAX_THERMOSTAT_PLUS:
        type = "MAX_THERMOSTAT_PLUS"
    elif device.type == MAX_WINDOW_SHUTTER:
        type = "MAX_WINDOW_SHUTTER"
    elif device.type == MAX_WALL_THERMOSTAT:
Beispiel #17
0
    def __init__(self, address, port):

        # connect to the cube
        self.cube = MaxCube(MaxCubeConnection(address, port))