If your code works well, than all is well. If I may offer advice: whenever
you have repeated code, separate it into a funciton. When testing, one test
must include >= or <= e.g. if heat_index is 45, nothing will get done. If
rain is 0,9 or lower, it will be ignored. As lazy as I am, I hate criptic
things like '${vars[41]}'. Luckily, your script does not need complex logic
but a simple stright flow of not multiply correlated rules.
You may find it usefull how parsing WeeWX variables is done in my script.
My parsing directly produces integers when needed, fixes the above problem
with the rain below 0,99 being ignored plus leaves items which should be
left alone. I will mostly not translate Croatian words to avoid creating
mistakes, but that should not present a problem.
I did manual install of WeeWX to RPi Zero and use RPi Zero as a root user,
so paths and rights may need to be adjusted for others. Most will say it is
impossible to set bash variables from awk, but I do not care. Nor about
comments on eval. Nor about using root account on Zero. Such comments are
not how security is assured.
1) prepare a WeeWX report we will be parsing. I modified this file, but can
be any skin:
/home/weewx/skins/Seasons/skin.conf
and added there
[[VremStanica]]
encoding = strict_ascii
template = VremStanica.txt.tmpl
then I created the file:
/home/weewx/skins/Seasons/VremStanica.txt.tmpl
and placed into it data I want extracted from WeeWX; adjust as needed. Name
in the first colument will automatically become the variable name in the
script. Note raw (epoch) times and lack of labels. It simplifes parsing
when labels are stuck to the numbers.
Time $current.dateTime.raw
InTemp $current.inTemp.format(add_label=False)
OutTemp $current.outTemp.format(add_label=False)
Dewpoint $current.dewpoint.format(add_label=False)
Humidity $current.outHumidity.format(add_label=False)
WindSpeed $current.windSpeed
WindCardinal $current.windDir.ordinal_compass
WindDirection $current.windDir
RainRate $current.rainRate.format(add_label=False)
Sunrise $almanac.sun.rise.raw
Sunset $almanac.sun.set.raw
After every report generation, we have the file with the last set of data
created. For my manual install, it is located at:
/home/weewx/public_html/VremStanica.tx
2) parse generated data into variables in a bash script.
Oneliner awk with just the single last else print statement from bellow
will parse all the WeeWx data from above and automatically assign variable
names from that same file. My locale is using comma as a decimal separator.
I round up RainRate so a 0,1 does not get integered to 0 - no rain.
Cardinal wind directions I leave unchanged (as letters). All other values
get converted to integers (no decimal separator).
eval $(awk '
{
if ($1 == "RainRate" && $2 > "0,0")
print ""$1"=\""int ($2+1)"\""
else if ($1 == "WindCardinal") # leave original
print ""$1"=\""$2"\""
else # convert to integer
print ""$1"=\""int ($2)"\""
}' /home/weewx/public_html/VremStanica.txt)
The above converts the entire VremStanica.txt into bash variables with the
same names. We can use them normally in the script without any extra work.
3) automate based on the parsed data. SmartHome needs complicated rules
wich must work together: 5 rules can close a shutter and overlap (closed
manually, it is raining, it is sunset, it is cold, strong wind...). Which
rule and when is allowed to lift the shutter? They all must cooperate
perfectly. That would be out of scope in this group.
The following system can be well used for lower amount of events that need
tracking. Easy to read and use.
# setup initial location for the flag file RoletaKisaFlag
RoletaKisaFlag="/root/RoletaKisaFlag"
# write the single piece of data $RoletaDignuta into a flag file, creating
it; Filename stands for its function (in my case: ShuttersRainFlag). File
iself can also be used as a timestamp for the action. After the } a
distinguishing addition (1,2,3 or a,b,c, or Kitchen, Balcony...) can be
made for similar flags.
echo "$RoletaDignuta" > "${RoletaKisaFlag}"
# make a timestamp when (a RoletaKisa rule was activated and) the
particular flag used
touch "${RoletaKisaFlag}"
# read in the timestamp from the particular flag
RoletaKisaFlagAge=$(date -r "${RoletaKisaFlag}" +%s)
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/weewx-user/8ede0467-3f26-4543-a5bc-9fe4ead26540%40googlegroups.com.