New app else statement always being done

So Groovy is kicking my … right now. I need an app to control a whole house humidifier and haven’t found one. So trying to make an app with no luck at the moment. I’ve commented a lot of the code out and have gotten stuck in one spot at the moment and am lost. Trying to compare a temp sensor to a number and getting a null error. Here is parts of the code and error when simulating (doesn’t work if published either).

section("Outside Temprature Sensor") {
    input "ousidetemp", "capability.temperatureMeasurement", required: true, title: "Select Outside Temprature Sensor"

if(outsidetemp.currentTemperature >= 40)// && humiditysensor.currentHumidity < humidity40p)
     if(fanon == 'on') 

11:13:35 AM: error java.lang.NullPointerException: Cannot get property ‘currentTemperature’ on null object

Have tried using outsidetemp.currentValue(“temperature”) and it doesn’t work either.

I know its probably something stupid but I’ve been stuck for hours.

So thought it was going to be something stupid. In the preferences I can’t spell. Wrote ousidetemp instead of outsidetemp. Forgot the t. So many hours down the drain.

Okay so new problem. The else statement is always being done. I found if I move the log.debug “using else” line to after the else the log.debug works properly but both switches still change. If the is after the else both switches and the log.debug is done every time. Any thoughts to why the else statement is always being done???

Here is all the code if you want to play.

name: “HVAC Humidifier”,
namespace: “mebaddog2002”,
author: “Michael Goldsberry”,
description: "This is for a whole house humidifier connected to the HVAC system. This app is designed to work with a steam style humidifier that only needs the HVAC fan on. It will turn on the HVAC fan and humidifier when the humidity drops below the set point. It will still work with the evaporate style humidifiers. Just note that it probably wont raise the humidity very much. It will not hurt the system if it comes on. It will only run the humidifier if your thermostat is set to heat. So no need to remove app during summer. You will need some kind of air proving switch so the app can verify that the fan is running. This app will also take into consideration the outside temp and automatically adjust your house humidity level so condensation does not develop on the inside of the windows. ",
category: “My Apps”,
iconUrl: “”,
iconX2Url: “”,
iconX3Url: “”)

	// TODO: put inputs here

preferences {
section(“About App”){
paragraph “This app will control a whole house steam humidifer. It will only work if the thermostat is in the heat mode. You need to install a fan air pressure proving switch in the duct work. This is so the humidifier does not run if the fan is not circulating air. As the outside temperature gets colder it will allow the humidity in the house to lower so condensation does not develop on the windows. During heating if the humidity drops it will turn on the humidifier. If the humidity is to low in the house after the heat turns off it will turn on the HVAC fan and the humidifier to raise the humidity level in the house.”
section(“Thermostat”) {
input “thermostat”, “capability.thermostat”, required: true, title: “Select Thermostat”
section(“Humidity Sensor”) {
input “humiditysensor”, “capability.relativeHumidityMeasurement”, required: true, title: “Select Humidity Sensor”
section(“HVAC Fan Proving Switch”) {
input “fanon”, “capability.switch”, required: true, title: “Select Fan Proving Switch”
section(“Outside Temprature Sensor”) {
input “outsidetemp”, “capability.temperatureMeasurement”, required: true, title: “Select Outside Temprature Sensor”
section(“Whole House Humidifier”) {
input “humidifier”, “capability.switch”, required: true, title: “Select Humidifier”
section(“Target Humidity Level”) {
input “humidity40p”, “number”, required: true, title: “Humidity Level Above 40 Degrees”, defaultValue:45
input “humidity30to39”, “number”, required: true, title: “Humidity Level Between 30 to 39 Degrees”, defaultValue:40
input “humidity20to29”, “number”, required: true, title: “Humidity Level Between 20 to 29 Degrees”, defaultValue:35
input “humidity10to19”, “number”, required: true, title: “Humidity Level Between 10 to 19 Degrees”, defaultValue:30
input “humidity0to9”, “number”, required: true, title: “Humidity Level Between 0 to 9 Degrees”, defaultValue:25
input “humiditylow”, “number”, required: true, title: “Humidity Level Less Then 0 Degrees”, defaultValue:20

def installed() {
log.debug “Installed with settings: ${settings}”



def updated() {
log.debug “Updated with settings: ${settings}”



// TODO: subscribe to attributes, devices, locations, etc.

def initialize() {
subscribe(humiditysensor, “humidity”, humidityControlHandler)
subscribe(fanon, “switch.on”, humidityControlHandler)
subscribe(fanon, “”, humidityControlHandler)

// TODO: implement event handlers.
def humidityControlHandler(evt) {
log.debug “humidityControlHandler called: $evt”

log.debug "fan on state ${fanon.currentSwitch}"
log.debug "Outside temp ${outsidetemp.currentTemperature}"
log.debug “Current humidity is ${humiditysensor.currentHumidity}”
//if(thermostat.thermostatOperatingState == “heat”)
//log.debug “heating”

if(fanon.currentSwitch == “off”) {
log.debug “humidifier off no fan”
if(outsidetemp.currentTemperature >= 40){/* && humiditysensor.currentHumidity < humidity40p) */
log.debug "fan on command sent"
if(fanon.currentSwitch == “on”){
log.debug “humidifier on command sent”
} else log.debug "using else"


Not sure why folks coding in Java or Groovy tend to not indent code around brackets and don’t put brackets on separate lines so you can see the logic

It’s missing brackets after the else

if(outsidetemp.currentTemperature >= 40)
	/* && humiditysensor.currentHumidity < humidity40p) */
	log.debug "fan on command sent"
	if(fanon.currentSwitch == “on”)
		log.debug “humidifier on command sent”
	log.debug "using else"

Not related to your issue, which I believe @arnb solved, but something to think about. I see the if outside temp >= 40. Might be better to base your on/off on a combination of outside temperature and current humidity like the EcoBee does. For example if its 30* outside but the humidity is only 22% inside it would be completely fine to turn on the humidifier. Make your app, and your overall comfort, a little better.

Thanks been trying to look at other people’s code to figure this out and messed that. That is much easier to read.

1 Like

The humidity part is commented out right now. It will be able to change the inside humidity level as the temp drops so condensation doesn’t develop on the windows.

1 Like

So quick question about “ ” and ‘ ’. Take this line for example

fanon.currentSwitch == “on” or fanon.currentSwitch == ‘on’

I have seen it both ways looking through peoples code and noticed I have it both ways in mine somehow. But they both seem to work. So what’s the difference? Is there a correct way to write it? And what problems could show up if the wrong quotes are used?

@mebaddog2002 is this working for you now? Would you be able to share your final version? I’m also looking for a solution that compares outside temp and indoor humidity to control condensation forming on windows.

It’s almost there but I had to stop working on the final version at the moment. Yes it does look at the outside temp and then adjusts the inside humidity so condensation does not form on the windows. Should have it ready for the beginning of winter this year.

Just so you know this is for a whole house humidifier connected into the hvac.

Did you ever this polished up? I would love to take a look at the final code. I just got a new house that is having this exact problem. I am surprised the “set and forget” mentality of thermostat companies.

No. Going to set down sometime after thanksgiving to finish it up. If you go on my github I have 2 versions on there. I’m using the first one in my house while I’m finishing up the second one. Even though I have a steam humidifier I have it set as a evaporation type and it works good. Just takes longer after the temp outside raises to bring the humidity back up in the house. The default humidity setting for the temp range is what I found as the recommended setting.

In the new version I’m building a buffer in the humidity level so the steam will come on when the heat is on and allow the humidity to raise a little above the set point. And allow it to lower a little below the set point before it turns the hvac fan on so it can raise the humidity in the house. It will also be able to tell if it turned the hvac fan on so it doesn’t turn it off if another program turned it on. Hopefully. Not very good at groovy so there is probably a way easier way to write the code.

Sorry just seen they weren’t updating to my GitHub. It is there now. Working the next few weeks on the final version hopefully.