Control a switch based on operating state of thermostat

Hello Folks,
I am trying to operate a switch ( humidifier ) based on the heating state of thermostat.

The events thermostatOperatingState is not trapped. I am not sure if that is even a valid event. I guessed looking at some documentation and I am not sure if this is correct.

Can someone help me correct the mistake.

Thanks,
Mohit

/---------------------------------------------------------------------------------/
preferences {
section("Choose a temperature sensor… "){
input “sensor”, “capability.thermostat”, title: “Sensor”
}
section("Select the heater or air conditioner outlet(s)… "){
input “outlets”, “capability.switch”, title: “Outlets”, multiple: true
}
}

def installed()
{
subscribe(sensor, “thermostatOperatingState”, temperatureHandler)
}

def updated()
{
unsubscribe()
subscribe(sensor, “thermostatOperatingState”, temperatureHandler)
}

def temperatureHandler(evt)
{
log.debug “Event Fired!”

log.debug "Value ($evt.Value)"

if (evt.Value=="heating") {
	outlets.on()
}
else {
	outlets.off()
}

}

I’ve been using:
subscribe(thermostats, “thermostatMode”, thermoChange);
But that’s using the custom Nest device by @dianoga

You can reference my events being triggered by thermostate mode change here:

Hello ImBrian

thermostatMode events fire when I change from heat to cool and vice versa… but then I was looking for switching something on when the heat turns on after the temperature has fallen below the set level in the thermostat.

looking at http://graph.api.smartthings.com/ide/doc/capabilities I think thermostatOperatingState is the correct event type to monitor but that does not seem to fire at all. I have tested both with simulator thermostat and a real one.

is this a bug ? I have not written many Apps for smartthings so it could be a silly mistake I am making somewhere.

Thanks,
Mohit

Actually my code was correct for most part. I made some mistake with evt.Value where V is in uppercase. After correcting that the app works fine. I see that at times the event firing can take some time but it works !

Thanks,
Mohit

Ahh, yes - sorry I had mistaken your intent. Sounds like all is well!

Yes
App is working fine.

Thanks for your help.

regards,
Mohit