KiboOst / php-simpleNetatmoAPI

Need a simple way to get your Netatmo Presence datas with a few lines of php? Here you are!
MIT License
35 stars 9 forks source link

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

Open Raftanel opened 1 year ago

Raftanel commented 1 year ago

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));
Semabeba commented 11 months ago

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));

Hello, and for the Pressure? Do you know how we can have it, please?