├── readmeAssets ├── IF.jpg ├── howto.jpg ├── mit.jpg ├── read.jpg ├── set.jpg ├── changes.jpg ├── logoNetatmo.png └── requirements.jpg ├── callback ├── NetConnect.jpg ├── callback.php └── README.md ├── LICENSE ├── README.md └── class └── splNetatmoAPI.php /readmeAssets/IF.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KiboOst/php-simpleNetatmoAPI/HEAD/readmeAssets/IF.jpg -------------------------------------------------------------------------------- /readmeAssets/howto.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KiboOst/php-simpleNetatmoAPI/HEAD/readmeAssets/howto.jpg -------------------------------------------------------------------------------- /readmeAssets/mit.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KiboOst/php-simpleNetatmoAPI/HEAD/readmeAssets/mit.jpg -------------------------------------------------------------------------------- /readmeAssets/read.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KiboOst/php-simpleNetatmoAPI/HEAD/readmeAssets/read.jpg -------------------------------------------------------------------------------- /readmeAssets/set.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KiboOst/php-simpleNetatmoAPI/HEAD/readmeAssets/set.jpg -------------------------------------------------------------------------------- /callback/NetConnect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KiboOst/php-simpleNetatmoAPI/HEAD/callback/NetConnect.jpg -------------------------------------------------------------------------------- /readmeAssets/changes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KiboOst/php-simpleNetatmoAPI/HEAD/readmeAssets/changes.jpg -------------------------------------------------------------------------------- /readmeAssets/logoNetatmo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KiboOst/php-simpleNetatmoAPI/HEAD/readmeAssets/logoNetatmo.png -------------------------------------------------------------------------------- /readmeAssets/requirements.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KiboOst/php-simpleNetatmoAPI/HEAD/readmeAssets/requirements.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 KiboOst 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /callback/callback.php: -------------------------------------------------------------------------------- 1 | getMessage()); 52 | } 53 | } 54 | 55 | //If message AND person seen by Presence 56 | if(isset($data['message']) && isset($data['snapshot_id']) && ($eventType == 'human')) 57 | { 58 | $snapshotID = $data['snapshot_id']; 59 | $snapshotKEY = $data['snapshot_key']; 60 | $snapshotURL = 'https://api.netatmo.com/api/getcamerapicture?image_id='.$snapshotID.'&key='.$snapshotKEY; 61 | 62 | echo 'Someone has been seen outdoor, I may arm the gatling.'; 63 | } 64 | 65 | ?> 66 | -------------------------------------------------------------------------------- /callback/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Netatmo callback 4 | 5 | I will try here to explain what is a callback script and why it can be usefull. 6 | 7 | You can set such callback script when you create an app on [Netatmo Connect](https://dev.netatmo.com/). Then, each time an event happens (someone is seen outdoor, a known person is seen at home, etc...), Netatmo server will do its job as usual (notifications, make it appear in timeline, etc...) but, it will now send this event to your callback script! 8 | 9 | So you won't have to make your script checking timeline or whatever, all events will end to your script automatically. Your script will then be able to do different things regarding the nature of the event. For example, if the home is empty and someone known is seen, you can call Jeedom to say *hello John, welcome home* with a TTS device. Or if your are out and someone is seen outdoor, you can send an email with the snapshot, etc. All is up to you to decide what to do regarding event, time, home state, etc. 10 | 11 | 12 | 13 | ## Requirements 14 | 15 | - Your Netatmo login and password. 16 | - A Netatmo Connect application. 17 | - A webserver, always accessible from internet. 18 | 19 | If you don't have Netatmo App yet, just create one, it's simple and free: 20 | 21 | - Register at https://dev.netatmo.com 22 | - Create an app at https://dev.netatmo.com/dev/createanapp (Enter any name) 23 | 24 | 25 | 26 | ## How-to 27 | 28 | On your Netatmo Connect account, go into your app, at *Technical Parameters*, you will see a field named *Webhook URL*. Here comes the interesting part! 29 | 30 | All you will have to do, is enter the url to reach your callback script: 31 | https://www.mydomain.com/callback.php 32 | 33 | >But wait until you have read everything before setting it, to not be banned! 34 | 35 |

36 | 37 | Then on your domain, you will of course have to create your callback.php script. 38 | 39 | Now, each time an event get to Netatmo server, this one will be sent back to your script as [json](https://www.w3schools.com/whatis/whatis_json.asp). So, your script will be notified of everything that happens on Netatmo Cameras. You can for example start to log all the data it receive, to get familiar with such data. 40 | 41 | You can get the example script [here](callback.php) as a start: 42 | 43 | ```php 44 | getMessage()); 95 | } 96 | } 97 | 98 | //If message AND person seen by Presence 99 | if(isset($data['message']) && isset($data['snapshot_id']) && ($eventType == 'human')) 100 | { 101 | $snapshotID = $data['snapshot_id']; 102 | $snapshotKEY = $data['snapshot_key']; 103 | $snapshotURL = 'https://api.netatmo.com/api/getcamerapicture?image_id='.$snapshotID.'&key='.$snapshotKEY; 104 | 105 | echo 'Someone has been seen outdoor, I may arm the gatling.'; 106 | } 107 | 108 | ?> 109 | ``` 110 | 111 | You will notice that first thing I do after receiving the data is to send an "ok" answer to Netatmo server. If you don't send this, the Netatmo server will set your script as unreachable which can end to being banned. So if you have errors later in your script, we have ever answered to Netatmo server. Anyway, if your domain is down for a moment, you can still be banned. 112 | 113 | >After 5 failures in the course of one hour, webhooks get banned and Netatmo server will stop sending events for the next 24h. You can unban yourself directly from the webhook section in your app details. You are only allowed to unban yourself 10 times in the course of 24h. 114 | 115 | So, you have the way and a small structure to make your own callback script according to your needs. 116 | 117 | For example, you can call a Jeedom scenario in some case with just this: 118 | 119 | ```php 120 | $url = 'https://a123456b.dns1.jeedom.com/core/api/jeeApi.php?apikey=myjeedomapikey&type=scenario&id=00&action=start'; 121 | file_get_contents($url); 122 | ``` 123 | You can add in such url some tags to pass who have been seen, and say Hello with [SNIPS](https://github.com/KiboOst/SNIPS-Tips) or whatever. I won't go into details here, as this depends on your smarthome if any, and what you want to do. 124 | 125 | Have a look on Netatmo Connect, on your app at *Webhooks* section. You can have a look at (or download) the log of all events sent to your callback. This will be handy to see which json parts are sent, and how to treat it in your callback script. 126 | 127 | Hope this will be helpful ;-) 128 | 129 | 130 | #### 29/11/2018 | KiboOst 131 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | # php-simpleNetatmoAPI 6 | 7 | ## Simple php API to get data from your Netatmo devices. 8 | 9 | ## Supported devices 10 | 11 | - Netatmo Weather Station 12 | - Netatmo Presence Cameras 13 | - Netatmo Welcome Cameras 14 | - Netatmo Doorbell 15 | 16 | This is a simple stand-alone API to get your Netatmo devices data in a more easy and more readable way. 17 | 18 | It does rely on official Netatmo SDK, even if no other resources are needed to get your data. Just download and use one single php file! 19 | 20 | >Need to setup a Netatmo callback ? Check [here](/callback) 21 | 22 | 23 | 24 | ## Requirements 25 | 26 | If you don't have Netatmo App yet, just create one, it's simple and free: 27 | 28 | - Register at https://dev.netatmo.com 29 | - Create an app at https://dev.netatmo.com/apps/createanapp#form (Enter any name) 30 | - After successfully created your app, just get client_id and client_secret 31 | 32 | In your app, check *Token generator* section: enter all needed scopes, then hit **Generate Token** 33 | 34 | Copy **Refresh Token** into refreshtoken.txt file beside your php script. This is extremely important, as for each API initialisation, this refresh token will change, and write back into the file for next calls. Also, this means you can't anymore (December 2023, thanks Netatmo, awkward decision!!) use same app for different scripts locations, or will have to synch this file! 35 | 36 | If you need to have this file in different folders you can try that: 37 | ```php 38 | require($_SERVER['DOCUMENT_ROOT']."/path/to/splNetatmoAPI.php"); 39 | chdir('/path/to/token/'); //for refreshtoken api file path 40 | $_splNetatmo = new splNetatmoAPI($Netatmo_app_id, $Netatmo_app_secret); 41 | ``` 42 | 43 | 44 | 45 | 46 | ## How-to 47 | 48 | All functions return a json array, you can echo it to see which key to get. 49 | 50 | Initialize: 51 | ```php 52 | require($_SERVER['DOCUMENT_ROOT']."/path/to/splNetatmoAPI.php"); 53 | $_splNetatmo = new splNetatmoAPI($Netatmo_app_id, $Netatmo_app_secret); 54 | if (isset($_splNetatmo->error)) die($_splNetatmo->error); 55 | ``` 56 | 57 | If you have several homes, you can specify a homeID as last argument. 58 | ```php 59 | require($_SERVER['DOCUMENT_ROOT']."/path/to/splNetatmoAPI.php"); 60 | $_splNetatmo = new splNetatmoAPI($Netatmo_app_id, $Netatmo_app_secret, 1); 61 | if (isset($_splNetatmo->error)) die($_splNetatmo->error); 62 | 63 | //You can also check homes configured on your account to connect to the right one 64 | //It will return all homes with name, id and camera number found. 65 | $homes = $_splNetatmo->getHomes(); 66 | echo "

homes:
".json_encode($homes, JSON_PRETTY_PRINT)."

"; 67 | ``` 68 | 69 | ### Weather Station: 70 | 71 | ```php 72 | //get module datas by its name: 73 | $getWeatherModuleDatas = $_splNetatmo->getWeatherModuleDatas('Exterieur'); 74 | echo "
getWeatherModuleDatas:
".json_encode($getWeatherModuleDatas, JSON_PRETTY_PRINT)."

"; 75 | 76 | //get all temperatures from all modules: 77 | $getWeatherTemperatures = $_splNetatmo->getWeatherTemperatures(); 78 | echo "
getWeatherTemperatures:
".json_encode($getWeatherTemperatures, JSON_PRETTY_PRINT)."

"; 79 | echo $getWeatherTemperatures['Exterieur']; 80 | 81 | //get all modules batteries: 82 | //If you specify a number under 100, it will return only modules under this number so you can get low batteries modules. 83 | $getWeatherBatteries = $_splNetatmo->getWeatherBatteries(); 84 | echo "
getWeatherBatteries:
".json_encode($getWeatherBatteries, JSON_PRETTY_PRINT)."

"; 85 | 86 | //get all modules firmwares versions: 87 | $getWeatherFirmVer = $_splNetatmo->getWeatherFirmVer(); 88 | echo "
getWeatherFirmVer:
".json_encode($getWeatherFirmVer, JSON_PRETTY_PRINT)."

"; 89 | 90 | //get all modules radio signal statut: 91 | $getWeatherRFs = $_splNetatmo->getWeatherRFs(); 92 | echo "
getWeatherRFs:
".json_encode($getWeatherRFs, JSON_PRETTY_PRINT)."

"; 93 | ``` 94 | 95 | ### Netatmo Cameras: 96 | 97 | 98 | 99 | #### Get some datas: 100 | *Change camera name by yours!* 101 | 102 | ```php 103 | //get all Presence cameras datas: 104 | $Cameras = $_splNetatmo->getPresenceCameras(); 105 | echo "
Cameras:
".json_encode($Cameras, JSON_PRETTY_PRINT)."

"; 106 | echo "
light_mode: ".json_encode($Cameras['Cam_Terrasse']['light_mode_status'], JSON_PRETTY_PRINT)."

"; 107 | 108 | //get 10 last event of defined type: 109 | //can request 'human', 'animal', 'vehicle', 'movement', 'All' 110 | $events = $_splNetatmo->getOutdoorEvents('All', 10); 111 | echo "
events:
".json_encode($events, JSON_PRETTY_PRINT)."

"; 112 | 113 | //get all Welcome cameras datas: 114 | $Cameras = $_splNetatmo->getWelcomeCameras(); 115 | echo "
Cameras:
".json_encode($Cameras, JSON_PRETTY_PRINT)."

"; 116 | 117 | //get 10 last indoor events: 118 | $events = $_splNetatmo->getIndoorEvents(10); 119 | echo "
events:
".json_encode($events, JSON_PRETTY_PRINT)."

"; 120 | 121 | //get all persons at home: 122 | $atHome = $_splNetatmo->getPersonsAtHome(); 123 | echo "
atHome :
".json_encode($atHome , JSON_PRETTY_PRINT)."

"; 124 | 125 | //get John datas: 126 | $John = $_splNetatmo->getPerson('John'); 127 | echo "
John :
".json_encode($John , JSON_PRETTY_PRINT)."

"; 128 | 129 | //is home empty ? 130 | echo $_splNetatmo->isHomeEmpty(); 131 | ``` 132 | 133 | 134 | 135 | #### Change some settings: 136 | *Change camera name by yours!* 137 | 138 | ```php 139 | //You can also get return value to know if all went fine. 140 | 141 | //set John away from home: 142 | $_splNetatmo->setPersonAway('John'); 143 | 144 | //set home empty: 145 | $_splNetatmo->setHomeEmpty(); 146 | 147 | //set person(s) at home: 148 | $_splNetatmo->setPersonsAtHome('John'); 149 | $_splNetatmo->setPersonsAtHome(['John','William']); 150 | 151 | //change Presence light intensity: 152 | $_splNetatmo->setLightIntensity('MyCam', 85); 153 | 154 | //change Presence Light mode (use either 'auto', 'on', 'off': 155 | $_splNetatmo->setLightMode('MyCam', 'auto'); 156 | 157 | //change Presence or Welcome monitoring (use either 'on', 'off': 158 | $_splNetatmo->setMonitoring('MyCam', 'on'); 159 | 160 | ``` 161 | 162 | ### Setting/dropping webhooks: 163 | 164 | ```php 165 | //set webhook: 166 | $endpoint = 'http://www.mydomain.com/myscripts/myPresenceWebhook.php'; 167 | $answer = $_splNetatmo->setWebhook($endpoint); 168 | print_r($answer); 169 | 170 | //drop webhook: 171 | $_splNetatmo->dropWebhook(); 172 | ``` 173 | 174 | >Need to setup a Netatmo callback ? Check [here](/callback) 175 | 176 | 177 | 178 | ## Changes 179 | 180 | #### v3.0 (2023-05-12) 181 | - Fix: refresh token to file, thanks to stupid Netatmo decision! See **Requirements** 182 | 183 | #### v1.7 (2022-04-25) 184 | - New: setSirenStatus() 185 | *example: $_splNetatmo->setSirenStatus('MyCam', true);* 186 | 187 | #### v1.65 (2021-06-20) 188 | - report Presence siren status 189 | 190 | #### v1.6 (2021-03-07) 191 | - Support doorbell 192 | 193 | #### v1.4 (2018-06-13) 194 | - New: setPersonsAtHome() 195 | - Fix: setMonitoring() for Welcome cameras 196 | 197 | #### v1.32 (2018-01-29) 198 | - Fix: isHomeEmpty() 199 | 200 | #### v1.31 (2017-11-29) 201 | - New: getHomes() return all found homes with their id and name 202 | - New: pass home id as last argument: new splNetatmoAPI($user, $pass, $app_id, $app_secret, 1); 203 | 204 | #### v1.3 (2017-11-18) 205 | - New: setMonitoring('camName', 'on') 206 | - New: setLightMode('camName', 'auto') 207 | - New: setLightIntensity('camName', 100) 208 | 209 | #### v1.2 (2017-05-24) 210 | - New: Welcome cameras support! 211 | - Warning: check Presence functions for name changes. 212 | 213 | #### v1.0 (2017-03-24) 214 | - First public version. 215 | 216 | 217 | 218 | ## License 219 | 220 | The MIT License (MIT) 221 | 222 | Copyright (c) 2017 KiboOst 223 | 224 | Permission is hereby granted, free of charge, to any person obtaining a copy 225 | of this software and associated documentation files (the "Software"), to deal 226 | in the Software without restriction, including without limitation the rights 227 | to use, copy, modify, merge, publish, distribute, sub-license, and/or sell 228 | copies of the Software, and to permit persons to whom the Software is 229 | furnished to do so, subject to the following conditions: 230 | 231 | The above copyright notice and this permission notice shall be included in all 232 | copies or substantial portions of the Software. 233 | 234 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 235 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 236 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 237 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 238 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 239 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 240 | SOFTWARE. 241 | -------------------------------------------------------------------------------- /class/splNetatmoAPI.php: -------------------------------------------------------------------------------- 1 | _weatherDatas)) $this->getWeatherDatas(); 19 | return $this->_weatherDatas['body']['devices'][0]['dashboard_data']; 20 | } 21 | 22 | public function getWeatherModuleDatas($Mname='') 23 | { 24 | if (is_null($this->_weatherDatas)) $this->getWeatherDatas(); 25 | $modules = $this->_weatherDatas['body']['devices'][0]['modules']; 26 | foreach ($modules as $module) 27 | { 28 | $name = $module['module_name']; 29 | if ($Mname == $name) return $module['dashboard_data']; 30 | } 31 | return false; 32 | } 33 | 34 | public function getWeatherTemperatures() 35 | { 36 | if (is_null($this->_weatherDatas)) $this->getWeatherDatas(); 37 | 38 | $modules = $this->_weatherDatas['body']['devices'][0]['modules']; 39 | 40 | $jsonDatas = array(); 41 | foreach ($modules as $module) 42 | { 43 | if (!isset($module['dashboard_data']['Temperature'])) continue; 44 | 45 | $name = $module['module_name']; 46 | $temp = $module['dashboard_data']['Temperature']; 47 | $jsonDatas[$name] = $temp; 48 | } 49 | //add main station: 50 | $jsonDatas[ $this->_weatherDatas['body']['devices'][0]['station_name'] ] = $this->_weatherDatas['body']['devices'][0]['dashboard_data']['Temperature']; 51 | return $jsonDatas; 52 | } 53 | 54 | public function getWeatherBatteries($lowLevel=100) 55 | { 56 | if (is_null($this->_weatherDatas)) $this->getWeatherDatas(); 57 | $modules = $this->_weatherDatas['body']['devices'][0]['modules']; 58 | 59 | $jsonDatas = array(); 60 | foreach ($modules as $module) 61 | { 62 | if (!isset($module['battery_percent'])) continue; 63 | 64 | $name = $module['module_name']; 65 | $batlevel = $module['battery_percent']; 66 | if ($batlevel <= $lowLevel) $jsonDatas[$name] = $batlevel; 67 | } 68 | return $jsonDatas; 69 | } 70 | 71 | public function getWeatherFirmVer() 72 | { 73 | if (is_null($this->_weatherDatas)) $this->getWeatherDatas(); 74 | $modules = $this->_weatherDatas['body']['devices'][0]['modules']; 75 | 76 | $jsonDatas = array(); 77 | foreach ($modules as $module) 78 | { 79 | if (!isset($module['firmware'])) continue; 80 | 81 | $name = $module['module_name']; 82 | $firmVer = $module['firmware']; 83 | $jsonDatas[$name] = $firmVer; 84 | } 85 | //add main station: 86 | $jsonDatas[ $this->_weatherDatas['body']['devices'][0]['station_name'] ] = $this->_weatherDatas['body']['devices'][0]['firmware']; 87 | return $jsonDatas; 88 | } 89 | 90 | public function getWeatherRFs() 91 | { 92 | if (is_null($this->_weatherDatas)) $this->getWeatherDatas(); 93 | $modules = $this->_weatherDatas['body']['devices'][0]['modules']; 94 | 95 | $jsonDatas = array(); 96 | foreach ($modules as $module) 97 | { 98 | if (!isset($module['rf_status'])) continue; 99 | 100 | $name = $module['module_name']; 101 | $rf = $module['rf_status']; 102 | $jsonDatas[$name] = $rf; 103 | } 104 | //add main station: 105 | $jsonDatas[ $this->_weatherDatas['body']['devices'][0]['station_name'] ] = $this->_weatherDatas['body']['devices'][0]['firmware']; 106 | return $jsonDatas; 107 | } 108 | 109 | 110 | //PRESENCE / WELCOME: 111 | public function getOutdoorEvents($requestType='All', $num=1) //human, animal, vehicle, All 112 | { 113 | //will return the last event of defined type as array of [title, snapshotURL, vignetteURL] 114 | if (is_null($this->_camerasDatas)) $this->getCamerasDatas($num); 115 | if (is_null($this->_cameras)) $this->getCameras(); 116 | 117 | $cameraEvents = $this->_camerasDatas['body']['homes'][$this->_homeID]['events']; 118 | $numEvents = count($cameraEvents); 119 | $counts = $num; 120 | if ($numEvents < $counts) $counts == $numEvents; 121 | 122 | $returnEvents = array(); 123 | for ($i=0; $i < $counts ;$i++) 124 | { 125 | $thisEvent = $cameraEvents[$i]; 126 | 127 | $id = $thisEvent['id']; 128 | $time = $thisEvent['time']; 129 | $camId = $thisEvent['camera_id']; 130 | 131 | //get camera name: 132 | $c = count($this->_cameras); 133 | for ($ic=0; $ic < $c; $ic++) 134 | { 135 | $cam = array_values($this->_cameras)[$ic]; 136 | if ($cam['id'] == $camId) 137 | { 138 | $camName = $cam['name']; 139 | if (isset($cam['vpn'])) $camVPN = $cam['vpn']; 140 | $camType = $cam['type']; 141 | break; 142 | } 143 | } 144 | //get only outdoors events: 145 | if ($camType != 'Presence') continue; 146 | 147 | $type = $thisEvent['type']; 148 | 149 | if ($type != 'outdoor' and $requestType=='All') 150 | { 151 | $time = $thisEvent['time']; 152 | $time = date("d-m-Y H:i:s", $time); 153 | $msg = $thisEvent['message']; 154 | $returnThis = array(); 155 | $returnThis['title'] = $msg; 156 | $returnThis['camera'] = $camName; 157 | $returnThis['time'] = $time; 158 | $returnThis['type'] = $thisEvent['type']; 159 | array_push($returnEvents, $returnThis); 160 | } 161 | 162 | if ($type == 'outdoor') 163 | { 164 | $eventList = $thisEvent['event_list']; 165 | $isAvailable = $thisEvent['video_status']; 166 | for ($j=0; $j < count($eventList) ;$j++) 167 | { 168 | $thisSubEvent = $thisEvent['event_list'][$j]; 169 | $subType = $thisSubEvent['type']; 170 | $subMsg = $thisSubEvent['message']; 171 | if (strpos($subType, $requestType) !== false OR $requestType=='All') 172 | { 173 | $subTime = $thisSubEvent['time']; 174 | $subTime = date("d-m-Y H:i:s", $subTime); 175 | 176 | if (isset($thisSubEvent['snapshot']['url'])) 177 | { 178 | $snapshotURL = $thisSubEvent['snapshot']['url']; 179 | } 180 | else if (isset($thisSubEvent['snapshot']['filename'])) //other vignette of same event! 181 | { 182 | $snapshotURL = $camVPN.'/'.$thisSubEvent['snapshot']['filename']; 183 | } 184 | else 185 | { 186 | $snapshotID = $thisSubEvent['snapshot']['id']; 187 | $snapshotKEY = $thisSubEvent['snapshot']['key']; 188 | $snapshotURL = 'https://api.netatmo.com/api/getcamerapicture?image_id='.$snapshotID.'&key='.$snapshotKEY; 189 | } 190 | 191 | if (isset($thisSubEvent['vignette']['url'])) 192 | { 193 | $vignetteURL = $thisSubEvent['vignette']['url']; 194 | } 195 | else if (isset($thisSubEvent['vignette']['filename'])) //other vignette of same event! 196 | { 197 | $vignetteURL = $camVPN.'/'.$thisSubEvent['vignette']['filename']; 198 | } 199 | else 200 | { 201 | $vignetteID = $thisSubEvent['vignette']['id']; 202 | $vignetteKEY = $thisSubEvent['vignette']['key']; 203 | $vignetteURL = 'https://api.netatmo.com/api/getcamerapicture?image_id='.$vignetteID.'&key='.$vignetteKEY; 204 | } 205 | 206 | //echo ''.'
'; 207 | //echo ''.'
'; 208 | 209 | $returnThis = array(); 210 | $returnThis['title'] = $subMsg; 211 | $returnThis['camera'] = $camName; 212 | $returnThis['time'] = $subTime; 213 | $returnThis['snapshotURL'] = $snapshotURL; 214 | $returnThis['vignetteURL'] = $vignetteURL; 215 | array_push($returnEvents, $returnThis); 216 | } 217 | } 218 | } 219 | } 220 | 221 | return $returnEvents; 222 | } 223 | 224 | public function getIndoorEvents($num=5) 225 | { 226 | if (is_null($this->_camerasDatas)) $this->getCamerasDatas(10); 227 | if (is_null($this->_cameras)) $this->getCameras(); 228 | 229 | $cameraEvents = $this->_camerasDatas['body']['homes'][$this->_homeID]['events']; 230 | $returnEvents = array(); 231 | for ($i=0; $i <= $num ;$i++) 232 | { 233 | //avoid iterating more than there is! 234 | if (isset($cameraEvents[$i])) $thisEvent = $cameraEvents[$i]; 235 | else break; 236 | 237 | $camId = $thisEvent['camera_id']; 238 | foreach ($this->_cameras as $cam) 239 | { 240 | if ($cam['id'] == $camId) 241 | { 242 | $camName = $cam['name']; 243 | $camType = $cam['type']; 244 | break; 245 | } 246 | } 247 | //get only indoor events: 248 | if ($camType != 'Welcome') 249 | { 250 | continue; 251 | } 252 | 253 | $id = $thisEvent['id']; 254 | $type = $thisEvent['type']; 255 | $time = $thisEvent['time']; 256 | $date = date('d-m-Y H:i:s', $time); 257 | $message = $thisEvent['message']; 258 | 259 | $returnThis = array(); 260 | $returnThis['title'] = $message . ' | '.$date.' | '.$camName; 261 | $returnThis['type'] = $type; 262 | $returnThis['time'] = $thisEvent['time']; 263 | $returnThis['date'] = $date; 264 | 265 | 266 | if (isset($thisEvent['person_id'])) $returnThis['person_id'] = $thisEvent['person_id']; 267 | 268 | if (isset($thisEvent['snapshot'])) 269 | { 270 | $snapshot = $thisEvent['snapshot']; 271 | if (isset($snapshot['url'])) 272 | { 273 | $snapshotURL = $snapshot['url']; 274 | } 275 | else 276 | { 277 | $snapshotID = $snapshot['id']; 278 | $snapshotKEY = $snapshot['key']; 279 | $snapshotURL = 'https://api.netatmo.com/api/getcamerapicture?image_id='.$snapshotID.'&key='.$snapshotKEY; 280 | } 281 | $returnThis['snapshotURL'] = $snapshotURL; 282 | } 283 | 284 | if (isset($thisEvent['is_arrival'])) $returnThis['is_arrival'] = $thisEvent['is_arrival']; 285 | $returnThis['camera_id'] = $camId; 286 | $returnThis['event_id'] = $id; 287 | 288 | array_push($returnEvents, $returnThis); 289 | } 290 | return $returnEvents; 291 | } 292 | 293 | public function getPerson($name) //Welcome 294 | { 295 | if ( is_string($name) ) $person = $this->getPersonByName($name); 296 | return $person; 297 | } 298 | 299 | public function getPersonsAtHome() //Welcome 300 | { 301 | $atHome = array(); 302 | foreach ($this->_persons as $thisPerson) 303 | { 304 | if ($thisPerson['out_of_sight'] == false) array_push($atHome, $thisPerson); 305 | } 306 | return array('result'=>$atHome); 307 | } 308 | 309 | public function isHomeEmpty() //Welcome 310 | { 311 | $atHome = $this->getPersonsAtHome(); 312 | if (count($atHome['result'])==0) return true; 313 | return false; 314 | } 315 | 316 | public function setPersonAway($person) //Welcome 317 | { 318 | if ( is_string($person) ) $person = $this->getPersonByName($person); 319 | if ( isset($person['error']) ) return $person; 320 | $personID = $person['id']; 321 | $homeID = $this->_camerasDatas['body']['homes'][$this->_homeID]['id']; 322 | 323 | $url = $this->_apiurl.'/api/setpersonsaway?access_token=' . $this->_accesstoken .'&home_id='.$homeID.'&person_id='.$personID .'&size=2'; 324 | $response = file_get_contents($url, false); 325 | 326 | $jsonDatas = json_decode($response, true); 327 | return $jsonDatas; 328 | } 329 | 330 | public function setPersonsAtHome($persons) //Welcome 331 | { 332 | if ( is_string($persons) ) 333 | { 334 | $arID = $this->getPersonByName($persons); 335 | if ( isset($arString['error']) ) return $arString; 336 | $arString = $arID['id']; 337 | $arString = '["'.$arString.'"]'; 338 | } 339 | 340 | if ( is_array($persons) ) 341 | { 342 | $arIDs = array(); 343 | foreach ($persons as $name) 344 | { 345 | $personID = $this->getPersonByName($name); 346 | if ( !isset($personID['error']) ) array_push($arIDs, $personID['id']); 347 | } 348 | $arString = implode('","', $arIDs); 349 | $arString = '["'.$arString.'"]'; 350 | } 351 | 352 | $homeID = $this->_camerasDatas['body']['homes'][$this->_homeID]['id']; 353 | 354 | $url = $this->_apiurl.'/api/setpersonshome?access_token=' . $this->_accesstoken .'&home_id='.$homeID.'&person_ids='.$arString; 355 | $response = file_get_contents($url, false); 356 | 357 | $jsonDatas = json_decode($response, true); 358 | return $jsonDatas; 359 | } 360 | 361 | public function setHomeEmpty() //Welcome 362 | { 363 | $homeID = $this->_camerasDatas['body']['homes'][$this->_homeID]['id']; 364 | 365 | $url = $this->_apiurl.'/api/setpersonsaway?access_token=' . $this->_accesstoken .'&home_id='.$homeID.'&size=2'; 366 | $response = file_get_contents($url, false); 367 | 368 | $jsonDatas = json_decode($response, true); 369 | return $jsonDatas; 370 | } 371 | 372 | public function setLightMode($camName, $mode='auto') //Presence 373 | { 374 | 375 | if ( is_string($camName) ) $camera = $this->getCamByName($camName); 376 | if ( isset($camera['error']) ) return $camera; 377 | 378 | $value = null; 379 | if (in_array($mode, array('on', '1', 1, true), true)) $value = 'on'; 380 | if (in_array($mode, array('off', '0', 0, false), true)) $value = 'off'; 381 | if (in_array($mode, array('auto', 2), true)) $value = 'auto'; 382 | if (!isset($value)) return array('error'=>'Unsupported value'); 383 | 384 | $command = '/command/floodlight_set_config?config='; 385 | $config = '{"mode":"'.$value.'"}'; 386 | 387 | $url = $camera['vpn'].$command.urlencode($config); 388 | $response = file_get_contents($url, false); 389 | 390 | $jsonDatas = json_decode($response, true); 391 | return $jsonDatas; 392 | } 393 | 394 | public function setMonitoring($camName, $mode='on') //Presence - Welcome 395 | { 396 | if ( is_string($camName) ) $camera = $this->getCamByName($camName); 397 | if ( isset($camera['error']) ) return $camera; 398 | 399 | $value = null; 400 | if (in_array($mode, array('on', '1', 1, true), true)) $value = 'on'; 401 | if (in_array($mode, array('off', '0', 0, false), true)) $value = 'off'; 402 | if (!isset($value)) return array('error'=>'Unsupported value'); 403 | 404 | if ($camera['status'] == $value) return array('error'=>'Camera ever in status '.$value); 405 | 406 | $command = '/command/changestatus?status='.$value; 407 | $url = $camera['vpn'].$command; 408 | 409 | $response = file_get_contents($url, false); 410 | 411 | $jsonDatas = json_decode($response, true); 412 | return $jsonDatas; 413 | } 414 | 415 | public function setLightIntensity($camName, $intensity=100) //Presence 416 | { 417 | if ( is_string($camName) ) $camera = $this->getCamByName($camName); 418 | if ( isset($camera['error']) ) return $camera; 419 | 420 | if ($camera['type'] != 'Presence') return array('result'=>null, 'error' => 'Unsupported camera for setLightIntensity()'); 421 | 422 | $intensity = intval($intensity); 423 | if ($intensity > 100 or $intensity < 0) return array('result'=>null, 'error' => 'Presence Light use intensity range from 0 to 100'); 424 | 425 | $config = '{"intensity":"'.$intensity.'"}'; 426 | $command = '/command/floodlight_set_config?config='; 427 | $url = $camera['vpn'].$command.urlencode($config); 428 | 429 | $response = file_get_contents($url, false); 430 | 431 | $jsonDatas = json_decode($response, true); 432 | return $jsonDatas; 433 | } 434 | 435 | public function setSirenStatus($camName, $status=0) //Presence 436 | { 437 | if ( is_string($camName) ) $camera = $this->getCamByName($camName); 438 | if ( isset($camera['error']) ) return $camera; 439 | 440 | if ($camera['type'] != 'Presence') return array('result'=>null, 'error' => 'Unsupported camera for setLightIntensity()'); 441 | 442 | $setStatus = false; 443 | if ($status == 0 || $status === false) { 444 | $setStatus = "no_sound"; 445 | } 446 | if ($status == 1 || $status === true) { 447 | $setStatus = "sound"; 448 | } 449 | if (!$setStatus) return array('result'=>null, 'error' => 'Unsupported siren status for setSirenStatus()'); 450 | 451 | $url = 'https://app.netatmo.net/syncapi/v1/setstate?access_token='.$this->_accesstoken; 452 | $postdata = http_build_query( 453 | array( 454 | 'home' => array( 455 | 'id' => $this->_homerealID, 456 | 'modules' => array( 457 | array( 458 | 'id' => $camera['id'], 459 | 'siren_status' => $setStatus 460 | ) 461 | ) 462 | ), 463 | 'app_identifier' => 'app_security' 464 | ) 465 | ); 466 | 467 | $opts = array('http' => 468 | array( 469 | 'method' => 'POST', 470 | 'header' => 'Content-type: application/x-www-form-urlencoded;charset=UTF-8'."\r\n". 471 | 'User-Agent: netatmoclient', 472 | 'content' => $postdata 473 | ) 474 | ); 475 | $context = stream_context_create($opts); 476 | $response = @file_get_contents($url, false, $context); 477 | $jsonDatas = json_decode($response, true); 478 | return $jsonDatas; 479 | } 480 | 481 | //COMMON: 482 | public function getHomes() 483 | { 484 | $api_url = $this->_apiurl.'/api/gethomedata?access_token=' . $this->_accesstoken .'&size=0'; 485 | $response = file_get_contents($api_url, false); 486 | 487 | $jsonDatas = json_decode($response, true); 488 | $homes = $jsonDatas['body']['homes']; 489 | 490 | $n = count($homes); 491 | $datas = []; 492 | for ($i = 0; $i < $n; $i++) { 493 | $data = [ 494 | 'ID' => $i, 495 | 'name' => $homes[$i]['name'], 496 | 'place' => $homes[$i]['place'], 497 | 'cameras' => count($homes[$i]['cameras']) 498 | ]; 499 | 500 | array_push($datas, $data); 501 | } 502 | return $datas; 503 | } 504 | 505 | 506 | //for sake of retro-compatibility: 507 | public function getPresenceCameras() 508 | { 509 | $camArray = array(); 510 | foreach ($this->_cameras as $camera) { 511 | if ($camera['type'] == 'Presence') $camArray[$camera['name']] = $camera; 512 | } 513 | return $camArray; 514 | } 515 | 516 | public function getWelcomeCameras() 517 | { 518 | $camArray = array(); 519 | foreach ($this->_cameras as $camera) { 520 | if ($camera['type'] == 'Welcome') $camArray[$camera['name']] = $camera; 521 | } 522 | return $camArray; 523 | } 524 | 525 | public function getDoorbells() 526 | { 527 | $camArray = array(); 528 | foreach ($this->_cameras as $camera) { 529 | if ($camera['type'] == 'Doorbell') $camArray[$camera['name']] = $camera; 530 | } 531 | return $camArray; 532 | } 533 | 534 | //WEBHOOK: 535 | public function setWebhook($endpoint) 536 | { 537 | $api_url = $this->_apiurl.'/api/addwebhook?access_token=' . $this->_accesstoken . '&url='.$endpoint.'&app_type=app_security'; 538 | $requete = @file_get_contents($api_url); 539 | $jsonDatas = json_decode($requete,true); 540 | return $jsonDatas; 541 | } 542 | 543 | public function dropWebhook() 544 | { 545 | $api_url = $this->_apiurl.'/api/dropwebhook?access_token=' . $this->_accesstoken .'&app_type=app_security'; 546 | $requete = @file_get_contents($api_url); 547 | $jsonDatas = json_decode($requete,true); 548 | return $jsonDatas; 549 | } 550 | 551 | 552 | //internal functions================================================== 553 | protected function getCamByName($name) //Presence - Welcome 554 | { 555 | foreach ($this->_cameras as $thisCamera) 556 | { 557 | if ($thisCamera['name'] == $name) return $thisCamera; 558 | } 559 | return array('result'=>null, 'error' => 'Unfound camera'); 560 | } 561 | 562 | protected function getCamerasDatas($eventNum=50) //request full Presence/Welcome datas 563 | { 564 | $api_url = $this->_apiurl.'/api/gethomedata?access_token=' . $this->_accesstoken .'&size='.$eventNum; 565 | $response = file_get_contents($api_url, false); 566 | 567 | $jsonDatas = json_decode($response, true); 568 | $this->_camerasDatas = $jsonDatas; 569 | if (isset($jsonDatas['body']['homes'][$this->_homeID])) 570 | { 571 | $this->_home = $jsonDatas['body']['homes'][$this->_homeID]['name']; 572 | $this->_homerealID = $jsonDatas['body']['homes'][$this->_homeID]['id']; 573 | if( isset($jsonDatas['body']['homes'][$this->_homeID]['place']['timezone']) ) $this->_timezone = $jsonDatas['body']['homes'][$this->_homeID]['place']['timezone']; 574 | return $jsonDatas; 575 | } 576 | else 577 | { 578 | $this->error = 'Unfound home with ID '.$this->_homeID; 579 | return false; 580 | } 581 | 582 | } 583 | 584 | protected function getWeatherDatas() //request full weather datas 585 | { 586 | $api_url = 'https://api.netatmo.com/api/getstationsdata?access_token=' . $this->_accesstoken; 587 | $response = file_get_contents($api_url, false); 588 | $jsonDatas = json_decode($response, true); 589 | $this->_weatherDatas = $jsonDatas; 590 | if( isset($jsonDatas['body']['devices'][$this->_homeID]['place']['timezone']) ) $this->_timezone = $jsonDatas['body']['devices'][$this->_homeID]['place']['timezone']; 591 | return $jsonDatas; 592 | } 593 | 594 | protected function getCameras() 595 | { 596 | if (is_null($this->_camerasDatas)) $this->getCamerasDatas(); 597 | $allCameras = array(); 598 | 599 | if (!isset($this->_camerasDatas['body']['homes'][$this->_homeID])) return false; 600 | 601 | foreach ($this->_camerasDatas['body']['homes'][$this->_homeID]['cameras'] as $thisCamera) 602 | { 603 | //live and snapshots: 604 | $cameraVPN = (isset($thisCamera['vpn_url']) ? $thisCamera['vpn_url'] : null); 605 | $isLocal = (isset($thisCamera['is_local']) ? $thisCamera['is_local'] : false); 606 | 607 | $cameraSnapshot = null; 608 | $cameraLive = null; 609 | 610 | if ($cameraVPN != null) 611 | { 612 | $cameraLive = ($isLocal == false ? $cameraVPN.'/live/index.m3u8' : $cameraVPN.'/live/index_local.m3u8'); 613 | $cameraSnapshot = $cameraVPN.'/live/snapshot_720.jpg'; 614 | } 615 | 616 | //which camera model: 617 | if ($thisCamera['type'] == 'NOC') //Presence 618 | { 619 | $camera = array('name' => $thisCamera['name'], 620 | 'id' => $thisCamera['id'], 621 | 'vpn' => $cameraVPN, 622 | 'snapshot' => $cameraSnapshot, 623 | 'live' => $cameraLive, 624 | 'status' => $thisCamera['status'], 625 | 'sd_status' => $thisCamera['sd_status'], 626 | 'alim_status' => $thisCamera['alim_status'], 627 | 'light_mode_status' => $thisCamera['light_mode_status'], 628 | 'is_local' => $isLocal, 629 | 'siren_status' => (isset($thisCamera['siren_status']) ? $thisCamera['siren_status'] : false), 630 | 'last_setup' => $thisCamera['last_setup'], 631 | 'type' => 'Presence' 632 | ); 633 | 634 | array_push($allCameras, $camera); 635 | } 636 | elseif ($thisCamera['type'] == 'NACamera') //Welcome: 637 | { 638 | $camera = array('name' => $thisCamera['name'], 639 | 'id' => $thisCamera['id'], 640 | 'vpn' => $cameraVPN, 641 | 'snapshot' => $cameraSnapshot, 642 | 'status' => $thisCamera['status'], 643 | 'sd_status' => $thisCamera['sd_status'], 644 | 'alim_status' => $thisCamera['alim_status'], 645 | 'is_local' => $isLocal, 646 | 'last_setup' => $thisCamera['last_setup'], 647 | 'type' => 'Welcome' 648 | ); 649 | 650 | array_push($allCameras, $camera); 651 | } 652 | elseif ($thisCamera['type'] == 'NDB') //Doorbell: 653 | { 654 | $camera = array('name' => $thisCamera['name'], 655 | 'id' => $thisCamera['id'], 656 | 'vpn' => $cameraVPN, 657 | 'snapshot' => $cameraSnapshot, 658 | 'status' => $thisCamera['status'], 659 | 'sd_status' => $thisCamera['sd_status'], 660 | 'alim_status' => $thisCamera['alim_status'], 661 | 'is_local' => $isLocal, 662 | 'type' => 'Doorbell' 663 | ); 664 | 665 | array_push($allCameras, $camera); 666 | } 667 | } 668 | $this->_cameras = $allCameras; 669 | } 670 | 671 | public function getPersons() //Welcome 672 | { 673 | if (is_null($this->_camerasDatas)) $this->getCamerasDatas(); 674 | $homeDatas = $this->_camerasDatas; 675 | 676 | $personsArray = array(); 677 | if ( isset($homeDatas['body']['homes'][$this->_homeID]['persons']) ) 678 | { 679 | $persons = $homeDatas['body']['homes'][$this->_homeID]['persons']; 680 | foreach ($persons as $person) 681 | { 682 | //echo "
person:
".json_encode($person, JSON_PRETTY_PRINT)."

"; 683 | $thisPerson = array(); 684 | $pseudo = 'Unknown'; 685 | if ( isset($person['pseudo']) ) $pseudo = $person['pseudo']; 686 | $thisPerson['pseudo'] = $pseudo; 687 | $thisPerson['id'] = $person['id']; 688 | $lastseen = $person['last_seen']; 689 | if ($lastseen == 0) $thisPerson['last_seen'] = 'Been long'; 690 | else $thisPerson['last_seen'] = date("d-m-Y H:i:s", $person['last_seen']); 691 | $thisPerson['out_of_sight'] = $person['out_of_sight']; 692 | if ( isset($person['is_arrival']) ) $thisPerson['is_arrival'] = $person['is_arrival']; 693 | array_push($personsArray, $thisPerson); 694 | } 695 | 696 | $this->_persons = $personsArray; 697 | return $personsArray; 698 | } 699 | else return array('None'); 700 | } 701 | 702 | protected function getPersonByName($name) //Welcome 703 | { 704 | if (empty($this->_persons)) return array('result'=>null, 'error' => 'No person defined in this home.'); 705 | 706 | foreach ($this->_persons as $thisPerson) 707 | { 708 | if ($thisPerson['pseudo'] == $name) return $thisPerson; 709 | } 710 | return array('result'=>null, 'error' => 'Unfound person'); 711 | } 712 | 713 | //home: 714 | public $_home; 715 | public $_timezone; 716 | 717 | //API: 718 | public $error; 719 | public $_homeID; 720 | public $_homerealID; 721 | 722 | //devices: 723 | public $_cameras = []; //both Presences and Welcome 724 | public $_persons = []; 725 | 726 | //datas: 727 | protected $_camerasDatas; 728 | protected $_weatherDatas; 729 | 730 | protected $_apiurl = 'https://api.netatmo.com/'; 731 | protected $_Netatmo_app_id; 732 | protected $_Netatmo_app_secret; 733 | public $_accesstoken; 734 | public $_refreshtoken; 735 | 736 | protected $tokenFilePath = 'refreshtoken.txt'; 737 | 738 | public function connect() 739 | { 740 | $token_url = $this->_apiurl.'/oauth2/token'; 741 | $postdata = http_build_query( 742 | array( 743 | 'grant_type' => 'refresh_token', 744 | 'client_id' => $this->_Netatmo_app_id, 745 | 'client_secret' => $this->_Netatmo_app_secret, 746 | 'refresh_token' => $this->_refresh_token 747 | ) 748 | ); 749 | $opts = array('http' => 750 | array( 751 | 'method' => 'POST', 752 | 'header' => 'Content-type: application/x-www-form-urlencoded;charset=UTF-8'."\r\n". 753 | 'User-Agent: netatmoclient', 754 | 'content' => $postdata 755 | ) 756 | ); 757 | $context = stream_context_create($opts); 758 | 759 | $response = @file_get_contents($token_url, false, $context); 760 | 761 | //netatmo server sometimes give 500, always works second time: 762 | if ($response === false) { 763 | $response = @file_get_contents($token_url, false, $context); 764 | if ($response === false) { 765 | $this->error = "Can't connect to Netatmo Server."; 766 | return false; 767 | } 768 | } 769 | $jsonDatas = json_decode($response, true); 770 | if (isset($jsonDatas['refresh_token'])) 771 | { 772 | file_put_contents($this->tokenFilePath, $jsonDatas['refresh_token']); 773 | $this->_refreshtoken = $jsonDatas['refresh_token']; 774 | $this->_accesstoken = $jsonDatas['access_token']; 775 | return true; 776 | } 777 | else 778 | { 779 | $this->error = "Can't get Netatmo token."; 780 | return false; 781 | } 782 | 783 | return true; 784 | } 785 | 786 | function __construct($Netatmo_app_id, $Netatmo_app_secret, $homeID=0) 787 | { 788 | $this->_Netatmo_app_id = $Netatmo_app_id; 789 | $this->_Netatmo_app_secret = $Netatmo_app_secret; 790 | 791 | if (file_exists($this->tokenFilePath)) { 792 | $this->_refresh_token = file_get_contents($this->tokenFilePath); 793 | } 794 | else 795 | { 796 | $this->error = "No refreshtoken file."; 797 | return false; 798 | } 799 | 800 | $this->_homeID = $homeID; 801 | $var = $this->connect(); 802 | if ($var == true) 803 | { 804 | $this->getWeatherDatas(); 805 | $this->getCameras(); 806 | $this->getPersons(); 807 | } 808 | } 809 | }//splNetatmoAPI end 810 | ?> --------------------------------------------------------------------------------