Temp min and max

47 replies [Last post]
Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010

With the extreme weather on its way, I thought it would be interesting to have a display on the joggler of the min and max temperatures in the last 24 hours.

However, I dont know C, or any other modern language. My programming started with basic and stopped with pascal. I can do assembler but that is about it these days. I seem to be able to follow about 70% of the LUA examples, but the language in the wiki goes over my head Im afraid. What is the f in f:add? I know I need a filter to look at the xAP endpoint, but I cant work it out.

Can someone help me understand? point me to a book for dummys even?

If I could get my head around this I could get the system to email me alerts for temperature in the loft water tank near freezing or the greenhouse frying up.

I dont ask for help lightly in such an "I dont know where to start" manner, but I am lost on this.

 

Many thanks 

Alan

g7pkf
Offline
United Kingdom
Joined: 11 Jan 2011
I cant help

But it's a really good idea, knowing the tempo averages would be nice.

 

I nearly run out of oil today so am currently looking to integrate an oil level/usge clocking thingy...

 

dont want to re-invent the wheel but cannot find any reasonably priced sensors.

 

Dean

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
A Float sensor?
brett
Offline
Providence, United States
Joined: 9 Jan 2010
distance sensor

Maybe even an Ultrasonic or InfraRed distance sensor - for a touchfree solution, just mount it on the top of your tank.

f is a xap.Filter() object and "add" is a method for that Object, it allows you to ADD a filter condition to some Filter that you are constructing.   Filters are use to make sure that your code only triggers when the correct xAP packet is noticed. see http://www.dbzoo.com/livebox/hah_plugboard_v2#filter

See this section about the ":" token.  http://www.lua.org/manual/5.1/manual.html#2.5.8

A call v:name(args) is syntactic sugar for v.name(v,args), except that v is evaluated only once

g7pkf
Offline
United Kingdom
Joined: 11 Jan 2011
Ultrasonic

Yes the tank comes with a "watchman" which gives a visual display of level...

 

think i might try and integrate this somehow. The tanks on order should get ity in 3-10 days.

 

will keep you posted.

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Try this

Try this script, sorry I've had to post it, I couldn't upload it (Brett ??), you will need to change this line   f:add("xap-header","source", "dbzoo.livebox.Controller:1wire.1") to match the temperature sensor you want to monitor :-

 

 

--[[

  Monitor a temperature sensor and output the

  maximum and minimum values

--]]

 

--module(...,package.seeall)

 

require("xap")

 

info={

   version="1.0", description="Max-Min Monitor"

}

 

-- setup some variables

  MinTemp = 999

  MaxTemp = 999

 

function TempChangeTrigger(frame)

-- We only get to this routine if a temperature change has been triggered

 

-- Create a local variable and put the current temperature in it

  local CurrTemp = frame:getValue("input.state","text")

 

-- Initialise the min and max temps if this is the first run

  if (tonumber(MinTemp) == 999) then

    MinTemp = CurrTemp; 

  end

 

  if (tonumber(MaxTemp) == 999) then

    MaxTemp = CurrTemp; 

  end

 

-- Do we have a new minimum temperature

  if (tonumber(CurrTemp) < tonumber(MinTemp)) then 

    MinTemp = CurrTemp; 

  end

 

-- Do we have a new maximum temperature

  if (tonumber(CurrTemp) > tonumber(MaxTemp)) then 

    MaxTemp = CurrTemp; 

  end

 

-- Debug lines

--  print("MinTemp : " .. MinTemp)

--  print("MaxTemp : " .. MaxTemp)

 

-- Prepare an xap message to be broadcast

  Msg = " Min: " .. MinTemp .. " - Max: " .. MaxTemp

  displayLCD(Msg)

 

end

 

function displayLCD(msg)

-- Send a message to the LCD

   local msg=string.format([[

xap-header

{

class=xAPBSC.cmd

target=dbzoo.livebox.Controller:lcd

}

output.state.1

{

id=*

state=on

text=%s

}]], msg)

   xap.sendShort(msg)

end

 

function init()

-- print("Max-Min Monitor - init")

 

-- Create a filter, the conditions needed to call our "action" routine

  f  = xap.Filter()

 

-- We want a temperature change to trigger our routine

  f:add("xap-header","source", "dbzoo.livebox.Controller:1wire.1")

 

-- This is the function we call when a match is made to the filters

  f:callback(TempChangeTrigger)

end

 

xap.init("dbzoo.lua.maxmin","FF01DE00")

init()

xap.process()

 

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
thanks

this looks good, will try it tomorrow.

Looking through it I cant see how I could get this onto the joggler? I cant see an endpoint. I think this will only put the min and max onto the LCD?

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
Hmmmmm

I tried this this morning, and while I dont have an LCD on the HAH, I looked at the messages on xfx, but its still showing the ip address.

I did change the source to a jeenode endpoint.

Any ideas?

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
LCD

The code does only write to the LCD at the moment.  You can download a virtual LCD from http://www.dbzoo.com/_media/livebox/hah-vlcd.zip, this will display anything that is sent to the HAH's LCD even if you don't have one connected.

I'll get the Joggler xAPFlash working tonight, although I'm not quite sure what is required.  I was going to expose two new xAP endpoints, possibly mintemp and maxtemp, these can then be used just like any other xAP endpoint on the joggler. 

Does that sound ok, or did people have something else in mind?

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
Thanks

I love the virtual LCD, but its still showing the IP address.

Yes, it just needs to provide an endpoint. and send messages such as:-

 

xap-header

{

v=12

hop=1

uid=FF00D808

class=xAPBSC.event

source=dbzoo.livebox.jeenode:test.temp

}

input.state

{

state=on

text=10

}

 

 

The joggler (iServer?) can pick up the text or state and then display in a textbox button on the Joggler.

I have been teaching myself C from here http://www.cprogramming.com/tutorial/c/lesson1.html and this is helping enormously with understanding LUA.

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
Oh, and in reply to your

Oh, and in reply to your actual question. I think I can expand this to add min and max for more sensors. When you add the joggler endpoints, can you add an indication of how the values are chosen so I can add more if required?

I would at least need two, one for outside, and another for the greenhouse.

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Second Try

Try this second attempt, it exposes two endpoints, see the code.  Let me know how you get on.  It's still a work in progress ;)

Karl

AttachmentSize
maxminv2.lua 2.25 KB
Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
Sorry - still nothing

Sorry - still nothing happening.

From your code I am expecting to see two new endpoints under Plugboard, but nothing.

I changed the monitored endpoint, saved it in /etc/Plugboard and rebooted. I let it run for 10 mins with xfx running.

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Applet

It isn't an applet yet, log in to the HAH cd into the plugboard directory and run it manually :-

cd /etc/plugboard
lua <script name>

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
Doh!Never did get my head

Doh!

Never did get my head around that bit.

Running it now and the two endpoints have appeared.

Nothing so far on the LCD or data in endpoints

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
Hang on Somethings happening

Its just kicked into life! 

Very exciting. Will write some xml for the joggler immediately.

Alan

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Great

Great, positive feedback is always a good motivator. 

In response to your post about about expanding it, I'll look into it.  I think the best way would be to create a table/array to store the details in and read it at run time.  That's probably pushing my knowledge at the moment, but I'm sure I've seen an example of this somewhere.  I'll see what I can do.

It would be nice to see a Joggler screenshot when you get something worth showing.

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
Joggler code

Here are two buttons that produce min and max for the greenhouse.

 

<button NAME="Ghousemin">

<label><text>G'House Min</text></label>

<gridX>3</gridX>

<gridY>0</gridY>

<style>blue</style>

<height>/2</height>

<posY>80</posY>

<textSuffix><![CDATA[ C]]></textSuffix>

<bsctext>

<fontsize>24</fontsize>

</bsctext>

<xAP>

<schema>xAPBSC</schema>

<uid>FF01DE01</uid>

<source>dbzoo.livebox.Plugboard:mintemp</source>

</xAP>

<mode>text</mode>

<hide>state</hide>

</button>

 

<button NAME="Ghousemax">

<label><text>G'House Max</text></label>

<gridX>3</gridX>

<gridY>0</gridY>

<style>red</style>

<height>/2</height>

<posY>160</posY>

<textSuffix><![CDATA[ C]]></textSuffix>

<bsctext>

<fontsize>24</fontsize>

</bsctext>

<xAP>

<schema>xAPBSC</schema>

<uid>FF01DE02</uid>

<source>dbzoo.livebox.Plugboard:maxtemp</source>

</xAP>

<mode>text</mode>

<hide>state</hide>

</button>

 

 

<button NAME="Ghouse">

<label><text>Greenhouse</text></label>

<gridX>3</gridX>

<gridY>0</gridY>

<style>black</style>

<height>/2</height>

<textSuffix><![CDATA[ C]]></textSuffix>

<bsctext>

<fontsize>24</fontsize>

</bsctext>

<xAP>

<schema>xAPBSC</schema>

<uid>FF00D808</uid>

<source>dbzoo.livebox.jeenode:test.temp</source>

</xAP>

<mode>text</mode>

<hide>state</hide>

</button>

How do upload an image?

 

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
(No subject)

min and max buttons for xml code in above post

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
How to convert to applet?

I have read the wiki, but I am none the wiser. 

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
A crash:-(

here is the debug

 

 

# lua minmax.lua

lua: minmax.lua:35: attempt to compare nil with number

stack traceback:

        minmax.lua:35: in function 'callback'

        /usr/share/lua/5.1/xap/init.lua:392: in function 'dispatch'

        /usr/share/lua/5.1/xap/init.lua:97: in function 'fun'

        /usr/share/lua/5.1/pl/list.lua:360: in function 'foreach'

        /usr/share/lua/5.1/xap/init.lua:96: in function 'callback'

        /usr/share/lua/5.1/xap/init.lua:203: in function 'dispatch'

        /usr/share/lua/5.1/xap/init.lua:117: in function 'process'

        minmax.lua:97: in main chunk

        [C]: ?

It seems that it doesnt like the fact that jeenodes can have '?' in the text field when they fire up - ie there is a period between the hah booting and creating the endpoint and valid data being received from the jeenode. In this time the text field will output '?' - example below:-
xap-header
{
v=12
hop=1
uid=FF00D808
class=xAPBSC.info
source=dbzoo.livebox.jeenode:test.temp
}
input.state
{
state=?
text=?
}
This can also occur if the TTL times out.

 

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Conversion

I'll convert the current version for you tonight, as is.  I'll then look at trying to make it more flexible, it just might take a while.  What I will do is add more notes into the existing code, and then perhaps you can add your own.

I can put some error checking in place for that sort of thing, the output you provided is very helpful, if you get any other errors just post like that it again,

Thanks

Karl

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
Many Thank you's

As is would be great, although if you could trap that error, it would be good as it happens a lot.

As is, I can work out some more endpoints and add those, or just make a new copy of the applet for each temperature (expecting Brett to whince hear and say its not efficient) ;)

 

Anyway, looks cool on my joggler!

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Brett

I think Brett is likely to wince at the code anyway!!

brett
Offline
Providence, United States
Joined: 9 Jan 2010
The code is pretty code

I was following the thread and the CODE is pretty damn good.  My only suggestion would be have some sort of sliding windows of max/min over a period.   Unless knowing max/min for the entire time the unit has been up is the objective.

Nice one Karl, I think you are getting it !

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Thanks Brett

Thanks Brett, I'm getting there slowly.  I'll have a stab at the rolling window, if this is coded correctly I guess the code could be used for both a time frame or entire time.

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
thanks guys, I suggested a 24

thanks guys, I suggested a 24 hour window in the original post. 

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
MaxMinApplet

Ok, here's an Applet, just drop this in the plugboard directory and restart the HAH/plugboard service.

If you read through it, you can see that the time frame is customisable, currently set to 24 hours.  It records any new minimum or maximum temperatures and resets a timer if a new minimum or maximum temperature is recorded.  If after the timeframe no new temperatures have been recorded it sets the minimum and maximum to be the current temperature, as clear as mud I know, but I think it's what you asked for.

Alan, it should also ignore "?" temperatures, although other non-numeric values will cause it to fail.  I need to improve this.  I also need to look at the arrays for multiple sensors, but I though it best to get it working in principle first.

Brett, I've struggled with local and global variables a bit, the code works, but I think I could improve it.  If you could give me some pointers when you get a minute I'd appreciate it, thanks.

AttachmentSize
maxminApplet.lua 3.24 KB
Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
Something is not right

Karl

I tried this today, but although the endpoints are generated, they never get any values in the messages ie:

 

xap-header

{

v=12

hop=1

uid=FF00D811

class=xAPBSC.info

source=dbzoo.livebox.Plugboard:maxtemp

}

input.state

{

state=?

text=?

}

Probably something to do with the error trap, but I cant see it?

 

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Check Monitored Endpoint

Did you remember to alter the sensor you're monitoring?

-- We want a temperature change to trigger our routine
  f:add("xap-header","source", "dbzoo.livebox.dev.Controller:1wire.1")
Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
I did, but there is a sensor

I did, but there is a sensor there anyway

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Dev System Endpoint

There is a sensor there, but I've got this on my dev system, so in the middle it says dev, did you take that out ?

  f:add("xap-header","source", "dbzoo.livebox.dev.Controller:1wire.1")

becomes

f:add("xap-header","source", "dbzoo.livebox.Controller:1wire.1")

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
Didnt spot thatWhich might

Didnt spot that

Which might explain why its burst into life. 

Doesnt explain why it didnt work the first time unless I had finger trouble. 

I can see it on XFX now, and the virtual LCD, but the joggler wasnt working. I tracked this to the UID changing and that is all working now. 

Many, many thanks for your great work!

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
Time frame

I dont want to take anything away from your work Karl- its great, but I am thinking about ways to make it better. (as I am sure you are)

Looking at the timeframe code, it looks like it will reset randomly in a 24 hour period if the min or max havent been exceeded in the last 24 hours. The 24 hours would, I think, start when the applet starts, so whenever the box is rebooted. This may cause the max temp to reset in the middle of the day, giving a false impression of the max temp for the last 24 hours. I am primarily thinking Greenhouse here.

The utopia would of course be a sliding window, but I can see that that would mean recording every temperature change and the time. Perhaps some Pachube integration could do this?

Failing that would it be possible to set different timers for these and have them expire at a specific time? I havent thought this all the way through, but having the min temp reset at sundown would seem logical?

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Next Version ??

Yes, I had also thought of all those points.  I implemented the timeframe windows in as easy was as possible.  It should be a sliding window, as long, as you point out, the HAH isn't reset.  The existing window is per monitored temp, not per min and max temp as I guess it should be.  So individual timers per min/max per monitored temp would be the right thing to do.

This is an interesting exercise.

I've just remembered, you can place a call to Pachube that will return the min and max values over a specified time, now if I could just get my head around JavaScript the solution might be very simple.

EJ-Ambient
Offline
Ringwood, United Kingdom
Joined: 5 Aug 2011
Outside Temperature

Hi All

I've got an outside weather-station and I'd like to min-max the temp - what do I need to change the statement .....

-- We want a temperature change to trigger our routine
  f:add("xap-header","source", "dbzoo.livebox.CurrentCost:temp")

For the following ....

xAPSource = sanday.cumulus.ASROCK

xAPClass and xAPSection = weather.report

key = TempC

Thanks in advance

;-) EJ

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
Simple way

EJ

The simple way is to use xfx viewer. If you dont have it, get it from here http://www.edjo.pwp.blueyonder.co.uk/edward/xAP/xFx/viewer_main.htm#

Then look at the endpoint that is reporting the temperature you are interested in and copy the source from the text in the bottom righthand window.

Hope that helps

Alan

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
XFX to the Rescue

Using XFX this is what a xAP message looks like from the device that you might want to monitor.  So cut and paste the source into the code, and that should be it.

xap-header
{
v=12
hop=1
uid=FF00DB80
class=xAPBSC.event
source=dbzoo.livebox.Controller:1wire.1
}
input.state
{
state=on
text=24.4
displaytext=HAH-Temp 24.4
}

 

-- We want a temperature change to trigger our routine
  f:add("xap-header","source", "dbzoo.livebox.CurrentCost:temp")

 

-- We want a temperature change to trigger our routine
  f:add("xap-header","source", "dbzoo.livebox.Controller:1wire.1")

EJ-Ambient
Offline
Ringwood, United Kingdom
Joined: 5 Aug 2011
Bit more to it --

Thanks for the rapid response...however, here's the xFx view....what do I put into the f:add() function?

xap-header
{
  v=12
  hop=1
  uid=FF437500
  class=weather.report
  source=sanday.cumulus.ASROCK
}
weather.report
{
  UTC=16:35
  DATE=20120208
  WindM=1.6
  WindK=2.5
  WindGustsM=3.1
  WindGustsK=5.0
  WindDirD=360
  WindDirC=NNW
  TempC=1.3
  TempF=34.3
  DewC=-1.6
  DewF=29.1
  AirPressure=1031.4
}

much appreciated - getting very cold tonight!!!

 

EJ

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Different

OK, you're going to need to change two things.  your source is "sanday.cumulus.ASROCK", but you also need to change some other parts of the code.  Get the maxminApplet.lua script and look for these lines :-

-- Create a local variable and put the current temperature in it
  CurrTemp = frame:getValue("input.state","text")

Now you need to change the getValue statement to get the name of the value you want, so change "input.state" to "weather.report", this is the section it's getting the value from, and change "text" to "TempC".

That should do it.

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
OMG!

I must have learnt something - I was going to suggest that, but wasnt confident that I was right.

EJ-Ambient
Offline
Ringwood, United Kingdom
Joined: 5 Aug 2011
Debug Log

Hi... now getting

Loading /etc/plua: variable 'CurrTemp' is not declared
stack traceback:
    [C]: in function 'error'
    /usr/share/lua/5.1/pl/strict.lua:40: in function </usr/share/lua/5.1/pl/strict.lua:38>
    (tail call): ?
    /etc/plugboard/MinMaxTempApplet.lua:36: in function 'callback'
    /usr/share/lua/5.1/xap/init.lua:392: in function 'dispatch'
    /usr/share/lua/5.1/xap/init.lua:97: in function 'fun'
    /usr/share/lua/5.1/pl/list.lua:360: in function 'foreach'
    /usr/share/lua/5.1/xap/init.lua:96: in function 'callback'
    /usr/share/lua/5.1/xap/init.lua:203: in function 'dispatch'
    /usr/share/lua/5.1/xap/init.lua:117: in function 'process'
    /etc/plugboard/plugboard.lua:73: in main chunk
    [C]: ?
lugboard/MinMaxTempApplet.lua     [ Max-Min Monitor ]

 

EJ

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Elliot,Make sure the line

Elliot,

Make sure the line looks like this, because I don't think it does :-

 

-- Create a local variable and put the current temperature in it
  CurrTemp = frame:getValue("weather.report","TempC")

 

And if it does, are you sure you've downloaded the latest version of the Applet, you should see the following lines close to the top of the code :-

 

 

info={
   version="3.0", description="Max-Min Monitor"
}

-- setup some variables
  MinTemp = 999
  MaxTemp = 999
  CurrTemp = 999

 

 

EJ-Ambient
Offline
Ringwood, United Kingdom
Joined: 5 Aug 2011
Yup - it does

It looks exactly  like your snippet....

The source is the latest download....

I see exactly what's written above...

Sorry...

 

EJ

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Fixed It

Change this :-

 

  CurrTemp = frame:getValue("weather.report","TempC")

 

To this :-

 

  CurrTemp = frame:getValue("weather.report","tempc")

 

The difference is the case, it must be lowercase!

EJ-Ambient
Offline
Ringwood, United Kingdom
Joined: 5 Aug 2011
Chuffin' case sensitive

Whoda thought it?  Blinkin' case sensitive in one location but not in another....I'll keep that one in the bag of eternal delights!

It works!  lower case !!!!!

Thanks

I can now see max and min temperatures from my outdoor weather station.....just a cool 1.2C at present, but I've a feeling it'll get much chillier later.....

EJ

 

Humm..that sounded a bit snippy...sorry guys, I realise that you can't be held responsible for other coder's prediliction for Upper and Lower case variable names......!

Got down to -0.4C last night.....cool!....... ;-) EJ

g7pkf
Offline
United Kingdom
Joined: 11 Jan 2011
WOW

Well i saw this and thought "here we go again" trash both HAH and Joggler trying to add functionality.

 

But no it works perfecto (well almost)

 

the only grief i have is the ststic joggler text is behind the reading so the reading is un-readable (if that makes sense)

 

Dean

 

P.S Thank you all

Alanmh
Offline
Reading, United Kingdom
Joined: 7 Jul 2010
Not really

Can you post a scren shot and the offending code?

Hardware Info