]>
git.frykholm.com Git - heatpump.git/blob - heatpump.py
1 import piplates
.DAQCplate
as DAQC
3 from decimal
import Decimal
5 import paho
.mqtt
.client
as mqtt
#import the client1
6 from prometheus_client
import start_http_server
, Summary
, Gauge
9 #thermistor reading function
10 def compressor(state
=None):
12 return DAQC
.getDOUTbyte(0)
18 def temp_get(volts
,supply_voltage
=5):
20 ohms
= Decimal(divider_resistor
*supply_voltage
/volts
-divider_resistor
) #calculate the ohms of the thermisttor
22 a
= Decimal(1.298022762e-3)
23 b
= Decimal(2.365068126e-4)
24 c
= Decimal(0.9305914923e-7)
25 #Steinhart Hart Equation
26 # T = 1/(a + b[ln(ohm)] + c[ln(ohm)]^3)
27 temp
= 1/(a
+ b
*ohms
.ln() + c
*ohms
.ln()**3)
28 tempc
= temp
- Decimal(273.15) #K to C
32 print(*data
,sep
=',', file=fp
)
35 fp
= open("/var/tmp/heatpump.csv","w+")
36 start_http_server(8000)
37 running_g
= Gauge('heatpump_running', 'Is the compressor running?')
38 top_g
= Gauge('heatpump_toptemp', 'Temperature at top of tank.')
39 return_g
= Gauge('heatpump_returntemp', 'Temperature at inlet sensor.')
40 gas_g
= Gauge('heatpump_hottemp', 'Temperature at Hot Gas side sensor.')
42 vv_retur
=temp_get(DAQC
.getADC(0,0),DAQC
.getADC(0,8))
43 vv_top
=temp_get(DAQC
.getADC(0,2),DAQC
.getADC(0,8))
44 hetgas
=temp_get(DAQC
.getADC(0,1),DAQC
.getADC(0,8))
45 print("VV retur:",vv_retur
)
46 print("VV top:",vv_top
)
47 print("Hetgas:",hetgas
)
48 print("Kompressor:",compressor())
49 log(fp
, [vv_retur
,vv_top
,hetgas
,str(compressor()[0])])
50 broker_address
="monitor.tranquillity.se"
51 client
= mqtt
.Client("P1") #create new instance
52 client
.connect(broker_address
) #connect to broker
53 client
.publish("heatpump/running",str(compressor()[0]), retain
=True)#publish
54 client
.publish("heatpump/toptemp",str(vv_top
), retain
=True)#publish
55 client
.publish("heatpump/returntemp",str(vv_retur
), retain
=True)#publish
56 client
.publish("heatpump/hottemp",str(hetgas
), retain
=True)#publish
57 running_g
.set(compressor()[0])
59 return_g
.set(vv_retur
)
63 print("Toptemp under 47. Startar kompressor")
66 print("Toptemp över 51. Stänger av kompressor")
67 # import pdb;pdb.set_trace()