Aller au contenu

Initial State


971jmd

Messages recommandés

salut 

je voie que toit aussi tu t'intéresse a initial state.

Ci-joint le tuto : https://forum.fibaro.com/topic/30976-fibaro-initialstate-plugin-how-to/?tab=comments#comment-155160

 

ini1.png.70fffabf129ec37b98ed4c729455b5c0.png

 

 

 

je le teste et ça fonctionne très bien, mais le Plugin initial state de FIBARO, ne propose pas de possibilité de remonter la valeur d'une variable global ou une la valeur d'un label.

 

je cherche de l'aide pour réaliser un code LUA pour remonter ces valeurs 
 

 merci de votre aide 

 

 

 

Lien vers le commentaire
Partager sur d’autres sites

j'avance bien grâce au FOFO officiel

 

mai il reste un problème, dans le code ci-dessous il il manque quel chose pour activée la scène a chaque foie que la LABEL1 change d'état .

 

je n'arrive pas

 

 

--[[
%% properties
389 ui.Label1.value
%% globals
--]]


-- only one instance allowed
if (fibaro:countScenes() == 2) then
fibaro:abort()
end



-- initialstate account informatons
-- please specify the login data below
local streamingAccessKey = "xxxxxxxxxxxxxxxxxxx"
local bucketKey = "xxxxxxxxxxxxxxx"

-- the name of the datapoint
local datakey = "VDLabel1"

-- change to the label you wish to read and show on initialstate
local mylabeltoread = fibaro:getValue(389, "ui.Label1.value")

------------------------------
-- do not change code below --
------------------------------

local headers = {}
headers['Content-Type'] = 'application/json'
headers['X-IS-AccessKey'] = streamingAccessKey
headers['X-IS-BucketKey'] = bucketKey
-- not sure if this is good idea, Fibaro is using in their plugin
-- but i think "Accept-Version: ~0" could be better
headers['Accept-Version'] = '0.0.1'

-- initialstate URL
local posturl = 'https://groker.initialstate.com/api/events'

-- main function
function showVDLabelOnInitialState()
  local event = {}
  -- let's use local time
  event["epoch"] = os.time()
  event["key"] = datakey
  event["value"] = mylabeltoread
  local bucket = {}
  table.insert(bucket, event)
  if (tostring(json.encode(bucket)) ~= "{}") then
    --send bucket
    isData = net.HTTPClient({timeout = 2000})
    isData:request(posturl, {
        options = {
          method = 'POST',
          headers = headers,
          data = json.encode(bucket),
        },
        success = function(param)
        end,
        error =  function() 
          print("error")
          -- no no, don't abort here, sometimes initialstate reports error, so let's not break loop
          --fibaro:abort()
        end
      }
    )
  else
    print('label without value? exiting now ...')
    fibaro:abort()
  end
  -- loop every 1 minute
setTimeout(function() showVDLabelOnInitialState(); end, 5000)
end

fibaro:debug("loop started...")
showVDLabelOnInitialState()

 

Modifié par 971jmd
Lien vers le commentaire
Partager sur d’autres sites

×
×
  • Créer...