Last active
June 6, 2024 19:53
-
-
Save boozeman/e191e01ef914e2651544a03a7acf32eb to your computer and use it in GitHub Desktop.
Berry script for Tasmota32. Generate some extra data with BME280 and SHT31 sensors Temperature, Humidity and Pressure data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GhData : Driver | |
var greenhouse_data | |
def greenhouse() | |
# Read needed Sensor data | |
import json | |
var sensors=json.load(tasmota.read_sensors()) | |
var p = sensors['BME280']['Pressure'] | |
var rh = sensors['SHT3X']['Humidity'] | |
var T = sensors['SHT3X']['Temperature'] | |
var switch1 = sensors['Switch1'] | |
var switch2 = sensors['Switch2'] | |
import math | |
# Equivalent sea level pressure - variable ap | |
var elevation = 91 | |
var ap = (p / math.pow(1 - ((0.0065 * elevation) / (T + (0.0065 * elevation) + 273.15)), 5.257)) # in hPa | |
# Absolute Humidity in g/m3 | |
var mw = 18.016 # molar mass of water g/mol | |
var r = 8314.3 # Universal gas constant J/mol/K | |
var ah = (6.112 * math.pow(2.718281828, (17.67 * T) / (T + 243.5)) * rh * mw) / ((273.15 + T) * r) | |
# Saturation Vapour Pressure (pa) | |
var SVP = 610.7 * (math.pow(10, (7.5 * T / (237.3 + T)))) | |
var es = SVP/1000 | |
# Actual Vapour Pressure (kPa) | |
var VPactual = (rh * SVP/1000)/100.0 | |
# Vapour Pressure Deficit in kPa | |
var VPD = ((1 - (rh/100))* SVP)/1000 | |
# Humidity Deficit of the air g/m3 | |
var PRT = SVP / (8.31 * (273.15 + T)) | |
# Humidity Defict of the air at 0% RH, Water mol mass mw is 18.016 | |
var HD = PRT * mw | |
HD = HD - (HD * rh/100) | |
var sw1 = (switch1 == 'ON') ? true : false | |
var sw2 = (switch2 == 'ON') ? true : false | |
self.greenhouse_data = [ap,ah*1000,es,VPactual,VPD,HD,sw1,sw2] | |
return self.greenhouse_data | |
end | |
def every_second() | |
if !self.greenhouse return nil end | |
self.greenhouse() | |
end | |
def web_sensor() | |
import string | |
if !self.greenhouse_data return nil end #- exit if not initialized -# | |
var msg = string.format( | |
"{s}SeaPressure2{m}%.1f kPa{e}".. | |
"{s}AbsoluteHumidity{m}%.2f g/m3{e}".. | |
"{s}Saturation Vapour Presusre{m}%.2f kPa{e}".. | |
"{s}VPactual{m}%.2f kPa{e}".. | |
"{s}VPD{m}%.2f kPa{e}".. | |
"{s}Humidity Deficit{m}%.2f g/m3{e}".. | |
"{s}Alarm Switch1{m}%s{e}".. | |
"{s}Door Switch{m}%s{e}", | |
self.greenhouse_data[0],self.greenhouse_data[1],self.greenhouse_data[2],self.greenhouse_data[3],self.greenhouse_data[4],self.greenhouse_data[5],self.greenhouse_data[6],self.greenhouse_data[7]) | |
tasmota.web_send_decimal(msg) | |
end | |
def json_append() | |
if !self.greenhouse_data return nil end | |
import string | |
var msg = string.format(",\"GhData\":{\"SeaPressure2\":%.1f,\"AbsoluteHumidity\":%.2f,\"Saturation Vapour Pressure\":%.2f,\"VPactual\":%.2f,\"VPD\":%.2f,\"Humidity Deficit\":%.2f,\"Alarm Switch\":\"%s\",\"Door Switch\":\"%s\"}", | |
self.greenhouse_data[0],self.greenhouse_data[1],self.greenhouse_data[2],self.greenhouse_data[3],self.greenhouse_data[4],self.greenhouse_data[5],self.greenhouse_data[6],self.greenhouse_data[7]) | |
tasmota.response_append(msg) | |
end | |
end | |
GhData = GhData() | |
tasmota.add_driver(GhData) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment