RE: Netatmo - Slok - 15.10.2017
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.
RE: Netatmo - Evens - 14.10.2018
Hi, does this Integration to Netatmo still work?
If not, is there any other way to read data from Netatmo?
BR Even Sundgot.
RE: Netatmo - Matt - 20.10.2018
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
RE: Netatmo - Peter - 29.12.2018
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?
RE: Netatmo - paalidar - 30.01.2019
okay, so I followed the recipe, how am I able to use those data as objects?
RE: Netatmo - Matt - 30.01.2019
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.
RE: Netatmo - paalidar - 30.01.2019
(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
RE: Netatmo - Erwin van der Zwart - 30.01.2019
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..
RE: Netatmo - victor.back - 26.09.2020
Hi.
Is this still working? I cannot create the private app from "http://dev.netatmo.com"
Its nothing that appears from that link.
RE: Netatmo - pioneersteffen - 14.09.2021
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
RE: Netatmo - Daniel - 15.09.2021
Add before refresh_netamo call to your library by adding require('user.netamo')
RE: Netatmo - pioneersteffen - 15.09.2021
Many thanks! That was the problem! Now it works!
RE: Netatmo - stemic01 - 10.02.2022
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?
RE: Netatmo - Erwin van der Zwart - 11.02.2022
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)
RE: Netatmo - stemic01 - 11.02.2022
Thanks a lot. I'll check it in the weekend.
RE: Netatmo - iridium - 13.07.2023
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"
RE: Netatmo - gjniewenhuijse - 13.07.2023
(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"}
RE: Netatmo - admin - 14.07.2023
Maybe there are some changes in their API. Try contacting Netatmo support.
RE: Netatmo - gjniewenhuijse - 14.07.2023
(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.
RE: Netatmo - gjniewenhuijse - 17.07.2023
- 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
|