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


Recommended Posts

Posted (edited)

Hi, I am creating a QA to make logs of wind sensor available in the yubii apps (maybe lux, temp, humidity too later) 

 

QA: 

Please login or register to see this attachment.

 

I am now updating my label like this from the info.timestamp table and info.value table.

but I have to make a line for each value i want to show. 

any1 knows if it is possible to update depending on how many values i get from my api call  ?

and sometimes i get less then 10 values back ill get an error too so 😅Any suggestions on how too do it? 

 

 

function QuickApp:update()
 
local function fmt(v)
      val = string.format("%02d",v)
      return val
      end
local fromtime = ""..self.store.year.."-"..fmt(self.store.frommonth).."-"..fmt(self.store.fromday).."-"..fmt(self.store.fromhour)..""
print("fromtime: ",fromtime)
local fromtime2 = toEpoc(fromtime)
print("fromtime2: ",fromtime2)
local tootime = ""..self.store.year.."-"..fmt(self.store.toomonth).."-"..fmt(self.store.tooday).."-"..fmt(self.store.toohour)..""
print("tootime: ",tootime)
local tootime2 = toEpoc(tootime)
print("tootime2: ",tootime2)
 
local data = api.get("/events/history?eventType=DevicePropertyUpdatedEvent&from="..fromtime2.."&to="..tootime2.."&objectType=device&objectId="..sensorid.."&numberOfRecords="..self.store.records.."")
 
for _,d in ipairs(data) do
info.timestamp[_] = todate(d.timestamp)
info.value[_] = d.data.newValue
--print("info.time:",info.timestamp[_], "info.value",info.value[_])
 
end
 
local line1 = "<font color=Green>Chart with timestamp and "..unittype.." in <font color=green>"..unit.." :"
local line2 = "<font color=orange>"..info.timestamp[1].." "..unittype.." <font color=green>"..info.value[1].." "..unit..""
local line3 = "<font color=orange>"..info.timestamp[2].." "..unittype.." <font color=green>"..info.value[2].." "..unit..""
local line4 = "<font color=orange>"..info.timestamp[3].." "..unittype.." <font color=green>"..info.value[3].." "..unit..""
local line5 = "<font color=orange>"..info.timestamp[4].." "..unittype.." <font color=green>"..info.value[4].." "..unit..""
local line6 = "<font color=orange>"..info.timestamp[5].." "..unittype.." <font color=green>"..info.value[5].." "..unit..""
local line7 = "<font color=orange>"..info.timestamp[6].." "..unittype.." <font color=green>"..info.value[6].." "..unit..""
local line8 = "<font color=orange>"..info.timestamp[7].." "..unittype.." <font color=green>"..info.value[7].." "..unit..""
local line9 = "<font color=orange>"..info.timestamp[8].." "..unittype.." <font color=green>"..info.value[8].." "..unit..""
local line10 = "<font color=orange>"..info.timestamp[9].." "..unittype.." <font color=green>"..info.value[9].." "..unit..""
local line11 = "<font color=orange>"..info.timestamp[10].." "..unittype.." <font color=green>"..info.value[10].." "..unit..""
 
self:updateView("loginfo","text","<table width= 400px border = 0px><td align =left><section align='left'><font size='"..Fontsize.."'><tt> "..line1.."\n"..line2.."\n"..line3.."\n"..line4.."\n"..line5.."\n"..line6.."\n"..line7.."\n"..line8.."\n"..line9.."\n"..line10.."  </tt></font></section>")
 
sensorvalue = string.format("%.0f",hub.getValue(sensorid, "value"))
self:updateProperty("value", hub.getValue(sensorid, "value"))
self:updateProperty("log", ""..unittype..":"..sensorvalue..""..unit.."")
 
end

 

 

 

 

Edited by Brors94
Posted (edited)

You already have the loop

 

Make a variable within the loop with the wanted text and data like:

labelText = “”

labelText = labelText ..”text: ” ..variable ..”\n”

 

and insert the variable labelText in your label. 


 

 

Edited by SmartHomeEddy
  • Thanks 1
  • Topic Author
  • Posted

    @SmartHomeEddy Thanks!! 😄 Makes it alot cleaner and was way to easy when you gave me the direction 😅

     

     

    • Like 1
  • Topic Author
  • Posted (edited)

    @SmartHomeEddy may i ask about 1 more thing? 

     

    edit:  (my braint didnt work😅

    This was a solution 😄

    rownumber =  1 + rownumber
    line = ""..line.." \n<font color=orange> "..rownumber..":"..info.timestamp[_].." "..unittype.." <font color=green>"..info.value[_].." "..unit.."   "

     

     

    Updated QA: 

    Please login or register to see this attachment.

     

     

    If I want to add the "Row number" to the label how do i do that in the loop?

    this throws an error

    ---------------------
    line = ""
    for _,d in ipairs(data) do
    info.timestamp[_] = todate(d.timestamp)
    info.value[_] = d.data.newValue
    rownumber = [_]
    line = ""..line.." \n<font color=orange> "..rownumber..":"..info.timestamp[_].." "..unittype.." <font color=green>"..info.value[_].." "..unit.."   "
     
    --print("info.time:",info.timestamp[_], "info.value",info.value[_])
    end
     
    Edited by Brors94

    Join the conversation

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

    Guest
    Reply to this topic...

    ×   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...