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

Export temperature chart data


Question

Posted

Guys, anyone know how can i export temperature sensor's data from chart?

I need to get a longer period (a month maybe) with all values and times measured by the sensor.

Thanks in advance

  • Like 1

Recommended Posts

  • 0
Posted

the lua definition should be a global lua function

Please login or register to see this code.

 

  • 0
Posted

@jgab, ok no error message anymore but also no email received

  • 0
Posted

So, what user id are you using?

  • 0
Posted

Hello jgab
just for information. My temperature measurement in ER5 sends an email.

 

(emailAdmin=2)
emailAdmin=rule("emailAdmin=USER('admin').id")


function exportTemps(startDate,stopDate,deviceId) -- global, no "local" in front of definition
   local function toEpoc(t)
     local y,m,d = t:match("(%d%d%d%d)%-(%d%d)%-(%d%d)")
     return os.time{year=tonumber(y),month=tonumber(m),day=tonumber(d),hour=0}
   end
   local data = api.get(string.format("/temperature/%s/%s/summary-graph/devices/temperature/%s",toEpoc(startDate),toEpoc(stopDate),deviceId))
   for _,d in ipairs(data) do d[1] = d[1]//1000 end
   return data
end


rule([[#sendTemps{id='$id',start='$start',stop='$stop'} =>
           local data = exportTemps(start,stop,id);
           local room = id:roomName;
           local lines = [_,fmt('%s %s %s %.02f°\n',os.date('%x %X',_[1]),room,id,_[2]) in data];
           emailAdmin:email = log('Temperatures from %s to %s:\n%s',start,stop,table.concat(lines))
     ]])


rule([[@17:59:05 & wday('sun') =>
         local d = os.date('*t');
         local stop = os.date('%Y-%m-%d',os.time({year=d.year,month=d.month,day=d.day+1}));
         local start = os.date('%Y-%m-%d',os.time({year=d.year,month=d.month,day=d.day-7}));
         post(#sendTemps{id=301,start=start,stop=stop})
     ]])

  • Thanks 1
  • 0
Posted (edited)

@sbk and @jgab Thanks have it too in email now.

I discovered what I did wrong, I overlooked one export temps!

Sorry

 

Edited by Sjakie
  • 0
Posted

@jgab for analyzing this data it's difficult to compare because the hot water temp is reporting the most data.

Project;

4 door sensors for temperature measuring 3/4 different spots on floor, thermostat 

1 or perhaps 2 DS temp sensors who registering hot water temperature.

Is it possible  every 15 minutes to have in email:

570, 1154, 1290, 804, 1352

Thanks in advance

 

 

  • 0
Posted

Hello @jgab try to use the code changing function, becouse i need not an graph, but the min and max-value of a period. The goal ist to send a mail/pushmessage of the min/max-values for night and day for evry date. I fail to found a function for the comparison and store the right value.
Have you an idea/beginning for me?

Thanks in advance!

  • 0
Posted

If you have this version with map defined.

 

 

If you retrieve the data for a given day

Please login or register to see this code.

This returns data for Jan 16 (It stops at 00:00 Jan 17)

Then map it to a list of temps (original data is a list of {{date, temp},{date, temp}...}

Please login or register to see this code.

Then retrieve the max and the min temperature of the list
 

Please login or register to see this code.

..and then mail it to yourself...

  • 0
Posted

Hello @jgab, thank you very much for your fast reply. I will test it on weekend.

  • 0
Posted

Hello @jgab now i tested this QA-code and it works:
 

function QuickApp:onInit()
    self:debug("onInit")
end
local fmt = string.format 
local function map(f,l) local r={} for _,v in ipairs(l) do r[#r+1]=f(v) end return r end
 
local function toEpoc(t)
  local y,m,d = t:match("(%d%d%d%d)%-(%d%d)%-(%d%d)")
  return os.time{year=tonumber(y),month=tonumber(m),day=tonumber(d),hour=0}
end
 
local function exportTemps(startDate,stopDate,deviceId)
  local data = api.get(fmt("/temperature/%s/%s/summary-graph/devices/temperature/%s",toEpoc(startDate),toEpoc(stopDate),deviceId))
  return map(function(v) return {v[1]//1000,v[2]} end,data)
end
 
local function exportEvents(startDate,stopDate,prop,deviceId)
  local data = api.get(fmt("/events/history?eventType=DevicePropertyUpdatedEvent&from=%s&to=%s&objectType=device&objectId=%s",toEpoc(startDate),toEpoc(stopDate),deviceId))
  return map(function(d) if d.data.property==prop then return {d.timestamp,d.data.newValue} end end,data)
end
 
local function logData(pref,data)
  for _,d in ipairs(data) do
    print(string.format("%s %s => %s",pref,os.date("%x %X",d[1]),d[2])) 
  end
end
 
function QuickApp:sendData()
local year      = os.date("%Y", os.time()-86400);
local month     = os.date("%m", os.time()-86400);
local yday      = os.date("%d", os.time()-86400);
local dfyday = os.date("%d", os.time()-86400-86400);
    local yesterday = tostring(year.."-"..month.."-"..yday)
    local daybfyday  = tostring(year.."-"..month.."-"..dfyday)
    data = exportEvents(daybfyday,yesterday,'value',1097)
    data = map(function(d) return d[2end, data)
    local maxTemp = math.max(table.unpack(data))
    local minTemp = math.min(table.unpack(data))
    print("Max: "..maxTemp.." Min: "..minTemp)
    hub.alert('push', {[1] = 2, }, daybfyday..": Max-Temperatur "..maxTemp.."°C"false'')
    hub.alert('push', {[1] = 2, }, daybfyday..": Min-Temperatur "..minTemp.."°C"false'')
end
 
On EventRunner4 i have added this:
rule("@08:21:00 => fibaro.call(QA_SendTemp, 'sendData')")--CheckButton
 
Unfortunaly this give me a error by executing :
in Rule:58[@08:21:00 => fibaro.call(QA_SendTemp, 'sendData')]: ./include/EventRunner.lua:1980: ./include/EventRunner.lua:273: Wrong parameter type, string required. Provided param 'nil' is type of nil[01.02.2024] [08:21:15] 
 
Button-definition:

Please login or register to see this image.

/monthly_2024_02/image.png.ba7aead652e30827d1b26f3c2b7f3169.png" /> What do i wrong? In addition to this question: How can i set the period of 20:00 yesterday to 08:00 today ("last night")? Thanks in advance.
  • 0
Posted (edited)

Does any1 made any nice Quickapp to view data(temp, lux, windspeed, true/false button events)  from the Yubii apps?

But with the timestamps like the example from jgab? 

 

Would love too have a "graphview"  in the quickapp but a view like this would also be nice.

(like this wave.fqa view) 

Please login or register to see this link.


This only gives the timestamp from my loop and only the data from every 15min the last 20 hours.

But would rather have the timestamps and data that is saved in the history to show.

 

 

Please login or register to see this image.

/monthly_2024_07/image.png.0fd01209b79d4a4effcb586cacd38584.png" />

 

 

 

Edited by Brors94
typo
  • 0
Posted

Maybe consider to automatically export the data to InfluxDB and make fancy graphs with Grafana?

  • 0
Posted

 

Yeah, have seen someone who offers a Quickapp for that.

But then again you would have too go to another app or webbrowser for it 😅
 

it dosent have to be a graph, It could be somthing like the picture I have. But with the possibility to change day/date. And not only the last 20 hour like mine can show. 

 

 

 

 

 

 

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