Hi,
I currently have them all sending their temp’s to a pi running influx database/grafana via the script below …
What is the easiest way please to add code into this script so that i can also send the temperature values to my Home Assistant so that I can view the sensors in a HA dashboard?
Thanks
Harry
code…
import os
import glob
import time
import urllib
import urllib2
import httplib
import json
import time
from influxdb import InfluxDBClient
client = InfluxDBClient(host=‘192.168.1.10’, port=8086)
client.switch_database(‘influxdb1’)
sensor_1 = ‘/sys/bus/w1/devices/28-020b91773d11/w1_slave’
sensor_1_t = 0
while True:
def read_temp(sensor):
f = open(sensor, 'r')
lines = f.readlines()
f.close()
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
return temp_c
sensor_1_t = read_temp(sensor_1)
print("Temp: " + str(sensor_1_t))
json_body = [
{
"measurement": "YOUR_MEASUREMENT",
"tags": {
"Device": "YOUR_DEVICE",
"ID": "YOUR_ID"
},
"fields": {
"lounge_temp": sensor_1_t,
}
}
]
client.write_points(json_body)
time.sleep(300)