Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Raftanel opened this issue Dec 19, 2022 · 1 comment
Open

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

Raftanel opened this issue Dec 19, 2022 · 1 comment

Comments

@Raftanel
Copy link

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
Copy link

Semabeba commented Dec 12, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants