Hi,
I've wrote some code to get the Oregon Scientific Weather Sensor into Domoticz using the RTL_433 code from
https://github.com/merbanan/rtl_433. Currently supporting 54 different 433mhz sensors.
Install the following:
Run the following code to create a logfile from the output of rtl_433
Code: Select all
pi@raspberrypi:~$ screen
pi@raspberrypi:~$ rtl_433 -R 12 -q -F csv > /home/pi/log/rtl_output.csv
Open the logfile and get the ID's from the sensors, create the corresponding virtual sensors and note the IDX
Create a python-script with the following code and change the necessary variables to your settings, server location, ID's etc. :
Code: Select all
import time
import urllib
def follow(thefile):
thefile.seek(0,2)
while True:
line = thefile.readline()
if not line:
time.sleep(0.1)
continue
yield line
if __name__ == '__main__':
ID = ['32','198','220'] #ID's of weather sensors
IDX = [12,13,14] #corresonding IDX in Domoticz
Server = "http://10.5.0.131:8080" #location of Domoticz server
Log = "/home/pi/log/rtl_output.csv" #location of logfile
msg = "RTL_update" #message shows up in log
#Start rtl_433 with the following options for the Oregon Scientific Weather Sensor:
#pi@raspberrypi:~$ rtl_433 -R 12 -q -F csv > /home/pi/log/rtl_output.csv
logfile = open(Log,"r")
loglines = follow(logfile)
last_id = ""
last_time = time.time()
for line in loglines:
try:
#2016-06-17 15:11:07,Weather Sensor THGR122N,32,2,LOW,24.200,46,,
#date,name,ID,channel,battery status,temperature,humidity,rain,rain?
my_list = line.split(',')
current_id = my_list[2]
if (last_id != current_id) or (float(time.time())-float(last_time) > 20): #send info to Domoticz when ID is different or the last info was send more then 20 sec ago
#print ( str(Server) + "/json.htm?type=command¶m=udevice&idx=" + str(IDX[int(ID.index(my_list[2]))]) + "&nvalue=0&svalue=" + my_list[5] + ";" + my_list[6] + ";0" )
httpresponse = urllib.urlopen( str(Server) + "/json.htm?type=command¶m=udevice&idx=" + str(IDX[int(ID.index(my_list[2]))]) + "&nvalue=0&svalue=" + my_list[5] + ";" + my_list[6] + ";0" )
#send message to domoticz log
httpresponse = urllib.urlopen( str(Server) + "/json.htm?type=command¶m=addlogmessage&message=" + msg)
last_id = current_id
last_time = time.time()
print ("Info send")
except:
print ("Error occured.")
Start a screen and run it.
When everything is going as planned the data should be coming in.
2DO
- Use logrotate to reduce filesize