This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Netatmo
#21
Has anyone tryed to find the way how to conect to netatmos wireless valves / relay?
https://www.netatmo.com/en-US/product/energy/valves
It seems there is no API for that.Only for thermostat.

THX for answer.
Reply
#22
Hi, does this Integration to Netatmo still work?
If not, is there any other way to read data from Netatmo?

BR Even Sundgot.
Reply
#23
Please find an updated version of the script, I improved how additional modules are read.

Code:
require 'ltn12'
require 'socket.http'
json = require("json")
https = require 'ssl.https'

function refresh_netatmo()
 local netatmo_debug = true
 local client_id = "xxx"
 local client_secret = "xxx"
 local username = "xxx"
 local password = "xxx"
 local scope = "read_station"
 -- optional device_id
 local device_id = "xxx"
 local request_token_url = "https://api.netatmo.net/oauth2/token"
 local request_device_list = "https://api.netatmo.net/api/devicelist"
 local response_body = { }

 local export_data = {}

 if (netatmo_debug) then
   alert("netatmo start")
 end
 
 local request_body = "grant_type=password&client_id=" .. client_id .."&client_secret=" .. client_secret .. "&username=" .. username .. "&password=" .. password .. "&scope=" .. scope

 local body, code, hdrs, stat = https.request
 {
   url = request_token_url;
   method = "POST";
   headers =
   {
     ["Content-Type"] = "application/x-www-form-urlencoded";
     ["Content-Length"] = #request_body;
   };
   source = ltn12.source.string(request_body);
   sink = ltn12.sink.table(response_body);
 }

 if (code ~= 200) then
   alert("netatmo auth error : "..tostring(code)..","..tostring(body))
   return
 end

 local response_decode = json.decode(table.concat(response_body))
 local access_token = response_decode.access_token
 if (netatmo_debug) then
   alert("netatmo token %s",access_token)
 end


 -- request for all devices
 local request_body = "access_token=" .. access_token .. "&app_type=app_station"
 -- request to limit to only one device :
 -- local request_body = "access_token=" .. access_token .. "&app_type=app_station&device_id=" .. device_id
 
 local response_body = { }

 local body, code, hdrs, stat = https.request
 {
   url = request_device_list;
   method = "POST";
   headers =
   {
     ["Content-Type"] = "application/x-www-form-urlencoded";
     ["Content-Length"] = #request_body;
   };
   source = ltn12.source.string(request_body);
   sink = ltn12.sink.table(response_body);
 }

 if (code ~= 200) then
   alert("netatmo devicelist error : "..tostring(code)..","..tostring(body))
   return
 end

 local response_decode = json.decode(table.concat(response_body))

 -- Main module
 if (netatmo_debug) then
   alert("netatmo main module")
 end

 grp.write("netatmo temperature interieure",response_decode.body.devices[1].dashboard_data.Temperature,dt.float16)
 grp.write("netatmo humidite interieure",response_decode.body.devices[1].dashboard_data.Humidity,dt.scale)
 grp.write("netatmo pression",response_decode.body.devices[1].dashboard_data.Pressure,dt.uint16)
 grp.write("netatmo CO2",response_decode.body.devices[1].dashboard_data.CO2,dt.float16)
 grp.write("netatmo sonometre",response_decode.body.devices[1].dashboard_data.Noise,dt.uint8)
 grp.write("netatmo temperature interieure minimum",response_decode.body.devices[1].dashboard_data.min_temp,dt.float16)
 grp.write("netatmo temperature interieure maximum",response_decode.body.devices[1].dashboard_data.max_temp,dt.float16)
 grp.write("netatmo pression absolue",response_decode.body.devices[1].dashboard_data.AbsolutePressure,dt.uint16)

 grp.write("netatmo salon temperature",response_decode.body.devices[1].dashboard_data.Temperature,dt.float16)
 grp.write("netatmo salon humidite",response_decode.body.devices[1].dashboard_data.Humidity,dt.scale)
 grp.write("netatmo salon CO2",response_decode.body.devices[1].dashboard_data.CO2,dt.uint16)

 -- search for additional modules by name
 
 for index, value in ipairs(response_decode.body.modules) do
   if (netatmo_debug) then
     alert("netatmo module " .. tostring(index) .. ":" .. tostring(value.module_name))
   end
   if (value.module_name == "Pluviomètre") then
     if (netatmo_debug) then
       alert("netatmo module match pluviometre")
     end
     grp.write("netatmo pluviometre",value.dashboard_data.Rain,dt.float16)
     grp.write("netatmo pluviometre 1h",value.dashboard_data.sum_rain_1,dt.float16)
     grp.write("netatmo pluviometre 24h",value.dashboard_data.sum_rain_24,dt.float16)

   elseif (value.module_name == "Extérieur") then
     if (netatmo_debug) then
       alert("netatmo module match exterieur")
     end
     grp.write("netatmo temperature exterieure",value.dashboard_data.Temperature,dt.float16)
     grp.write("netatmo humidite exterieure",value.dashboard_data.Humidity,dt.float16)
     grp.write("netatmo temperature exterieure minimum",value.dashboard_data.min_temp,dt.float16)
     grp.write("netatmo temperature exterieure maximum",value.dashboard_data.max_temp,dt.float16)

   elseif (value.module_name == "Chambre") then
     if (netatmo_debug) then
       alert("netatmo module match Chambre")
     end
     grp.write("netatmo chambre temperature",value.dashboard_data.Temperature,dt.float16)
     grp.write("netatmo chambre CO2",value.dashboard_data.CO2,dt.float16)
     grp.write("netatmo chambre humidite",value.dashboard_data.Humidity,dt.scale)
   
   elseif (value.module_name == "Bureau") then
     if (netatmo_debug) then
       alert("netatmo module match Bureau")
     end
     grp.write("netatmo bureau temperature",value.dashboard_data.Temperature,dt.float16)
     grp.write("netatmo bureau CO2",value.dashboard_data.CO2,dt.float16)
     grp.write("netatmo bureau humidite",value.dashboard_data.Humidity,dt.scale)
         
   elseif (value.module_name == "Studio") then
     if (netatmo_debug) then
       alert("netatmo module match Studio")
     end
     grp.write("netatmo studio temperature",value.dashboard_data.Temperature,dt.float16)
     grp.write("netatmo studio CO2",value.dashboard_data.CO2,dt.float16)
     grp.write("netatmo studio humidite",value.dashboard_data.Humidity,dt.scale)
   
   end
 
 end

 if (netatmo_debug) then
   alert("netatmo end")
 end
 
 
end
Reply
#24
Hello Matt, thanks for the update, works great for me. Did you by any chance also try to integrate the readings for battery levels of the modules?
Reply
#25
okay, so I followed the recipe, how am I able to use those data as objects?
Reply
#26
Quote:okay, so I followed the recipe, how am I able to use those data as objects?

If you write the value to objects you should be able to see it in the object list.
You can also script anything with netatmo value as condition.
I hope this helps.
Reply
#27
(30.01.2019, 20:11)Matt Wrote:
Quote:okay, so I followed the recipe, how am I able to use those data as objects?

If you write the value to objects you should be able to see it in the object list.
You can also script anything with netatmo value as condition.
I hope this helps.

No values, no errors, no alerts
Reply
#28
Hi,

Did you create all your objects with the exact same names (including capitals) as used in line 84 to 95 and all other grp.write lines?

Try to change the names to GA’s to be sure..
Reply
#29
Hi.

Is this still working? I cannot create the private app from "http://dev.netatmo.com"
Its nothing that appears from that link.
Reply
#30
Hi @all,

many thanks for supplying this script and the description.

I implemented the script as described unfortunately no value is written. I implemented just one object to get it working and scale it afterwards, In the failure log the following message is shown:

„netatmo 14.09.2021 21:44:00
User script:1: attempt to call global 'refresh_netatmo' (a nil value)
stack traceback:
User script:1: in main chunk“

My configuration is attached, do you see any mistake and reason why it doesn’t work?

Many thanks for your help.

Best Regards
Steffen

Attached Files Thumbnail(s)
                       

Reply
#31
Add before refresh_netamo call to your library by adding require('user.netamo')
------------------------------
Ctrl+F5
Reply
#32
Many thanks! That was the problem! Now it works!  Smile
Reply
#33
API SCRIPT - WIND SPEED in Meters per Second?
Is there a simple way to change the script to show value as MS instead of km/h?
Schneider Wiser (homeLynk), Power Tags, DALI, Multitouch Pro, Panasonic Heating pump, Flexit balansed ventilation, HUE integration, Lemus Speaker system. Tibber integration.
Reply
#34
Code:
--1 km/h to m/s = 0.28 m/s
value = 1
value = math.round(value * 5/18, 2) -- 1000/3600 = ((1000/200)/(3600/200)) = 5/18
log(value)
Reply
#35
Thanks a lot. I'll check it in the weekend.
Schneider Wiser (homeLynk), Power Tags, DALI, Multitouch Pro, Panasonic Heating pump, Flexit balansed ventilation, HUE integration, Lemus Speaker system. Tibber integration.
Reply
#36
Hello. 

Do you know if there are problems with netatmo? I've been offline for two days.

I have this error: "netatmo auth error : 400.1"
Reply
#37
(13.07.2023, 09:53)iridium Wrote: Hello. 

Do you know if there are problems with netatmo? I've been offline for two days.

I have this error: "netatmo auth error : 400.1"

same problem here

response_body returns: string: {"error":"unauthorized_client"}
Reply
#38
Maybe there are some changes in their API. Try contacting Netatmo support.
Reply
#39
(14.07.2023, 08:46)admin Wrote: Maybe there are some changes in their API. Try contacting Netatmo support.

Maybe this?
Client credentials grant type
https://api.netatmo.com/oauth2/token
Method: POST

!! This method will be deprecated in october 2022 !!
If you want to access data from another user's account, you MUST use the Authorization code grant type.

Netatmo Connect | Authentication

For now i choose generate token with the right scope in de Netatmo My Apps window. This generates an access and refresh token. I used the access_token hardcoded in the script.
Reply
#40
- generate a refresh_token with the right scope in http://dev.netatmo.com under my apps and choose for Token generator
- Copy the Refresh Token to the variable refresh_token

Now every run of the function get_token refreshed the token and saved it for further use.

Code:
-- get auth token from refresh token
refresh_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
function get_token()
    refresh = storage.get('netatmo_refresh_1', refresh_token)
 
  local request_body = "grant_type=refresh_token&client_id=" .. client_id .."&client_secret=" .. client_secret .. "&refresh_token=" .. refresh

  local body, code, hdrs, stat = https.request
  {
    url = request_token_url;
    method = "POST";
    headers =
    {
      ["Content-Type"] = "application/x-www-form-urlencoded";
      ["Content-Length"] = #request_body;
    };
    source = ltn12.source.string(request_body);
    sink = ltn12.sink.table(response_body);
  }

  if (code ~= 200) then
    if (netatmo_debug) then
      log("netatmo auth error: "..tostring(code)..", "..tostring(body))
    end
    return
  end

  local response_decode = json.decode(table.concat(response_body))
  local access_token = response_decode.access_token
  if response_decode.refresh_token then
        storage.set('netatmo_refresh_1', response_decode.refresh_token)
  end
  if (netatmo_debug) then
    log(response_body)
    log("netatmo token %s",access_token)
  end
  return "access_token=" .. access_token 
end
Reply


Forum Jump: