コード例 #1
0
def run(args):
    """Query Netatmo API to collect weather data and ingest in influx DB."""
    LoggerConfig.set_verbose(args.verbose)
    logger = LoggerConfig.get_logger(__name__)

    ifclient = InfluxDBClient(args.influxdb_host, args.influxdb_port,
                              args.influxdb_user, args.influxdb_pass,
                              args.influxdb_db)
    api = netatmo.WeatherStation({
        'client_id': args.netatmo_client_id,
        'client_secret': args.netatmo_client_secret,
        'username': args.netatmo_user,
        'password': args.netatmo_password
    })

    logger.info('Get station data')
    assert api.get_data()
    time = datetime.datetime.utcnow()
    response = api.devices

    points = NetatmoResponseMapper.to_influxdb_point(response, time)
    try:
        ifclient.write_points(points)
    except Exception as e:
        logger.error(points)
        logger.error(e)
        exit(1)

    logger.info('Done')
コード例 #2
0
def fetch_rain():
    """
        retrieve measures from rain station and append them to csv files
    """
    ws = netatmo.WeatherStation(netatmo.DEFAULT_RC_FILE)
    if not ws.get_data():
        return
    station = ws.station_by_name()
    rainmodule = station['modules'][1]
    print("module_id    : {}".format(rainmodule['_id']))
    print("module_name  : {}".format(rainmodule['module_name']))
    print("data_type    : {}".format(rainmodule['data_type']))

    data_type = ["Rain"]
    netatmo.dl_csv(ws, "netatmo_rain.csv",
                   station['_id'], rainmodule['_id'],
                   data_type, rainmodule['dashboard_data']['time_utc'])
コード例 #3
0
ファイル: fetch_netatmo.py プロジェクト: tyberion/smart_home
def netatmo_data():
    # credentials as parameters
    ws = netatmo.WeatherStation(
        {'client_id': NETATMO_ID,
         'client_secret': NETATMO_SECRET,
         'username': NETATMO_USERNAME,
         'password': NETATMO_PASSWORD,
         'default_station': NETATMO_STATION_ID,
         })
    ws.get_data()
    module = ws.devices[0]
    module_data = [module['dashboard_data']] + [m['dashboard_data'] for m in module['modules']]
    data = pd.DataFrame(module_data)
    data['Datetime'] = data.time_utc.apply(datetime.fromtimestamp)
    # data['module_name'] = [module['module)name']0
    data['Name'] = [module['module_name']] + [m['module_name'] for m in module['modules']]
    data['Type'] = 'Netatmo'

    return data[['Datetime', 'Type', 'Name', 'CO2', 'Humidity', 'Noise', 'Pressure', 'Temperature']]
コード例 #4
0
  def collect(self):
    """Collect grabs and returns a set of DataPoints."""
    creds = pkl.load(open('/home/entrymissing/.credentials/netatmo.pkl', 'rb'))
    weather_station = netatmo.WeatherStation(creds)
    weather_station.get_data()
    station = weather_station.devices[0]

    data = []
    now = time.time()
    for metric_type in station['data_type']:
      metric_name = self._base_name + 'basis.' + metric_type.lower()
      data.append(DataPoint(now, metric_name, station['dashboard_data'][metric_type]))
    for module_data in station['modules']:
      module_name = module_data['module_name'].lower()
      data.append(DataPoint(
          now, self._base_name + module_name + '.battery', module_data['battery_percent']))
      for metric_type in module_data['data_type']:
        metric_name = self._base_name + module_name + '.' + metric_type.lower()
        data.append(DataPoint(now, metric_name, module_data['dashboard_data'][metric_type]))


    return data
コード例 #5
0
ファイル: main.py プロジェクト: cltj/netAtmo
import netatmo
import fs
import requests
import json
import time
import config
import datetime

# Fetch data using ~/.netatmorc credentials
netatmo.fetch()

# Credentials as parameters
ws = netatmo.WeatherStation( {
        'client_id': config.CLIENT_ID,          
        'client_secret': config.CLIENT_SECRET,
        'username': config.USERNAME,
        'password': config.PASSWORD,
        'device': config.DEVICE_ID } )
ws.get_data()

# Store json response in response variable
response = ws.devices

# Convert from Python to JSON // Make it a string
x = json.dumps(response)

# Convert from JSON to Python dictionary
y = json.loads(x)

# Exstract values from object (dictionary)
module_name = (y[0]["modules"][0]["module_name"])
コード例 #6
0
ファイル: alarumd.py プロジェクト: markshuttle/thegloaming
try:
    alarm_hour = int(config['alarm']['hour']) % 24
except (KeyError, TypeError, ValueError):
    print('No alarm hour')
    alarm_hour = 'UNSET'
try:
    alarm_minute = int(config['alarm']['minute']) % 60
except (KeyError, TypeError, ValueError):
    print('No alarm minute')
    alarm_minute = 'UNSET'

# initialise netatmo
ws = netatmo.WeatherStation({
    'client_id': client_id,
    'client_secret': client_secret,
    'username': username,
    'password': password,
    'default_station': station_id
})

# Handler serves alarm static content in the /ui/ directory, and /weather
# gets a JSON struct with the current temperature and forecast along with
# details of the relevant data source for each.


class AlarumHandler(http.server.SimpleHTTPRequestHandler):
    def translate_path(self, path):
        # Courtesy of http://louistiao.me/posts/python-simplehttpserver-recipe-serve-specific-directory/
        path = posixpath.normpath(unquote(path))
        words = path.split('/')
        words = filter(None, words)
コード例 #7
0
    elif float(value) <= 1700:
        icon = "\uf5c0"  # half-star
    elif float(value) <= 2500:
        icon = "\uf12e"  # puzzle
    elif float(value) <= 3000:
        icon = "\uf619"  # poop
    elif float(value) > 3000:
        icon = "\uf2fe"  # poo
    return icon


# Get netatmo data
ws = netatmo.WeatherStation({
    'client_id': NA_CLIENT_ID,
    'client_secret': NA_CLIENT_SECRET,
    'username': NA_USERNAME,
    'password': NA_PASSWORD,
    'default_station': NA_DEFAULT_STATION
})
ws.get_data()
na_battery = ws.devices[0]["modules"][0]["battery_percent"]
na_signal = ws.devices[0]["modules"][0]["rf_status"]
na_temp_in = round(float(ws.devices[0]["dashboard_data"]["Temperature"]), 1)
na_temp_in_min = round(float(ws.devices[0]["dashboard_data"]["min_temp"]), 1)
na_temp_in_max = round(float(ws.devices[0]["dashboard_data"]["max_temp"]), 1)
na_temp_in_co2 = ws.devices[0]["dashboard_data"]["CO2"]
na_temp_in_noise = ws.devices[0]["dashboard_data"]["Noise"]
na_temp_in_humid = ws.devices[0]["dashboard_data"]["Humidity"]
na_temp_out = round(
    float(ws.devices[0]["modules"][0]["dashboard_data"]["Temperature"]), 1)
na_temp_out_min = round(