def main():
    """ main function """
    conf = ConfigParser.ConfigParser()
    conf.read('tradfri.cfg')

    hubip = conf.get('tradfri', 'hubip')
    securityid = conf.get('tradfri', 'securityid')

    lightbulb = []
    lightgroup = []

    print('[ ] tradfri: requireing all tradfri devices, please wait ...')
    devices = tradfriStatus.tradfri_get_devices(hubip, securityid)
    groups = tradfriStatus.tradfri_get_groups(hubip, securityid)

    for deviceid in tqdm(range(len(devices)), desc='tradfri lightbulbs', unit=' lightbulb'):
        lightbulb.append(tradfriStatus.tradfri_get_lightbulb(hubip, securityid,
                                                             str(devices[deviceid])))

    # sometimes the request are to fast, the will decline the request (flood security)
    # in this case you could increse the sleep timer
    time.sleep(.5)

    for groupid in tqdm(range(len(groups)), desc='tradfri groups', unit=' group'):
        lightgroup.append(tradfriStatus.tradfri_get_group(hubip, securityid,
                                                          str(groups[groupid])))

    print('[+] tradfri: device information gathered')
    print('===========================================================\n')

    for _ in range(len(lightbulb)):
        try:
            if lightbulb[_]["3311"][0]["5850"] == 0:
                print('bulbid {}, name: {}, bightness: {}, state: off'
                      .format(lightbulb[_]["9003"], lightbulb[_]["9001"],
                              lightbulb[_]["3311"][0]["5851"]))
            else:
                print('bulbid {}, name: {}, bightness: {}, state: on'
                      .format(lightbulb[_]["9003"], lightbulb[_]["9001"],
                              lightbulb[_]["3311"][0]["5851"]))
        except KeyError:
            # device is not a lightbulb but a remote control, dimmer or sensor
            pass

    print('\n')

    for _ in range(len(lightgroup)):
        if lightgroup[_]["5850"] == 0:
            print('groupid: {}, name: {}, state: off'
                  .format(lightgroup[_]["9003"], lightgroup[_]["9001"]))
        else:
            print('groupid: {}, name: {}, state: on'
                  .format(lightgroup[_]["9003"], lightgroup[_]["9001"]))
Beispiel #2
0
def main():
    """ main function """
    conf = ConfigParser.ConfigParser()
    conf.read('tradfri.cfg')

    hubip = conf.get('tradfri', 'hubip')
    securityid = conf.get('tradfri', 'securityid')

    lightbulb = []
    lightgroup = []

    print('[ ] Tradfri: acquiring all Tradfri devices, please wait ...')
    devices = tradfriStatus.tradfri_get_devices(hubip, securityid)
    groups = tradfriStatus.tradfri_get_groups(hubip, securityid)

    for deviceid in tqdm(range(len(devices)), desc='Tradfri lightbulbs', unit=' lightbulb'):
        lightbulb.append(tradfriStatus.tradfri_get_lightbulb(hubip, securityid,
                                                             str(devices[deviceid])))

    # sometimes the request are to fast, the will decline the request (flood security)
    # in this case you could increse the sleep timer
    time.sleep(.5)

    for groupid in tqdm(range(len(groups)), desc='Tradfri groups', unit=' group'):
        lightgroup.append(tradfriStatus.tradfri_get_group(hubip, securityid,
                                                          str(groups[groupid])))

    print('[+] Tradfri: device information gathered')
    print('===========================================================\n')

    for _ in range(len(lightbulb)):
        try:
            if lightbulb[_]["3311"][0]["5850"] == 0:
                print('bulb ID {}, name: {}, brightness: {}, state: off'
                      .format(lightbulb[_]["9003"], lightbulb[_]["9001"],
                              lightbulb[_]["3311"][0]["5851"]))
            else:
                print('bulb ID {}, name: {}, brightness: {}, state: on'
                      .format(lightbulb[_]["9003"], lightbulb[_]["9001"],
                              lightbulb[_]["3311"][0]["5851"]))
        except KeyError:
            # device is not a lightbulb but a remote control, dimmer or sensor
            pass

    print('\n')

    for _ in range(len(lightgroup)):
        if lightgroup[_]["5850"] == 0:
            print('group ID: {}, name: {}, state: off'
                  .format(lightgroup[_]["9003"], lightgroup[_]["9001"]))
        else:
            print('group ID: {}, name: {}, state: on'
                  .format(lightgroup[_]["9003"], lightgroup[_]["9001"]))
def main():
    """ main function """
    conf = configparser.ConfigParser()
    script_dir = os.path.dirname(os.path.realpath(__file__))
    conf.read(script_dir + '/tradfri.cfg')

    hubip = conf.get('tradfri', 'hubip')
    apiuser = conf.get('tradfri', 'apiuser')
    apikey = conf.get('tradfri', 'apikey')

    print('devices:')
    for deviceid in tradfriStatus.tradfri_get_devices(hubip, apiuser, apikey):
        time.sleep(0.5)
        device = tradfriStatus.tradfri_get_device(hubip, apiuser, apikey,
                                                  deviceid)
        id = device["9003"]
        name = device["9001"]

        if "3311" in device:
            bulb = device["3311"][0]
            brightness = bulb["5851"]
            state = bulb["5850"]
            state = {0: 'off', 1: 'on'}[state]
            if "5711" in bulb:
                warmth = float(bulb["5711"])
                warmth = round(
                    (warmth - 250) / (454 - 250) * 100,
                    1)  # reported as a percentage (100% maximum warmth)
            else:
                warmth = "N/A"
            print(
                'ID: {0:<5}, name: {1: <35}, brightness: {2: <3}, warmth: {3: >5}%, state: {4}'
                .format(id, name, brightness, warmth, state))
        else:
            print('ID: {0:<5}, name: {1: <35}'.format(id, name))
    print('\n')

    print('groups:')
    for groupid in tradfriStatus.tradfri_get_groups(hubip, apiuser, apikey):
        time.sleep(0.5)
        group = tradfriStatus.tradfri_get_group(hubip, apiuser, apikey,
                                                groupid)
        id = group["9003"]
        name = group["9001"]
        state = group["5850"]
        state = {0: 'off', 1: 'on'}[state]
        print('ID: {0:<5}, name: {1: <16}, state: {2}'.format(id, name, state))
    print('\n')
def main():
    """ main function """
    conf = ConfigParser.ConfigParser()
    script_dir = os.path.dirname(os.path.realpath(__file__))
    conf.read(script_dir + '/tradfri.cfg')

    hubip = conf.get('tradfri', 'hubip')
    apiuser = conf.get('tradfri', 'apiuser')
    apikey = conf.get('tradfri', 'apikey')

    lightbulb = []
    lightgroup = []

    print('[ ] Tradfri: acquiring all Tradfri devices, please wait ...')
    devices = tradfriStatus.tradfri_get_devices(hubip, apiuser, apikey)
    groups = tradfriStatus.tradfri_get_groups(hubip, apiuser, apikey)

    for deviceid in tqdm(range(len(devices)), desc='Tradfri devices', unit=' devices'):
        lightbulb.append(tradfriStatus.tradfri_get_lightbulb(hubip, apiuser, apikey,
                                                             str(devices[deviceid])))

    # sometimes the request are to fast, the will decline the request (flood security)
    # in this case you could increse the sleep timer
    time.sleep(.5)

    for groupid in tqdm(range(len(groups)), desc='Tradfri groups', unit=' group'):
        lightgroup.append(tradfriStatus.tradfri_get_group(hubip, apiuser, apikey,
                                                          str(groups[groupid])))

    print('[+] Tradfri: device information gathered')
    print('===========================================================\n')
    for _ in range(len(lightbulb)):
        try:
            brightness = lightbulb[_]["3311"][0]["5851"]
            try:
                warmth     = float(lightbulb[_]["3311"][0]["5711"])
                warmth     = round((warmth-250)/(454-250)*100,1)# reported as a percentage (100% maximum warmth)
            except KeyError:
                warmth = "NAN"

            if lightbulb[_]["3311"][0]["5850"] == 0:
                print('bulb ID {0:<5}, name: {1: <35}, brightness: {2: <3}, warmth: {3: >5}%, state: off'
                      .format(lightbulb[_]["9003"], lightbulb[_]["9001"],
                              brightness,warmth))
            else:
                print('bulb ID {0:<5}, name: {1: <35}, brightness: {2: <3}, warmth: {3: >5}%, state: on'
                      .format(lightbulb[_]["9003"], lightbulb[_]["9001"],
                              brightness,warmth))
        except KeyError:
            # device is not a lightbulb but a remote control, dimmer or sensor
            pass

    print('\n')

    for _ in range(len(lightgroup)):
        if lightgroup[_]["5850"] == 0:
            print('group ID: {0:<5}, name: {1: <16}, state: off'
                  .format(lightgroup[_]["9003"], lightgroup[_]["9001"]))
        else:
            print('group ID: {0:<5}, name: {1: <16}, state: on'
                  .format(lightgroup[_]["9003"], lightgroup[_]["9001"]))
Beispiel #5
0
from tradfri import tradfriStatus
from tqdm import tqdm

conf = ConfigParser.ConfigParser()
script_dir = os.path.dirname(os.path.realpath(__file__))
conf.read(script_dir + '/tradfri.cfg')

hubip = conf.get('tradfri', 'hubip')
securityid = conf.get('tradfri', 'securityid')

lightbulb = []
lightgroup = []

print('[ ] Tradfri: acquiring all Tradfri devices, please wait ...')
devices = tradfriStatus.tradfri_get_devices(hubip, securityid)
groups = tradfriStatus.tradfri_get_groups(hubip, securityid)

print(groups)

print(devices)

print(devices)
lightgroup = []
downstairs = [150864, 164492, 166823, 175915]
for groupid in groups:
    lightgroup.append(
        tradfriStatus.tradfri_get_group(hubip, securityid, str(groupid)))


def allOn(groups):