Temp min and max
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
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
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.
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()
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?
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
Attachment | Size |
---|---|
maxminv2.lua | 2.25 KB |
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>
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.
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
I think Brett is likely to wince at the code anyway!!
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 !
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.
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.
Attachment | Size |
---|---|
maxminApplet.lua | 3.24 KB |
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")
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")
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.
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
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")
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
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.
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
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
It looks exactly like your snippet....
The source is the latest download....
I see exactly what's written above...
Sorry...
EJ
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!
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
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
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