How to make a calculation
How to make a calculation
I hope somebody can help me with a simple calculation, I can't find out how to do it.
I want to make a variable which contains the rain of the actual year, my rain gauge (Oregon Scientific PCR800) only gives the total accumulated rain so I have to subtract the total rain with the rain last year to get the rain this year.
I've made three extra properties for this sensor Variable 0,1 and 2, Variable 0 has to be filled with the total rain of the sensor, I can do that with a task PV sub but how to do that automatic?
Variable 1 holds the rain of last year and I looking for a task which fills variable 2 with the result of variable 0 - variable 1 (automatic)
Can somebody help me with this?
Henk
I want to make a variable which contains the rain of the actual year, my rain gauge (Oregon Scientific PCR800) only gives the total accumulated rain so I have to subtract the total rain with the rain last year to get the rain this year.
I've made three extra properties for this sensor Variable 0,1 and 2, Variable 0 has to be filled with the total rain of the sensor, I can do that with a task PV sub but how to do that automatic?
Variable 1 holds the rain of last year and I looking for a task which fills variable 2 with the result of variable 0 - variable 1 (automatic)
Can somebody help me with this?
Henk
-
- HouseBot Guru Extraordinaire
- Posts: 1121
- Joined: Tue Sep 28, 2004 7:49 am
- Location: The Netherlands
Re: How to make a calculation
Hi,
Is the rain gauge connected to a WMR200? If so, how do you get the data into HouseBot? Is that an automatic process where HouseBot is interfaced to the base unit or do you have to run special software to get the data (out of a database or something) and import it into HouseBot? If it can be interfaced directly into HouseBot, I guess a nice script could do way more than just hold a total.
As for a task, just check to see if V0 changes (not equal '_' which is always true) and than do your calculation. This would only make sense if V0 and V1 get updated automatically I guess.
Is the rain gauge connected to a WMR200? If so, how do you get the data into HouseBot? Is that an automatic process where HouseBot is interfaced to the base unit or do you have to run special software to get the data (out of a database or something) and import it into HouseBot? If it can be interfaced directly into HouseBot, I guess a nice script could do way more than just hold a total.
As for a task, just check to see if V0 changes (not equal '_' which is always true) and than do your calculation. This would only make sense if V0 and V1 get updated automatically I guess.
Re: How to make a calculation
No, the rain gauge is connected to Housebot trough a RFXcom tranceiver unit and the problem is, I don't know how to make a script.
The graphics I need I generate with Meteohub, Housebot I use to control the climate in the house but on the main page of the remote I want to see the rain in the actual year.
The graphics I need I generate with Meteohub, Housebot I use to control the climate in the house but on the main page of the remote I want to see the rain in the actual year.
- Attachments
-
- The main page of the HB soft remote (In Dutch)
- HB Main page.jpg (140.52 KiB) Viewed 3703 times
-
- HouseBot Guru Extraordinaire
- Posts: 1121
- Joined: Tue Sep 28, 2004 7:49 am
- Location: The Netherlands
Re: How to make a calculation
I guess i would pay off to get a script going. Many examples online and the helpfile should get you going. Using a script, you are able to do more powerfull stuff with all the data. You could calculate day totals, hourly totals etc etc. What exactly is it you need to know about a script? How to set up the device or the scripting language itself?
Re: How to make a calculation
As I explained in the start of this post, the only ting I need is a task or script thats subtracts the accumulated rain with the last year's total so I have a indication on my main page what's the total rainfall this year.
Other graphics etc will be generated by Meteohub and displayed trough the HB main page.
Other graphics etc will be generated by Meteohub and displayed trough the HB main page.
-
- HouseBot Guru Extraordinaire
- Posts: 1121
- Joined: Tue Sep 28, 2004 7:49 am
- Location: The Netherlands
Re: How to make a calculation
I can't tell you much about task PV's etc because I don't use them because of all the restrictions. I can tell you everything about scripting though. Just tell me what you need to know about the script part.
There is a sample.vb script in the scripts directory which is very easy to read. Just have a look at that. It shows you how to get and set properties from within a script. Calculations are simple once you get the script going.
There is a sample.vb script in the scripts directory which is very easy to read. Just have a look at that. It shows you how to get and set properties from within a script. Calculations are simple once you get the script going.
Re: How to make a calculation
See the script below. It does what you want and is annotated to describe exactly what is being done. This should get you started. Using scripts in HB is actually pretty easy and increases the power of the software several fold.
Happy New Year
Osler
Code: Select all
Dim TotalRainfall
Dim LastYearRainfall
Dim ThisYearRainfall
'Step 1: Get the device property values from HouseBot that you want to manipulate
TotalRainfall = CDbl(GetPropertyValue(OregonScientificPCR800.Variable0))
LastYearRainfall = CDbl(GetPropertyValue(OregonScientificPCR800.Variable1))
'Step 2: Do the math
ThisYearRainfall = TotalRainfall - LastYearRainfall
'Step 3: Place the answer to the question back into the device property that you want
Call SetPropertyValue(OregonScientificPCR800.Variable2, ThisYearRainfall)
'NOTE:
'OregonScientificPCR800 should be changed to whatever the device name is in HouseBot
'I have used CDbl to convert the HouseBot values to a double-precision number assuming
'they are in decimal form. This may not be necessary.
Osler
Re: How to make a calculation
OK, Thanks, I'm going to try this, it should be my first script.
Where do I have to save the script, can I edit it with notepad and what must be the extension, I suppose something like script.vbs or so?
Thanks, Henk
Where do I have to save the script, can I edit it with notepad and what must be the extension, I suppose something like script.vbs or so?
Thanks, Henk
-
- HouseBot Guru Extraordinaire
- Posts: 1121
- Joined: Tue Sep 28, 2004 7:49 am
- Location: The Netherlands
Re: How to make a calculation
Save it as HouseBot\Config\Scripts\YourScript.vbs
Create a script device (same going as setting up a NULL device) and point the device to your script. All questions are asked during device setup. Notepad would do but there are many (free) editers around which support color coding so you can actually read your code better. I use UltraEdit.
You can setup a task to trigger your script. The task would look something like:
If ('Null Devices -> YourNullDevice.Variable0' is Not Equal '_') Then
Change 'Script Devices -> YourScriptDevice.State' to 'Running'
Create a script device (same going as setting up a NULL device) and point the device to your script. All questions are asked during device setup. Notepad would do but there are many (free) editers around which support color coding so you can actually read your code better. I use UltraEdit.
You can setup a task to trigger your script. The task would look something like:
If ('Null Devices -> YourNullDevice.Variable0' is Not Equal '_') Then
Change 'Script Devices -> YourScriptDevice.State' to 'Running'
Re: How to make a calculation
After some trial and error and reading the help file I noticed the device and property name must be included in quotes ". After changing this the script is running.
I'm using the sleep command to run it every minute and it works.
Next question, how to start a script automatically when HouseBot is starting? And how do you upload a script as attachment? The extensions .vbs and.txt are not allowed.
The script:
Dim TotalRain
Dim RegenLastYear
Dim ThisYearRainfall
Dim RegenDitJaar
'Step 1: Get the device property values from HouseBot that you want to manipulate
Do
Sleep (60000)
TotalRain = (GetPropertyValue("TP18RegenMeting.TotalRainfall"))
RegenLastYear = (GetPropertyValue("TP18RegenMeting.RegenLaatsteJaren"))
'Step 2: Do the math
ThisYearRainfall = TotalRain - RegenLastYear
'Step 3: Place the answer to the question back into the device property that you want
Call SetPropertyValue("TP18RegenMeting.RegenDitJaar", ThisYearRainfall )
Loop
I'm using the sleep command to run it every minute and it works.
Next question, how to start a script automatically when HouseBot is starting? And how do you upload a script as attachment? The extensions .vbs and.txt are not allowed.
The script:
Dim TotalRain
Dim RegenLastYear
Dim ThisYearRainfall
Dim RegenDitJaar
'Step 1: Get the device property values from HouseBot that you want to manipulate
Do
Sleep (60000)
TotalRain = (GetPropertyValue("TP18RegenMeting.TotalRainfall"))
RegenLastYear = (GetPropertyValue("TP18RegenMeting.RegenLaatsteJaren"))
'Step 2: Do the math
ThisYearRainfall = TotalRain - RegenLastYear
'Step 3: Place the answer to the question back into the device property that you want
Call SetPropertyValue("TP18RegenMeting.RegenDitJaar", ThisYearRainfall )
Loop
-
- HouseBot Guru Extraordinaire
- Posts: 1121
- Joined: Tue Sep 28, 2004 7:49 am
- Location: The Netherlands
Re: How to make a calculation
If the script had a Running stae when HouseBot was closed, it should maintain the Running state after a restart of HouseBot.
To make sure your script is running, HouseBot supports a so called "Startup" Task. If you create a task with that name and set the script state to running in that task, it should always start.
As for uploading.... haven't done that yet, but there is a scripts section so somehow you should be able to.
To make sure your script is running, HouseBot supports a so called "Startup" Task. If you create a task with that name and set the script state to running in that task, it should always start.
As for uploading.... haven't done that yet, but there is a scripts section so somehow you should be able to.