Example: Show graph of average temperature in 24hours

Task

How to show temperature of the last 24h in graphs, in 24 points? Taking into account that temperature object is being updated more frequently..

Event script which make storage of temperatures

Source code    
  1. -- current temperature value
  2. value = knxdatatype.decode(event.datahex, dt.float16)
  3.  
  4. -- number of stored values
  5. count = storage.get('avg_count', 0) + 1
  6. -- sum of all stored values
  7. value = value + storage.get('avg_value', 0)
  8.  
  9. -- save new values
  10. storage.set('avg_count', count)
  11. storage.set('avg_value', value)

Scheduled script which calculates the average temperature of last hour and writes it into KNX group address

Source code    
  1. -- get current values
  2. count = storage.get('avg_count', 0)
  3. value = storage.get('avg_value', 0)
  4.  
  5. -- check if there is at least one value stored
  6. if count > 0 then
  7. -- write average value to the required group address
  8. grp.write('11/7/19', (value / count), dt.float16)
  9. end
  10.  
  11. -- reset storage
  12. storage.set('avg_count', 0)
  13. storage.set('avg_value', 0)

Make Graph

  • Go to Visualization tab, then press on the Unlock current floor plan for editing.  In the Graph section, choose the created object with group address ’11/7/19′, choose graph width/height, number of points.
  • When clicking on the newly created KNX object after 24 hours, it looks like this