From: Jim S. <js...@sy...> - 2007-10-23 17:36:18
|
I use the Process_Item structure within MrHouse to run digitemp and dump = the results into a file - which I have code to process and transfer the = results into $misc variables for other programs to use - and map to the weather variables - here is the code; # Program: Reads the temperature sensors on the OneWire Bus # Author: J. Serack # Orginal date: May 15, 2005 # Changed date: May 30, 2005 # This next line categorizes the program for program code control # Category =3D iButtons # This next line provides a description of the code in the setup control #@ This code reads the temperature sensors on the OneWire Bus using = Digitemp ################# Assumptions and Definitions ################################## # Assumes that digitemp is installed and there is a symbolic link to the executable defined as digitemp # my $digitempserialport =3D"/dev/ttyS1"; my $digitempreadspeed =3D 1000; my $digitemprcfile =3D"/usr/local/misterhouse/thislocation/data/onewire/.digitemprc"; my $digitempinitresultfile =3D"/usr/local/misterhouse/thislocation/data/onewire/ibuttoninit.data"; my $digitempresultfile =3D"/usr/local/misterhouse/thislocation/data/onewire/ibutton.data"; $v_iButton_readtemps =3D new Voice_Cmd "Read the iButton temperature = buttons"; $v_iButton_readtemps-> set_info('This reads all all iButton temperature devices.'); $ibutton_read =3D new Process_Item("digitemp -c$digitemprcfile -a -r$digitempreadspeed"); $ibutton_init =3D new Process_Item("digitemp -c$digitemprcfile -i -s$digitempserialport"); $v_iButton_init =3D new Voice_Cmd "Initialize digitemp"; $v_iButton_init-> set_info('This initializes the iButton devices serial numbers.'); ################ Definitions of Ibuttons to temperature names ################ # # Map Ibutton temperature sensors by ID to meaningful names # This insures that a missing sensor does not affect the digitemp = mapping # to temperature names and values. # #DS1820/DS18S20/DS1920 Temperature Sensor $Misc{ID10AAB7ED000800D4} =3D "Temperature_pool_water_high"; $Misc{TS10AAB7ED000800D4} =3D "TempSpare3"; #DS1820/DS18S20/DS1920 Temperature Sensor $Misc{ID102BD53100080088} =3D "Temperature_pool_water_low"; $Misc{TS102BD53100080088} =3D "TempSpare2"; #DS1820/DS18S20/DS1920 Temperature Sensor $Misc{ID1009D7ED000800C0} =3D "Temperature_pool_air"; $Misc{TS1009D7ED000800C0} =3D "TempSpare4"; #DS1820/DS18S20/DS1920 Temperature Sensor $Misc{ID109BF5ED00080064} =3D "Temperature_pool_water"; $Misc{TS109BF5ED00080064} =3D "TempSpare1"; #DS1820/DS18S20/DS1920 Temperature Sensor $Misc{ID106EE53100080092} =3D "Temperature_basement"; $Misc{TS106EE53100080092} =3D "TempSpare6"; #DS1820/DS18S20/DS1920 Temperature Sensor $Misc{ID107DC13100080077} =3D "Temperature_outside"; $Misc{TS107DC13100080077} =3D "TempSpare5"; #digitemp 10DFCC31000800A9 : DS1820/DS18S20/DS1920 Temperature Sensor $Misc{ID10DFCC31000800A9} =3D "Temperature_wet_test"; $Misc{TS10DFCC31000800A9} =3D "TempSpare7"; #digitemp 10DFCC31000800A9 : DS1820/DS18S20/DS1920 Temperature Sensor $Misc{ID10EADDED0008000D} =3D "Humidity_wet_bulb"; $Misc{TS10EADDED0008000D} =3D "TempSpare8"; $Misc{ID105BDEED00080073} =3D "Humidity_dry_bulb"; $Misc{TS105BDEED00080073} =3D "TempSpare9"; # # ################ Initialization to run once ################################## # my $initready; # Make sure the read is only run after the init is = complete. if ($Reread or $Startup or said $v_iButton_init) { $initready =3D 0; set_output $ibutton_init $digitempinitresultfile; start $ibutton_init; } if (done_now $ibutton_init) { $initready =3D1; # ROM assignment line looks like #ROM #0 : 10A8BC31000800D9 for my $data (file_read $digitempinitresultfile) { next unless $data =3D~ /ROM \#(\d+) : (\S+)/; $Misc{"DigitempID$1"}=3D $2; print "$1 $2 \n"; } } ################ Regular Code to get the temperature ######################### # my $ID; my $Tempspare; my $Tempname; if (new_minute 1 or said $v_iButton_readtemps) { set_output $ibutton_read $digitempresultfile; start $ibutton_read if $initready; } # Data looks like this: Feb 28 22:44:16 Sensor 0 C: 3.01 F: 37.42 if (done_now $ibutton_read) { for my $data (file_read $digitempresultfile) { next unless $data =3D~ /Sensor (\d+) C: (\S+) F: (\S+)/; next if $3 > 180; # False readings look like 185 # Looking up by the order of reading which sensor is which # referenced to its name by the ID of the ibutton device $ID =3D $Misc{"DigitempID$1"}; $Tempname =3D $Misc{"ID$ID"}; $Tempspare =3D $Misc{"TS$ID"}; print "$Tempname temp=3D$2\n"; # Putting the temperatures into the weather hash for plotting and use $Weather{$Tempspare} =3D $2; $Weather{$Tempname} =3D $2; } } -----Original Message----- From: mis...@li... [mailto:mis...@li...] On Behalf Of = Tim Sailer Sent: October 23, 2007 1:07 PM To: jr...@io...; The main list for the MisterHouse home automation = program Subject: Re: [mh] IButton Help request On Tue, October 23, 2007 10:58, Joel Davidson wrote: > Jocelyn, > > Here's the code I use to read a couple of temp sensors with mh. I=20 > don't know if this will help or not. This is some of the earlier code = > I wrote for mh, and looking at it now I don't think I need the=20 > Generic_Items to hold the temp, but it seems to work... And then=20 > again I really don't see much functional difference between my code=20 > and yours. > > Joel > ------------------------------------------------------------ > $Garage_Temp_b =3D new iButton '10000800128eb8'; $WineCellar_Temp_b = =3D=20 > new iButton '100008000524ed'; $Garage_Temp =3D new Generic_Item; > $WineCellar_Temp =3D new Generic_Item; > > if ($New_Minute) { > $Garage_Temp =3D read_temp $Garage_Temp_b; > $WineCellar_Temp =3D read_temp $WineCellar_Temp_b; > } > ------------------------------------------------------------ I've done it another way. I have a process (owfs) collection the data, = and writing the data I want to a text file that is simply: var|value var1|value var2|value Then I use the following code to pull it into MH. Maybe this isn't the = best way of doing it, but it's been working for a couple of years for me. # # ## get weather from txt file, pushs to status line. ## ## Tim Sailer 9/15/05 ## # # File is simply lines with 2 values separated by a | # var_value|value # WindSpeed|3.5 # # I run a script that dumps the file into /tmp, and I read it once a = minute. # This is rough, but it works, in case you have data from somwhere with = no # direct way to get it into MisterHouse # # noloop=3Dstart my @ar1; my $wcount=3D0; my $keyword; my $keyval; my $temperature; # noloop=3Dstop if (time_cron('0,5,10,15,20,25,30,35,40,45,50,55 * * * *') || $Startup) { open (WIN,'</tmp/weather.txt'); while (<WIN>) { chomp; ($keyword,$keyval)=3Dsplit(/\|/,$_); if ($keyword eq "") { next; } $wcount++; $Weather{$keyword}=3D$keyval; logit ("/var/log/mh/weather.log","$keyword,$keyval"); } close WIN; $temperature =3D $Weather{TempOutdoor} if $Reload; $Weather{RainTotal}=3D$Weather{Rain}; $Weather{WindSpeed} =3D sprintf("%3.1f",$Weather{WindSpeed}); $Weather{Summary_Short}=3D sprintf("%3.1f %3d%% %4.2f", $Weather{TempOutdoor}, $Weather{HumidOutdoor}, $Weather{Rain}); $Weather{Wind} =3D " $Weather{WindSpeed} $Weather{wind_dir}"; set $fBR round $Weather{FBedroom}; set $attic round $Weather{Attic}; set $by round $Weather{TempOutdoor}; set $solar round $Weather{solar}; set $garage round $Weather{garage}; } -- Tim Sailer Coastal Internet, Inc. www.buoy.com 631-399-2910 -------------------------------------------------------------------------= This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ ________________________________________________________ To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=3D1365 |