21

Displaying the netatmo ombrometer & anemometer data in the Fibaro HC2

by boomx28. March 2016

After we have already integrated the netatmo anemometer and the netatmo welcome into the Fibaro HomeCenter 2, the ombrometer cannot be missing either. How to do it can be read below.

The script of the netatmo anemometer serves as the basis for our scene. The script is now able to request the values of both sensors, the anemometer’s, as well as the rain sensor’s, via API at the netatmo servers and save them in variables, as well as display them in a virtual device. In case you should not have one of the two devices: No problem, the script is being tested automatically and the values will then not be requested at the netatmo servers.
As far as you do not own an ombrometer yet, you can currently buy one for 62€. For instance on amazon.

New functions of the netatmo script:

  • Script does automatically recognize, which additional sensors (besides the weather station + outdoor module) are arranged and only requests the arranged sensors
  • 4 values are being requested for the amount of rainfall: hourly amount of rainfall, daily amount of rainfall, weekly amount of rainfall and monthly amount of rainfall
  • Test, if all needed variables have been arranged properly
  • Debug can be turned off
  • Bugfix: The script does not crash anymore, when the API cannot be contacted via netatmo, instead there is an error report regardless from the Debug-settings
debug_1

Debug-Window when the debug-mode is activated (debug = 1)

There is a 98 % chance of an error report when first starting it. This is, because the variables have not been arranged yet. You will be informed through the script, which variables have to be arranged via the variable-panel. They are shown in the picture. Once you have arranged the variables, the scene will go on as usual and without any changes.

A red signal will show that there are still some variables having to be arranged

A red signal will show that there are still some variables having to be arranged

netatmo script:

The only thing that has to be changed at the script is your data of the site dev.netatmo.com. In case you are wanting to use the virtual device (can be found at the end of the text) as well, you need to additionally adjust the ID of the virtual device in line 15 to your ID.

You can optionally activate or deactivate the debug-mode in line 13 (0 = deactivated; 1 = activated).

When deactivating the debug, only the following two lines will show up in the debug. The script will afterwards renew the values every 5 minutes:

Debug-window when the debug-mode is deactivated (debug = 0)

Debug-window when the debug-mode is deactivated (debug = 0)

You should not change anything at the local variable “refresh”. The data is only sent from the respective station to the netatmo servers every 5 minutes, which is why a shorter refresh-time between the requests would not make sense.

And of course, as promised, there is a matching virtual device for that. You can download it on here (simply click on the picture). You can simply import it via “Add/Remove device”. Please make sure that the file has the ending .vfib.

netatmo_VD

In case you should have further ideas to what can be done with the integration, we would be happy to read them in the comments. You can also download the two icons for the scene and the virtual device.

icon

icon for the VD

icon_refresh

Icon for the scene

About The Author
boomx
boomx
21 Comments
  • Kjell Morten Lyngvær
    29. March 2016 at 17:17

    Hi
    It will not work for me :-(
    Here is the text popping up when i try to Debug.

    [ERROR] 17:11:05: line 22: attempt to call method ‘getSourceTrigger’ (a nil value)

  • CharlesO
    4. May 2016 at 21:17

    Hi
    tks for the super VD but where is the scene you can upload sample pls

  • Lasse
    8. May 2016 at 23:51

    Cant get it to work, no data shows up in the virtual device.

    • boomx
      boomx
      9. May 2016 at 15:29

      Can you post the Debug of the scene?

      • Lasse
        9. May 2016 at 18:07

        Sorry but I don’t fully understand german..

        [DEBUG] 17:50:36: netatmo Zusatzmodul Integration v.1.2 gestartet.
        [DEBUG] 17:50:36: Daten werden alle 5 min aktualisiert. Bei debug = 0 wird nichts debuggt
        [DEBUG] 17:50:36: oAuth 2.0 durchgeführt.
        [DEBUG] 17:50:38: netatmo Sensoren werden gesucht…
        [DEBUG] 17:50:38: Regensensor 05:00:00:00:58:40 erkannt.
        [DEBUG] 17:50:38: Windmesser 05:00:00:00:58:40 erkannt.
        [DEBUG] 17:50:40: Windmesser wird ausgelesen…
        [DEBUG] 17:50:40: Windgeschwindigkeit: 2 km/h
        [DEBUG] 17:50:40: Varible windstaerke nicht gefunden. Bitte anlegen
        [DEBUG] 17:50:40: Varible windrichtung nicht gefunden. Bitte anlegen
        [DEBUG] 17:50:40: Varible boenstaerke nicht gefunden. Bitte anlegen
        [DEBUG] 17:50:40: Varible boenrichtung nicht gefunden. Bitte anlegen
        [DEBUG] 17:50:40: Windmesser auslesen beendet.
        [DEBUG] 17:50:40: Varible rain_day nicht gefunden. Bitte anlegen
        [DEBUG] 17:50:40: Regenmenge: 0 mm2 (day)

        [DEBUG] 17:50:40: Varible rain_week nicht gefunden. Bitte anlegen
        [DEBUG] 17:50:40: Regenmenge: 0 mm2 (week)

        [DEBUG] 17:50:40: Varible rain_hour nicht gefunden. Bitte anlegen
        [DEBUG] 17:50:40: Regenmenge: 0 mm2 (hour)

        [DEBUG] 17:50:40: Varible rain_month nicht gefunden. Bitte anlegen
        [DEBUG] 17:50:40: Regenmenge: 7.07 mm2 (month)

        [DEBUG] 17:55:36: oAuth 2.0 durchgeführt.
        [DEBUG] 17:55:37: netatmo Sensoren werden gesucht…
        [DEBUG] 17:55:37: Regensensor 05:00:00:00:58:40 erkannt.
        [DEBUG] 17:55:37: Windmesser 05:00:00:00:58:40 erkannt.
        [DEBUG] 17:55:38: Varible rain_hour nicht gefunden. Bitte anlegen
        [DEBUG] 17:55:38: Regenmenge: 0 mm2 (hour)

        [DEBUG] 17:55:38: Varible rain_week nicht gefunden. Bitte anlegen
        [DEBUG] 17:55:38: Regenmenge: 0 mm2 (week)

        [DEBUG] 17:55:38: Varible rain_day nicht gefunden. Bitte anlegen
        [DEBUG] 17:55:38: Regenmenge: 0 mm2 (day)

        [DEBUG] 17:55:38: Varible rain_month nicht gefunden. Bitte anlegen
        [DEBUG] 17:55:38: Regenmenge: 7.07 mm2 (month)

        [DEBUG] 17:55:39: Windmesser wird ausgelesen…
        [DEBUG] 17:55:39: Windgeschwindigkeit: 2 km/h
        [DEBUG] 17:55:39: Varible windstaerke nicht gefunden. Bitte anlegen
        [DEBUG] 17:55:39: Varible windrichtung nicht gefunden. Bitte anlegen
        [DEBUG] 17:55:39: Varible boenstaerke nicht gefunden. Bitte anlegen
        [DEBUG] 17:55:39: Varible boenrichtung nicht gefunden. Bitte anlegen
        [DEBUG] 17:55:39: Windmesser auslesen beendet.
        [DEBUG] 17:57:55: netatmo Zusatzmodul Integration v.1.2 gestartet.
        [DEBUG] 17:57:55: Daten werden alle 5 min aktualisiert. Bei debug = 0 wird nichts debuggt

  • Lasse
    9. May 2016 at 19:25

    Also could you make a english version of this?

    Thanks

    • boomx
      boomx
      9. May 2016 at 22:41

      Hi,

      I can translate the code ;) You need the variables windstaerke, windrichtung, boenstaerke, boenrichtung, rain_hour, rain_week, rain_month.

      Greetz

      • Lasse
        9. May 2016 at 23:07

        Hello,

        Much appreciated if you could translate it – thanks!

        I didn’t know/understod that you had to add Variables Panels (I saw that on previous pages/code).

      • Lasse
        25. May 2016 at 22:54

        Hi again,
        How is it going with the translation?

  • Martin
    27. July 2016 at 8:14

    Hi, this is perfekt. Only sometime break with this error
    [DEBUG] 16:25:50: [1;31m2016-07-25 16:25:50.742614 [ fatal] LUA error: /usr/share/lua/5.2/json/decode/util.lua:35: unexpected character @ character: 1 0:1 [<] line:
    [DEBUG] 16:25:50: <

    Any idea ?

  • Patrick
    2. August 2016 at 15:18

    Hi

    First I want to thank you for this wonderful solution / script, I really appreciated it !
    But so now and then I got the following error message (see below) and the script will stop :(
    I’m currently using the 1.2version ?

    -My question to you, is this a known error ?
    -What is the solution to prevent this from happening ?

    [DEBUG] 13:40:51: _[1;31m2016-08-02 13:40:51.524189 [ fatal] LUA error: /usr/share/lua/5.2/json/decode/util.lua:35: unexpected character @ character:

  • boomx
    boomx
    2. August 2016 at 23:10

    Hi,

    yes, it is a known error. It is a problem with the api of netatmo. I try to code a exception. Stay tuned :)

    Greetz

    • Patrick
      7. August 2016 at 15:56

      Hi Boomx,

      Great to hear, and I will definitely stay tuned !!
      Thanks a lot !

    • WimJanse
      25. September 2016 at 19:10

      Hi boomx, thanks for the fantastic interface, all working great.
      However, I also get the breakdown with the unexpected character @ from time to time. If you could indeed code an exception, that would be fabulous
      Cheers

  • emiel
    21. August 2016 at 17:16

    This lua script look great. I’ve found a problem when you use 2 base stations. the script is at a certain point looking for a rain gauge (which is connected to the second station) at the data of the first station and gives an error:

    [DEBUG] 17:12:10: netatmo Zusatzmodul Integration v.1.2 gestartet.
    [DEBUG] 17:12:10: Daten werden alle 5 min aktualisiert. Bei debug = 0 wird nichts debuggt
    [DEBUG] 17:12:10: oAuth 2.0 durchgeführt.
    [DEBUG] 17:12:11: netatmo Sensoren werden gesucht…
    [DEBUG] 17:12:11: Regensensor 05:00:00:00:48:58 erkannt.
    [DEBUG] 17:12:11: Regensensor 05:00:00:00:93:80 erkannt.
    [DEBUG] 17:12:11: Windmesser 05:00:00:00:93:80 erkannt.
    [DEBUG] 17:12:13: Neerslag: 0 mm (hour)
    [DEBUG] 17:12:13: Neerslag: 5.151 mm (day)
    [DEBUG] 17:12:13: Neerslag: 40.4 mm (month)
    [DEBUG] 17:12:13: [1;31m2016-08-21 17:12:13.849540 [ fatal] LUA error:
    /opt/fibaro/scenes/239.lua:165: bad argument #1 to ‘pairs’ (table expected, got nil)

    (line 165 is: for k, v in pairs(data.body) do )

    any ideas of how to deal with 2 base stations??

  • Philippe TC
    12. September 2016 at 2:37

    Very nice to have a script like this, but unfortunately it leaves more questions than answers to me.

    Would be nice when you have a small user manual how to install.
    Did I read in one of the comments that I have to define variables? Where en what variables?
    In the section -DIESE DATEN ANPASSEN- I have to fill in CLIENT_ID and CLIENT_SECRET. It’s not clear what this refers to. Can someone help?
    The username and password below that, do they refer to the login at auth.netatmo.com? If not, then what does it refer to?

    Thanks for help!

  • Wim Janse
    5. November 2016 at 13:55

    Boomx,

    I understood from Netatmo that the API devicelist will be faded out by end of November, needs to be replaced with getstationsdata.

    Would you have the possibility to update your fantastic tool? (I unfortunate lack the LUA programming knowledge)

    Thanks,
    WimJanse

  • Wim Janse
    5. November 2016 at 15:47

    Boomx
    I learned from Netatmo that the API call devicelist will no longer be supported as of 30 november.
    The call will be replaced by getstationsdata. Would you be so kind to update your excellent tool. I’m using this in Fibaro HC2 to control my sunscreens ( have to go up if too much wind), which I will not be able to fo in future.
    I tried myself, but the API response structure is different, and I lack LUA knowledge to make the change myself.

    Thank you,
    WimJanse

  • Sankotronic
    24. November 2016 at 9:18

    Hi boomx,

    My outdoor module died on me so at the moment I have only indoor module, rain and window sensor. After outdoor module died I also noticed that script for getting data from rain and wind sensor stop working. I get this error in debugging window:

    [DEBUG] 09:10:02: [1;31m2016-11-24 09:10:02.703299 [ fatal] LUA error: /opt/fibaro/scenes/76.lua:133: attempt to concatenate global ‘int_id’ (a nil value)

    After analyzing problem I found that you are getting device id after loop which is getting module id’s. After moving this line of code

    int_id = data.body.devices[1]._id

    before loop it is again working OK. See complete code for getting devices after change:

    function getDevices()
    getResponseData(‘https://api.netatmo.net/api/devicelist’,’access_token=’..token,
    function(data)
    fibaro:debug(‘Wind and rain sensor data requested…’)
    int_id = data.body.devices[1]._id
    for _, v in pairs(data.body.modules) do
    if (v.data_type[1] == ‘Rain’) then
    rain_id = v._id
    fibaro:debug(‘Rain sensor ‘ .. rain_id .. ‘ recognized!’)
    –rain_bat = calcBat(v.battery_vp, true)
    if rain_id ~= nil then
    getSumRain(60 * 60, ‘hour’)
    getSumRain(60 * 60 * 24, ‘day’)
    getSumRain(60 * 60 * 24 * 7, ‘week’)
    getSumRain(60 * 60 * 24 * 30, ‘month’)
    end
    elseif (v.data_type[1] == ‘Wind’) then
    wind_id = v._id
    fibaro:debug(‘Windsensor ‘ .. wind_id .. ‘ recognized!’)
    getmeasureWind()
    end
    end
    end
    )
    end

    Thank you and keep up good work!

Leave a Response