aboutsummaryrefslogtreecommitdiffstats
path: root/Common/sensors.py
blob: 6517b53336c91e83654e7d8538dd9a8264258dc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
Get Environmental Sensor Data.
"""

import External.lnetatmo as lnetatmo


def get_netatmo_temperature(station='zBox', module='zBox Room'):
    """
    Get Netatmo Temperature Data.

    @param: station - Name of Netatmo station to poll [String]
    @param: module - Name of Netatmo module to poll [String]
    @return: temperature - Temperature (Celsius) [Float]
    @return: epoch - Unix Timestamp (Seconds) [Float]
    """

    # Load Credentials
    with open('userpass_netatmo', 'r') as f:
        line = f.readline()
        line = line.strip().split(',')
        clientId = line[0]
        clientSecret = line[1]
        username = line[2]
        password = line[3]

    # Auth to Netatmo API
    authorization = lnetatmo.ClientAuth(clientId = clientId, \
                                        clientSecret = clientSecret, \
                                        username = username, \
                                        password = password)
    devList = lnetatmo.DeviceList(authorization)

    # Get Data
    temperature = devList.lastData(station=station)[module]['Temperature']
    epoch = devList.lastData(station=station)[module]['When']

    return temperature, epoch