Several working DS18B20's temp sensors connected to different Pi's running on my home network

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)

You can interrogate your influxDB database from Home Assistant to create sensors:

Hi,

Was hoping to move away from my influx/grafana pi, and somehow have the script send the temps directly to HA (via webhooks?) with each temperature viewable in a dashboard (without any logging)?

Possible?

thanks

There are many ways to talk directly from your pi to Home Assistant.

I used this without issue for years:

If you don’t want to use that custom solution you can publish directly to mqtt from your script. Then create mqtt sensors in home assistant.