SmartThings Community

Netatmo Weather Station?


(Tim Slagle) #21

@chevyman142000

Here’s the PHP Script I wrote for this purpose. I have it ran locally every 5 minutes. I use windows scheduler to run a BAT file that launches the script silently in the background. Maybe this will help you a little to @Dianoga ?

You will need to go to Netatmo and setup a dev account and get a client ID and App Secret. dev.netatmo.com is where you can sign up for that.

then just fill in the bolded stuff below in the first two sections with your APP ID and netatmo username and password. and your station ID and Password for the weather underground station and you’re good to go.

This also does the conversion from Celsius to Fahrenheit and estimates dew point based on humidity and temp.

#!/usr/bin/php
<?php
date_default_timezone_set('UTC');
/**
 * oAuth settings from http://dev.netatmo.com/dev/listapps
 */
define('APP_ID', 'CLIENT ID HERE');
define('APP_SECRET', 'CLIENT SECRET HERE');
define('USERNAME', 'USERNAME HERE');
define('PASSWORD', 'PASSWORD HERE');
define('TOKEN_URL', 'https://api.netatmo.net/oauth2/token');
define('DEVICELIST_URL', 'https://api.netatmo.net/api/devicelist');

/**
 * Station ID from http://www.wunderground.com/wxstation/signup.html
 */
define('STATION_URL', 'http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php');
define('STATION_ID', 'STATION ID HERE');
define('STATION_PASSWORD', 'PASSWORD HERE');
define('DEBUG', 1);

if (APP_ID == '' || APP_SECRET == '' || USERNAME == '' || PASSWORD == '' || STATION_ID == '' || STATION_PASSWORD == '') {
  fwrite(STDERR, "APP_ID, APP_SECRET, USERNAME, PASSWORD, STATION_ID, STATION_PASSWORD cannot be empty.\n");
  exit(1);
}

$opts = array(
  'http' => array(
    'method' => 'POST',
    'header' => 'Content-type: application/x-www-form-urlencoded',
    'content' => http_build_query(array(
      'grant_type' => "password",
      'client_id' => APP_ID,
      'client_secret' => APP_SECRET,
      'username' => USERNAME,
      'password' => PASSWORD
    ))
  )
);
if (DEBUG) print_r($opts);

$context = stream_context_create($opts);
$response = file_get_contents(TOKEN_URL, FALSE, $context);
$response_json = json_decode($response, TRUE);
if (DEBUG) print_r($response_json);

if (!$response || empty($response_json['access_token'])) {
  fwrite(STDERR, "Couldn't retrieve the access_token. Please check your username and password.\n");
  exit(1);
}

$access_token = $response_json['access_token'];
$device_list = json_decode(file_get_contents(DEVICELIST_URL . '?access_token=' . $access_token));
if (!$device_list || sizeof($device_list->body->devices) == 0) {
  fwrite(STDERR, "Couldn't find any devices\n");
  exit(1);
}

if (sizeof($device_list->body->modules) == 0 || empty($device_list->body->modules[0]->_id)) {
  fwrite(STDERR, "Couldn't find outdoor devices\n");
  exit(1);
}

$indoor_id = $device_list->body->devices[0]->_id;
$outdoor_id = $device_list->body->modules[0]->_id;

$last_data = $device_list->body->devices[0]->last_data_store;
if (DEBUG) print_r($last_data);

$params = array(
  'ID' => STATION_ID,
  'PASSWORD' => STATION_PASSWORD,
  'action' => 'updateraw',
  'dateutc' => date("Y-m-d H:i:s",$last_data->$outdoor_id->K),
  'humidity' => $last_data->$outdoor_id->b,
  'temp' => $last_data->$outdoor_id->a,
  'baromhPa' => $last_data->$indoor_id->e,
  'indoortemp' => $last_data->$indoor_id->a,
  'indoorhumidity' => $last_data->$indoor_id->b,
  'softwaretype' => 'Netatmo'
);

// calculate dew point using temperature and humidity (optional)
// source: http://www.aprweather.com/pages/calc.htm
$params['dewpt'] = ($params['temp'] - (14.55 + 0.114 * $params['temp']) * (1 - (0.01 * $params['humidity'])) - pow((2.5 + 0.007 * $params['temp']) * (1 - (0.01 * $params['humidity'])), 3) - (15.9 + 0.117 * $params['temp']) * pow(1 - (0.01 * $params['humidity']), 14));

// conversion to F
$params['tempf'] = $params['temp'] * 9 / 5 + 32;
$params['dewptf'] = $params['dewpt'] * 9 / 5 + 32;
$params['indoortempf'] = $params['indoortemp'] * 9 / 5 + 32;
$params['baromin'] = $params['baromhPa'] * 0.0295299830714;
// remove SI after conversion
unset($params['temp'],$params['dewpt'],$params['indoortemp'],$params['baromhPa']);
ksort($params);
if (DEBUG) print_r($params);

$response = file_get_contents(STATION_URL . '?' . http_build_query($params));
if (DEBUG) print $response;

?>

(Kevin Tierney) #22

Just ordered one from ATT wireless’s website. They considered it an “accessory” and it was eligible for their 25% off when you buy 3, so I added two 5$ usb charger plugs. Can’t wait to see what kind of cool stuff can be done with it. Will be interesting to monitor the “noise polution” i.e how often our dogs bark when we are not home


(Fei Xiao) #23

Hooray @Dianoga, once we get a device type for Netatmo, looking forward to having the home fan turn on when CO2 gets to a certain threshold. BTW, your Nest device type works great! I’m looking forward to getting these 2 “things” working together :slight_smile:


(Brian Steere) #24

Just so everyone knows, I now have the device and have started working on tying things together. It may take a bit longer than I expected as I’m apparently also redoing a bathroom and having family visit, but I’ll get it done as soon as I can.


(Jeff DeWolfe) #25

That’s excellent news! Can’t wait!!


(Brian Steere) #26

Not ready to release yet but…


(Tim Slagle) #27

@Dianoga

Dude!!! That’s so awesome!!! Thanks so much!!!

P.S. I’m a great beta tester;)


(Kevin Tierney) #28

Looks impressive. Can’t wait to try it out


(Hans Holm) #29

Great, now I have to buy a Netatmo too :wink: Awesome work.


(Jeff DeWolfe) #30

Damn man, I can’t wait!!! Thanks for working on this!


(Gene Kendrick) #31

Looks Great. Hope it includes the rain gauge also


(Brian Steere) #32

@genekend Right now it doesn’t include the rain gauge as I don’t have one and can’t test it. If anyone has one and is willing/able to give me the result of the getdevices API call, I can try adding it.


(Ben Edwards) #33

Tune into the Dev Office Hour tonight at 8pm EST / 5pm PST to see this in action. @Dianoga has offered to demo during it.

More info here


(Kevin Tierney) #34

Since its been a few weeks, are there any updates on this?


(Jeff DeWolfe) #35

I’m hoping soon!!


(Tim Slagle) #36

@Dianoga any good news? :):):slight_smile:


(Claudio) #37

@Dianoga I am happy to offer as a beta tester too! Have two netatmo and it would be great to use it! Are you planning actions like: when it rains, or when humidity is over…, or when C02 is over… etc?

thanks!


(Tim Slagle) #38

@Dianoga

I ordered the rain gauge. Will let you know when it comes in. That way we can get that reporting too!! :smile: :feelsgood:


(Tim Slagle) #39

Found this little nugget in the IDE today! :smile:

Release coming soon? :wink:


(Jeff DeWolfe) #40

God I hope so. Sure takes long enough for things to go through the QA process…