Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Question

Posted

Witam, mam urządzenie Smogomierz, z którego odczyty chciałbym umieszczać w zmiennych aby móc np sterować taśmą rgb oraz utworzyć urządzenie wirtualne. Dane pobierane są z lokalnego ip http://192.168.5.134/api w postaci 

Please login or register to see this code.

Utworzyłem scenę, która potrafi odczytać ale nie mam pojęcia jak to przenieść do zmiennych:

pm10 -> spm10

pm25 -> spm25

temperature -> stemp

pressure -> spres

humiditi -> shumi

 

scena. która wyświetla w debug:

--[[
%% properties
%% events
%% globals spm25
--]]

local url = "http://192.168.5.134/api"
local http = net.HTTPClient() 

http:request(url, { 
    options = { 
        method = 'GET', 
        timeout = 2000
    }, 
    success = function(response)
        fibaro:debug(response.status)
        if response.status == 200 or response.status == 201 then
          fibaro:debug(response.data);
                    
        end
    end,
    error = function(err) 
        fibaro:debug("Error: " .. err) 
    end 
}) 

 

Z góry dziękuję za pomoc, ps smogomierz to fajny polski pomysł, podobnie jak strona aqi.eco na którą można przekazywać dane

1 answer to this question

Recommended Posts

  • 0
  • Inquirer
  • Posted

    nie umiem programować ale metodą wytnij wklej :) udało mi się utworzyć VD. Poniżej kod oraz VD. Powstała dzięki wszystkim dzielącym się wiedzą. 

     

     

    --[[
    VD pobiera dane z urządzenia SMOGOMIERZ znajdującego się w lokalnej sieci LAN. Wyniki wyświetlane są w VD oraz umieszczane w zmiennych globalnych - do wykożystania np w sterowaniu RGB. 
    Kod umieszony pod przyciskiem AKTUALIZACJA
    W pętli głównej:
    local ID = fibaro:getSelfId()
    fibaro:sleep(60*1000) -- 1min
    fibaro:call(ID, "pressButton", "11"); - nr przycisku AKTUALIZACJA
    fibaro:debug("status updated")

    zadeklarowane zmienne globalne 
    spm10
    spm25
    spres
    stemp
    shumi
    sdewp
    sAQ

    ]]--

    local selfId   = tonumber(fibaro:getSelfId());
    ip       = '192.168.5.134' --adres ip lokalny smogomierza
    url      = '/api'
    http     = Net.FHttp(ip, 80)

    --poziomy wg norm 
    local pm10vlow = 1
    local pm10low = 20
    local pm10medium = 60
    local pm10high = 100
    local pm10vhigh = 140
    local pm10critic = 200

    local pm25vlow = 1
    local pm25low = 13
    local pm25medium = 36
    local pm25high = 60
    local pm25vhigh = 84
    local pm25critic = 120

    local Level --pomocnicza nie wykozystana
    --[[ zmienne nie wykożystywane
    local VeryLow
    local Low
    local Medium
    local High
    local VeryHigh
    local Critical
    ]]--


    fibaro:call(selfId, "setProperty", "ui.Label1.value", "Brak Danych");
    fibaro:call(selfId, "setProperty", "ui.Label2.value", "Brak Danych");
    fibaro:call(selfId, "setProperty", "ui.Label3.value", "Brak Danych");
    fibaro:call(selfId, "setProperty", "ui.Label4.value", "Brak Danych");
    fibaro:call(selfId, "setProperty", "ui.Label5.value", "Brak Danych");
    fibaro:call(selfId, "setProperty", "ui.Label6.value", "Brak Danych");
    fibaro:call(selfId, "setProperty", "ui.Label7.value", "Brak Danych");


    response ,status, errorCode = http:GET(url);
    fibaro:debug("Response: " .. response);
    --fibaro:debug("Response: " .. status);
    fibaro:debug("Response: " .. errorCode);


    jsonString = json.decode(response);
    local pm10;
    local pm25;
    local temp;
    local humi;
    local pres;
    local dewp;

    pm10 = jsonString.pm10;
    pm25 = jsonString.pm25;
    temp = jsonString.temperature;
    humi = jsonString.humidity;
    pres = jsonString.pressure;
    dewp = jsonString.dewpoint;

    fibaro:setGlobal("spm10", pm10); --zmienne globalne
    fibaro:setGlobal("spm25", pm25); --zmienne globalne
    fibaro:setGlobal("stemp", temp); --zmienne globalne
    fibaro:setGlobal("shumi", humi); --zmienne globalne
    fibaro:setGlobal("spres", pres); --zmienne globalne
    fibaro:setGlobal("sdewp", dewp); --zmienne globalne

    fibaro:call(selfId, "setProperty", "ui.Label1.value", tostring(pm10));
    fibaro:call(selfId, "setProperty", "ui.Label2.value", tostring(pm25));
    fibaro:call(selfId, "setProperty", "ui.Label3.value", tostring(temp));
    fibaro:call(selfId, "setProperty", "ui.Label4.value", tostring(humi));
    fibaro:call(selfId, "setProperty", "ui.Label5.value", tostring(pres));
    fibaro:call(selfId, "setProperty", "ui.Label6.value", tostring(dewp));
    fibaro:call(selfId, "setProperty", "ui.Label7.value", (fibaro:getGlobalValue('sAQ')));

    if pm10 < pm10low and pm25 < pm25low then
        Level = 1
        fibaro:setGlobal ("sAQ", "Bardzo Dobra"); --sAQ zmienna globalna do wyswietklania
        fibaro:debug ("poziom" ..Level)

        
    elseif pm10 < pm10medium and pm25 < pm25medium then
        Level = 2
        fibaro:setGlobal ("sAQ", "Dobra");
        fibaro:debug ("poziom" ..Level)
        
        
    elseif pm10 < pm10high and pm25 < pm25high then
        Level = 3;
        fibaro:setGlobal ("sAQ", "Średnia");
        fibaro:debug ("poziom" ..Level);

        
    elseif pm10 < pm10vhigh and pm25 < pm25vhigh then
        Level = 4
        fibaro:setGlobal ("sAQ", "Zła");
        fibaro:debug ("poziom" ..Level)
        
        
    elseif pm10 < pm10critic and pm25 < pm25critic then
        Level = 5
        fibaro:setGlobal ("sAQ", "Fatalna");
        fibaro:debug ("poziom" ..Level)
        
        
      else
              fibaro:debug("cos nie tak");
    end

    Please login or register to see this attachment.

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...