Giter Site home page Giter Site logo

php-simplenetatmoapi's Introduction

php-simpleNetatmoAPI

Simple php API to get data from your Netatmo devices.

Supported devices

  • Netatmo Weather Station
  • Netatmo Presence Cameras
  • Netatmo Welcome Cameras
  • Netatmo Doorbell

This is a simple stand-alone API to get your Netatmo devices data in a more easy and more readable way.

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!

Need to setup a Netatmo callback ? Check here

Requirements

If you don't have Netatmo App yet, just create one, it's simple and free:

In your app, check Token generator section: enter all needed scopes, then hit Generate Token

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!

If you need to have this file in different folders you can try that:

require($_SERVER['DOCUMENT_ROOT']."/path/to/splNetatmoAPI.php");
chdir('/path/to/token/'); //for refreshtoken api file path
$_splNetatmo = new splNetatmoAPI($Netatmo_app_id, $Netatmo_app_secret);

How-to

All functions return a json array, you can echo it to see which key to get.

Initialize:

require($_SERVER['DOCUMENT_ROOT']."/path/to/splNetatmoAPI.php");
$_splNetatmo = new splNetatmoAPI($Netatmo_app_id, $Netatmo_app_secret);
if (isset($_splNetatmo->error)) die($_splNetatmo->error);

If you have several homes, you can specify a homeID as last argument.

require($_SERVER['DOCUMENT_ROOT']."/path/to/splNetatmoAPI.php");
$_splNetatmo = new splNetatmoAPI($Netatmo_app_id, $Netatmo_app_secret, 1);
if (isset($_splNetatmo->error)) die($_splNetatmo->error);

//You can also check homes configured on your account to connect to the right one
//It will return all homes with name, id and camera number found.
$homes = $_splNetatmo->getHomes();
echo "<pre><br>homes:<br>".json_encode($homes, JSON_PRETTY_PRINT)."</pre><br>";

Weather Station:

//get module datas by its name:
$getWeatherModuleDatas = $_splNetatmo->getWeatherModuleDatas('Exterieur');
echo "<pre>getWeatherModuleDatas:<br>".json_encode($getWeatherModuleDatas, JSON_PRETTY_PRINT)."</pre><br>";

//get all temperatures from all modules:
$getWeatherTemperatures = $_splNetatmo->getWeatherTemperatures();
echo "<pre>getWeatherTemperatures:<br>".json_encode($getWeatherTemperatures, JSON_PRETTY_PRINT)."</pre><br>";
echo $getWeatherTemperatures['Exterieur'];

//get all modules batteries:
//If you specify a number under 100, it will return only modules under this number so you can get low batteries modules.
$getWeatherBatteries = $_splNetatmo->getWeatherBatteries();
echo "<pre>getWeatherBatteries:<br>".json_encode($getWeatherBatteries, JSON_PRETTY_PRINT)."</pre><br>";

//get all modules firmwares versions:
$getWeatherFirmVer = $_splNetatmo->getWeatherFirmVer();
echo "<pre>getWeatherFirmVer:<br>".json_encode($getWeatherFirmVer, JSON_PRETTY_PRINT)."</pre><br>";

//get all modules radio signal statut:
$getWeatherRFs = $_splNetatmo->getWeatherRFs();
echo "<pre>getWeatherRFs:<br>".json_encode($getWeatherRFs, JSON_PRETTY_PRINT)."</pre><br>";

Netatmo Cameras:

Get some datas:

Change camera name by yours!

//get all Presence cameras datas:
$Cameras = $_splNetatmo->getPresenceCameras();
echo "<pre>Cameras:<br>".json_encode($Cameras, JSON_PRETTY_PRINT)."</pre><br>";
echo "<pre>light_mode: ".json_encode($Cameras['Cam_Terrasse']['light_mode_status'], JSON_PRETTY_PRINT)."</pre><br>";

//get 10 last event of defined type:
//can request 'human', 'animal', 'vehicle', 'movement', 'All'
$events = $_splNetatmo->getOutdoorEvents('All', 10);
echo "<pre>events:<br>".json_encode($events, JSON_PRETTY_PRINT)."</pre><br>";

//get all Welcome cameras datas:
$Cameras = $_splNetatmo->getWelcomeCameras();
echo "<pre>Cameras:<br>".json_encode($Cameras, JSON_PRETTY_PRINT)."</pre><br>";

//get 10 last indoor events:
$events = $_splNetatmo->getIndoorEvents(10);
echo "<pre>events:<br>".json_encode($events, JSON_PRETTY_PRINT)."</pre><br>";

//get all persons at home:
$atHome = $_splNetatmo->getPersonsAtHome();
echo "<pre>atHome :<br>".json_encode($atHome , JSON_PRETTY_PRINT)."</pre><br>";

//get John datas:
$John = $_splNetatmo->getPerson('John');
echo "<pre>John :<br>".json_encode($John , JSON_PRETTY_PRINT)."</pre><br>";

//is home empty ?
echo $_splNetatmo->isHomeEmpty();

Change some settings:

Change camera name by yours!

//You can also get return value to know if all went fine.

//set John away from home:
$_splNetatmo->setPersonAway('John');

//set home empty:
$_splNetatmo->setHomeEmpty();

//set person(s) at home:
$_splNetatmo->setPersonsAtHome('John');
$_splNetatmo->setPersonsAtHome(['John','William']);

//change Presence light intensity:
$_splNetatmo->setLightIntensity('MyCam', 85);

//change Presence Light mode (use either 'auto', 'on', 'off':
$_splNetatmo->setLightMode('MyCam', 'auto');

//change Presence or Welcome monitoring (use either 'on', 'off':
$_splNetatmo->setMonitoring('MyCam', 'on');

Setting/dropping webhooks:

//set webhook:
$endpoint = 'http://www.mydomain.com/myscripts/myPresenceWebhook.php';
$answer = $_splNetatmo->setWebhook($endpoint);
print_r($answer);

//drop webhook:
$_splNetatmo->dropWebhook();

Need to setup a Netatmo callback ? Check here

Changes

v3.0 (2023-05-12)

  • Fix: refresh token to file, thanks to stupid Netatmo decision! See Requirements

v1.7 (2022-04-25)

  • New: setSirenStatus() example: $_splNetatmo->setSirenStatus('MyCam', true);

v1.65 (2021-06-20)

  • report Presence siren status

v1.6 (2021-03-07)

  • Support doorbell

v1.4 (2018-06-13)

  • New: setPersonsAtHome()
  • Fix: setMonitoring() for Welcome cameras

v1.32 (2018-01-29)

  • Fix: isHomeEmpty()

v1.31 (2017-11-29)

  • New: getHomes() return all found homes with their id and name
  • New: pass home id as last argument: new splNetatmoAPI($user, $pass, $app_id, $app_secret, 1);

v1.3 (2017-11-18)

  • New: setMonitoring('camName', 'on')
  • New: setLightMode('camName', 'auto')
  • New: setLightIntensity('camName', 100)

v1.2 (2017-05-24)

  • New: Welcome cameras support!
  • Warning: check Presence functions for name changes.

v1.0 (2017-03-24)

  • First public version.

License

The MIT License (MIT)

Copyright (c) 2017 KiboOst

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sub-license, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

php-simplenetatmoapi's People

Contributors

cadkey avatar kiboost avatar kokluch avatar zainjar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-simplenetatmoapi's Issues

Fonction pour récupérer l'intensité lumineuse caméra Presence

Bonjour,

Serait-il possible d'ajouter une fonction pour récupérer l'intensité lumineuse d'une caméra Presence ?
Ne connaissant pas du tout le PHP, j'ai tout de même tenté de le faire moi-même en me basant sur la fonction getWeatherBatteries mais sans succès...

Merci d'avance.

damanujan/php-NetatmoCameraAPI vs KiboOst/php-simpleNetatmoAPI

Bonjour,

D'après ce que je comprends vous avez participé à "php-NetatmoCameraAPI".
Mon projet est juste de commander le projecteur de ma "Présence" depuis ma Home Center 2 Fibaro comme le fait SIRI via l'application Homekit. Je suis au bon endroit ?

Et merci pour le job accompli !!

Have a good day - Jean-Paul

Not an issue: I added 2 more funktion for CO2 and humidity

Hello, I never used Github, I don't know how to propose new content. Thank you for your simple API.

I added 2 new function to splNetatmoAPI.php, it's mostly copy&paste but it can spare a few Minutes to someone:

public function getWeatherHumidity()
    {
        if (is_null($this->_weatherDatas)) $this->getWeatherDatas();

        $modules = $this->_weatherDatas['body']['devices'][0]['modules'];

        $jsonDatas = array();
        foreach ($modules as $module)
        {
            if (!isset($module['dashboard_data']['Humidity'])) continue;

            $name = $module['module_name'];
            $humidity = $module['dashboard_data']['Humidity'];
            $jsonDatas[$name] = $humidity;
        }
        //add main station:
        $jsonDatas[ $this->_weatherDatas['body']['devices'][0]['station_name'] ] = $this->_weatherDatas['body']['devices'][0]['dashboard_data']['Humidity'];
        return $jsonDatas;
    }

    public function getWeatherCO2()
    {
        if (is_null($this->_weatherDatas)) $this->getWeatherDatas();

        $modules = $this->_weatherDatas['body']['devices'][0]['modules'];

        $jsonDatas = array();
        foreach ($modules as $module)
        {
            if (!isset($module['dashboard_data']['CO2'])) continue;

            $name = $module['module_name'];
            $co2 = $module['dashboard_data']['CO2'];
            $jsonDatas[$name] = $co2;
        }
        //add main station:
        $jsonDatas[ $this->_weatherDatas['body']['devices'][0]['station_name'] ] = $this->_weatherDatas['body']['devices'][0]['dashboard_data']['CO2'];
        
		return $jsonDatas;
    }

and you can use it easily with:

$getWeatherHumudity = $_splNetatmo->getWeatherHumidity();
echo "Humidity:".str_replace('"','',json_encode($getWeatherHumudity, JSON_PRETTY_PRINT));

$getWeatherCO2 = $_splNetatmo->getWeatherCO2();
echo "CO2:".str_replace('"','',json_encode($getWeatherCO2, JSON_PRETTY_PRINT));

Can't connect to Netatmo Server

I get this error direct after initialising. Just at testing to connect.

So splNetatmoAPI.php is found and included. I have entered variables for Netatmo_user, pass, id and secret in front of the initial $_splNetatmo = new splNetatmoAPI call.

ID and Secret is newly created at Netatmo Server.
What do I wrong?

Not an issue, just a thank you

Hi, didn't find a contact address so I just wanted to tell you that your simpleNetatmo API helped me to start with getting data from my Netatmo weather station.

I intend to query my Netatmo data periodically and forward it to OpenWeatherMap as my OpenSprinkler system needs weather data which were transferred to wunderground in the past but Netatmo does no longer support this data transfer. As OpenWeatherMap is also supported I trying to setup a data forwarder on my Synology NAS at home.

Demande d'info

Bonjour, @KiboOst

Je cherche a faire fonctionner ce script sur jeedom mais je ne comprend pas comment faire.
J'ai cherche sur le forum mais rien vu de probant ?.
Aurait tu un lien vers un tuto ou autre ?

Merci pour ton retour.

function getLightIntensity

Hi,

thank you very much for this great software.
Is it possible to create a function getLightIntensity?
Background: i wish to use a remotecontrol to decrease od increase the intensity.

Greetings
Kaloschke

Netatmo change authentification

Hi KiboOst,
Do you work on an update of your script to take under considération the Netatmo authentification change ?
Tx

Ask question about authorization

Hi

Is script is valid with the new authorisation of netatmo (begin oct 2022) ?

Regards

Bonjour

Est ce que ce script va fonctionner avec la nouvelle api d'authorisation imposé par netatmo en octobre 2022 ?

Cordialement

description missing

Where to fill in "client_id" and "client_secret" within the PHP (what line & where) ?
Can you please be more precise.
Thanks in Advance

authentification Netatmo modifié depuis hier midi

J'ai tenté de solutionner.
Je stocke access_token et refresh_token dans un json. La Doc dit que la durée de vie est de 3h mais je constate que le couple access_token refresh_token ne fonctionne qu'une fois et génère quand même des erreurs régulièrement.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.