Home‎ > ‎Home Automation Project‎ > ‎

Code - Read 1wire & update RRD

Script to read values from the 1-wire network and update the databases

#!/bin/bash
# Jan Larsson 2013

# Value for your pulses on  the power meter.
OMRAKNINGSFAKTOR=1.0

TempSensor_1="28.FAED2F040000"
TempSensor_2="28.FFE32F040000"
Counter_1="1D.AD8B0F000000"
TempSensor_gvhallf="10.D0212A020800"
TempSensor_gvhallr="10.8B1C2A020800"
TempSensor_gvdatarumf="10.1C1E2A020800"
TempSensor_gvdatarumr="10.FB202A020800"
Sensor_light="20.9D2C10000000"
TempSensor_ute="10.6A112A020800"

RRDDataDirectory="/home/jl/rrddata/"
RRDDataFile_1="temp_1.rrd"
RRDDataFile_2="temp_2.rrd"
RRDDataFile_3="el_vp.rrd"
RRDDataFile_4="temp_gvhall.rrd"
RRDDataFile_5="temp_gvdatarum.rrd"
RRDDataFile_6="light.rrd"
RRDDataFile_7="ute.rrd"

# Get temps form OWFS
Temp_1=`cat /mnt/1wire/$TempSensor_1/temperature|sed -e s/" "//g|awk '{$1=$1 + 0.005;printf "%.2f", $1}'`
Temp_2=`cat /mnt/1wire/$TempSensor_2/temperature|sed -e s/" "//g|awk '{$1=$1 + 0.005;printf "%.2f", $1}'`
COUNT=`cat /mnt/1wire/$Counter_1/counters.A|sed -e s/" "//g`
VALUE=`echo "$OMRAKNINGSFAKTOR $COUNT" |awk '{printf "%.0f", ($1 * $2)}'`
Temp_gvhallf=`cat /mnt/1wire/$TempSensor_gvhallf/temperature|sed -e s/" "//g|awk '{$1=$1 + 0.005;printf "%.2f", $1}'`
Temp_gvhallr=`cat /mnt/1wire/$TempSensor_gvhallr/temperature|sed -e s/" "//g|awk '{$1=$1 + 0.005;printf "%.2f", $1}'`
Temp_gvdatarumf=`cat /mnt/1wire/$TempSensor_gvdatarumf/temperature|sed -e s/" "//g|awk '{$1=$1 + 0.005;printf "%.2f", $1}'`
Temp_gvdatarumr=`cat /mnt/1wire/$TempSensor_gvdatarumr/temperature|sed -e s/" "//g|awk '{$1=$1 + 0.005;printf "%.2f", $1}'`
Light=`cat /mnt/1wire/$Sensor_light/volt.B|sed -e s/" "//g|awk '{printf "%.6f", $1}'`
Temp_ute=`cat /mnt/1wire/$TempSensor_ute/temperature|sed -e s/" "//g|awk '{$1=$1 + 0.005;printf "%.2f", $1}'`





#Update RRD database
rrdtool update $RRDDataDirectory$RRDDataFile_1 N:$Temp_1
rrdtool update $RRDDataDirectory$RRDDataFile_2 N:$Temp_2
rrdtool update $RRDDataDirectory$RRDDataFile_3 N:$VALUE
rrdtool update $RRDDataDirectory$RRDDataFile_4 N:$Temp_gvhallf:$Temp_gvhallr
rrdtool update $RRDDataDirectory$RRDDataFile_5 N:$Temp_gvdatarumf:$Temp_gvdatarumr
rrdtool update $RRDDataDirectory$RRDDataFile_6 N:$Light
rrdtool update $RRDDataDirectory$RRDDataFile_7 N:$Temp_ute

#write to file for SwitchKing, add + if positive temp.
if [ ${Temp_ute:0:1} == "-" ]; then
# Negative temp with minus sign already
        echo $Temp_ute > /var/www/temp_ute.log
else
# positive temp without + sign  that we now add.
        pos_temp_ute="+"$Temp_ute
echo $pos_temp_ute > /var/www/temp_ute.log
fi


#  echo $Temp_1, $Temp_2, $VALUE
# echo $Temp_gvhallf, $Temp_gvhallr, $Temp_gvdatarumf, $Temp_gvdatarumr, $Light

Comments