Hi so I have been trying for weeks to get my Condensation Prediction App working with no luck. (I have minimum to no coding experience, but I can follow along somewhat. I have assembled a mash of code from all over the place but I cant get it working.)
I am sure someone will be able to look at it and suggest fixes in 10 seconds!
Issues...
- I dont think the device can see the setting in the app, leading to "java.lang.NullPointerException: Cannot get property 'outsideTempDevice' on null object on line 37 (method pollSensors)" error
- The goal is to be able to show the prediction of the device in the dashboard.
Anyone fancy helping me out?
---Here is the device code----
definition(
name: "Condensation Prediction App",
namespace: "KHR1", // Replace with your desired namespace
author: "Your Name", // Replace with your name
description: "Predicts condensation based on temperature and humidity",
category: "Convenience",
iconUrl: "",
iconX2Url: ""
)
preferences {
section("Sensors") {
input "outsideTempDevice","capability.temperatureMeasurement", title: "Outside Temperature Sensor", multiple: false, required: true
input "insideTempDevice", "capability.temperatureMeasurement", title: "Inside Temperature Sensor", multiple: false, required: true
input "insideHumidityDevice", "capability.relativeHumidityMeasurement", title: "Inside Humidity Sensor", multiple: false, required: true
}
}
def installed() {
initialize()
}
def updated() {
unsubscribe()
initialize()
}
def initialize() {
// Create or update the virtual device
createOrAdjustVirtualDevice()
}
def createOrAdjustVirtualDevice() {
def deviceName = "VirtualCondensationPrediction2"
def deviceNamespace = "KHR1"
def deviceNetworkId = "d5dafb13"
def existingDevice = getChildDevices().find { device.deviceNetworkId == deviceNetworkId }
if (existingDevice) {
existingDevice.deviceNetworkId = deviceNetworkId
existingDevice.updateDataValue("outsideTempDevice", deviceSettings.outsideTempDevice)
existingDevice.updateDataValue("insideTempDevice", deviceSettings.insideTempDevice)
existingDevice.updateDataValue("insideHumidityDevice", deviceSettings.insideHumidityDevice)
} else {
addChildDevice(deviceNamespace, deviceName, deviceNetworkId)
sendEvent(name: "outsideTempDevice", value: deviceSettings.outsideTempDevice)
sendEvent(name: "insideTempDevice", value: deviceSettings.insideTempDevice)
sendEvent(name: "insideHumidityDevice", value: deviceSettings.insideHumidityDevice)
}
}
---Here is the device code-----
metadata {
definition (name: "VirtualCondensationPrediction2", namespace: "KHR1", author: "Your Name"){
capability "Sensor"
command "setcondensationPrediction", ["STRING"]
attribute "condensationPrediction", "String"
command "setoutsideTemp", ["NUMBER"]
attribute "outsideTemp", "Number"
command "setinsideTemp", ["NUMBER"]
attribute "insideTemp", "Number"
command "setinsideHumidity", ["NUMBER"]
attribute "insideHumidity", "Number"
}
}
def installed() {
initialize()
}
def updated() {
unsubscribe()
initialize()
}
def initialize() {
// Assuming the deviceNetworkId is set correctly in the app
def deviceNetworkId = "d5dafb13"
// Fetch device settings from the app using deviceNetworkId
def outsideTempDevice = getChildDevice(deviceNetworkId).getDataValue("outsideTempDevice")
def insideTempDevice = getChildDevice(deviceNetworkId).getDataValue("insideTempDevice")
def insideHumidityDevice = getChildDevice(deviceNetworkId).getDataValue("insideHumidityDevice")
runEvery15Minutes(pollSensors)
}
def pollSensors() {
def outsideTemp = getTemperature(deviceSettings.outsideTempDevice)
def insideTemp = getTemperature(deviceSettings.insideTempDevice)
def insideHumidity = getHumidity(deviceSettings.insideHumidityDevice)
def prediction = predictCondensation(outsideTemp, insideTemp, insideHumidity)
setAttribute("outsideTemp", outsideTemp)
setAttribute("insideTemp", insideTemp)
setAttribute("insideHumidity", insideHumidity)
setAttribute("condensationPrediction", prediction)
}
def calculateDewPoint(temperature, relativeHumidity) {
def a = 17.625
def b = 243.04
def alpha = (a * temperature) / (b + temperature) + Math.log10(relativeHumidity / 100)
return (b * alpha) / (a - alpha)
}
def predictCondensation(outsideTemp, insideTemp, insideHumidity) {
def windowSurfaceTemp = (insideTemp + outsideTemp) / 2
def dewPoint = calculateDewPoint(insideTemp, insideHumidity)
if (windowSurfaceTemp <= dewPoint) {
return "Condensation is likely to occur."
} else {
return "Condensation is unlikely."
}
}
// Helper methods to get sensor values using capability identifiers
def getTemperature(device) {
return device.currentValue("temperature")
}
def getHumidity(device) {
return device.currentValue("humidity")
}
thanks in advance!