netatmo

package module
v0.0.0-...-7ab465f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2016 License: MIT Imports: 7 Imported by: 0

README

netatmo-api-go

Simple API to access Netatmo weather station data written in Go.

Currently tested only with one weather station, outdoor and indoor modules. Let me know if it works with rain or wind gaude.

Quickstart

  • Create a new netatmo app
  • Download module go get github.com/exzz/netatmo-api-go
  • Try below example (do not forget to edit auth credentials)

Example

import (
  "fmt"
  "os"

  "github.com/exzz/netatmo-api-go"
)

func main() {

  n, err := netatmo.NewClient(netatmo.Config{
    ClientID:     "YOUR_APP_ID",
    ClientSecret: "YOUR_APP_SECRET",
    Username:     "YOUR_CREDENTIAL",
    Password:     "YOUR_PASSWORD",
  })
  if err != nil {
    fmt.Println(err)
    os.Exit(1)
  }

  dc, err := n.GetDeviceCollection()
  if err != nil {
    fmt.Println(err)
    os.Exit(1)
  }

  for _, station := range dc.Stations() {
    fmt.Printf("Station : %s\n", station.StationName)

    for _, module := range station.Modules() {
      fmt.Printf("\tModule : %s\n", module.ModuleName)

      ts, data := module.Data()
      for dataType, value := range data {
        fmt.Printf("\t\t%s : %s (%d)\n", dataType, value, ts)
      }
    }
  }
}

Output should look like this :

Station : Home
  Module : Outside
    Temperature : %!s(float32=20.2) (1440302379)
    Humidity : %!s(int32=86) (1440302379)
  Module : Bedroom 1
    CO2 : %!s(int32=500) (1441981664)
    Humidity : %!s(int32=69) (1441981664)
    Temperature : %!s(float32=21.2) (1441981664)
  Module : Bedroom 2
    Temperature : %!s(float32=21) (1441981632)
    CO2 : %!s(int32=508) (1441981632)
    Humidity : %!s(int32=68) (1441981632)
  Module : Living room
    Temperature : %!s(float32=22.1) (1441981633)
    CO2 : %!s(int32=516) (1441981633)
    Humidity : %!s(int32=67) (1441981633)
  Module : Dining room
    Humidity : %!s(int32=75) (1441982895)
    Noise : %!s(int32=36) (1441982895)
    Pressure : %!s(float32=1015.9) (1441982895)
    Temperature : %!s(float32=21.5) (1441982895)
    CO2 : %!s(int32=582) (1441982895)

Tips

  • Only GetDeviceCollection() method actually do an API call and refresh all data at once
  • Main station is handle as a module, it means that Modules() method returns list of additional modules and station itself.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client use to make request to Netatmo API ClientID : Client ID from netatmo app registration at http://dev.netatmo.com/dev/listapps ClientSecret : Client app secret Username : Your netatmo account username Password : Your netatmo account password Stations : Contains all Station account

func NewClient

func NewClient(config Config) (*Client, error)

NewClient create a handle authentication to Netamo API

func (*Client) GetDeviceCollection

func (c *Client) GetDeviceCollection() (*DeviceCollection, error)

GetDeviceCollection returns the list of stations owned by the user, and their modules

type Config

type Config struct {
	ClientID     string
	ClientSecret string
	Username     string
	Password     string
}

Config is used to specify credential to Netatmo API ClientID : Client ID from netatmo app registration at http://dev.netatmo.com/dev/listapps ClientSecret : Client app secret Username : Your netatmo account username Password : Your netatmo account password

type DashboardData

type DashboardData struct {
	Temperature      float32 `json:"Temperature,omitempty"`
	Humidity         int32   `json:"Humidity,omitempty"`
	CO2              int32   `json:"CO2,omitempty"`
	Noise            int32   `json:"Noise,omitempty"`
	Pressure         float32 `json:"Pressure,omitempty"`
	AbsolutePressure float32 `json:"AbsolutePressure,omitempty"`
	Rain             float32 `json:"Rain,omitempty"`
	Rain1Hour        float32 `json:"sum_rain_1,omitempty"`
	Rain1Day         float32 `json:"sum_rain_24,omitempty"`
	WindAngle        float32 `json:"WindAngle,omitempty"`
	WindStrength     float32 `json:"WindStrength,omitempty"`
	GustAngle        float32 `json:"GustAngle,omitempty"`
	GustStrength     float32 `json:"GustStrength,omitempty"`
	LastMeasure      float64 `json:"time_utc"`
}

DashboardData is used to store sensor values Temperature : Last temperature measure @ LastMeasure (in °C) Humidity : Last humidity measured @ LastMeasure (in %) CO2 : Last Co2 measured @ time_utc (in ppm) Noise : Last noise measured @ LastMeasure (in db) Pressure : Last Sea level pressure measured @ LastMeasure (in mb) AbsolutePressure : Real measured pressure @ LastMeasure (in mb) Rain : Last rain measured (in mm) Rain1Hour : Amount of rain in last hour Rain1Day : Amount of rain today WindAngle : Current 5 min average wind direction @ LastMeasure (in °) WindStrength : Current 5 min average wind speed @ LastMeasure (in km/h) GustAngle : Direction of the last 5 min highest gust wind @ LastMeasure (in °) GustStrength : Speed of the last 5 min highest gust wind @ LastMeasure (in km/h) LastMessage : Contains timestamp of last data received

type Device

type Device struct {
	ID                string `json:"_id"`
	StationName       string `json:"station_name"`
	ModuleName        string `json:"module_name"`
	Type              string
	DashboardData     DashboardData `json:"dashboard_data"`
	DataType          []string      `json:"data_type"`
	MainDevice        string        `json:"main_device,omitempty"`
	AssociatedModules []*Device     `json:"-"`
}

Device is a station or a module ID : Mac address StationName : Station name (only for station) ModuleName : Module name Type : Module type :

"NAMain" : for the base station
"NAModule1" : for the outdoor module
"NAModule4" : for the additionnal indoor module
"NAModule3" : for the rain gauge module
"NAModule2" : for the wind gauge module

DashboardData : Data collection from device sensors DataType : List of available datas MainDevice : Id of main station (only for module) AssociatedModules : Associated modules (only for station)

func (*Device) Data

func (s *Device) Data() (int, map[string]interface{})

Data returns timestamp and the list of sensor value for this module

func (*Device) Modules

func (s *Device) Modules() []*Device

Modules returns the list of modules associated to this station also return station itself in the list

type DeviceCollection

type DeviceCollection struct {
	Body struct {
		Stations []*Device `json:"devices"`
		Modules  []*Device
	}
}

DeviceCollection hold all devices from netatmo account (stations and modules) Error : returned error (nil if OK) Stations : List of stations Modules : List of additionnal modules

func (*DeviceCollection) Stations

func (dc *DeviceCollection) Stations() []*Device

Stations returns the list of stations

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL