Cannot pull preference for a IF statement but comes through on debug

I was making a modification to the stock SmartSense Temp/Humidity Sensor to make Humidity the primary display tile. Once that was done I decided I wanted to not have to have two different device types, I rather have one that is user selectable between temp and humidity. I have rooms with Ecobee thermostats and I want to add humidity so some of them will have humidity primary on the display and others would have temp. So I went though and made the changes as I could but my compare statement isn’t selecting between the two. Here is my preference section:

preferences { section("Prefs") { input "primarySensor", "enum", options: ["temperature":"Temperature Value", "humidity":"Humidity Value"], defaultValue: "temperature", title: "Choose the value you want to appear first both on the things list and the primary display tile, either temperature or humidity.", displayDuringSetup: true } }

During install if the user doesn’t select anything then “temperature” because the default. Then I added a debug to see the preference:

log.debug "Current Preferences: primarySensor - ${primarySensor}"

In debug I see “Current Preferences: primarySensor - temperature” which is correct. Then later I try to use this in a compare:

tiles(scale: 2) { if ("${primarySensor}"=="temperature") { (stuff for temperature sensor primary) } else { (stuff for humidity sensor primary) } }

The problem is the condition always is false. I know from the debug the value is “temperature” and thats what I’m using for my compare but it never resolves. If I change the IF statement to 1==1 then it is true and the temp displays correctly so the logic is correct but the compare does not work. What exactly am I doing wrong? I’ve also tried just (primarySensor==“temperature”) and that didn’t help either.

-Allan

You are trying to make dynamic tiles?

I spent a lot of time trying to do this and many variables are not set until after the tile section is loaded. Before the if statement add the log.debug and see if primarySensor is initialized. I am pretty sure it is not.

Exactly what I’m trying to do. I will add in the debug and see what happens. If it doesn’t work maybe there’s a way to refresh it after the initial load and switch the tiles? I would really hate to have to have two devices, one for temperature and one for humidity, if 95% of the device type is the same. I have a bad feeling you are correct though.

I modified the stock device type and added in a humidity offset just like the temperature offset (not sure why that wasn’t in there from SmartThings already) along with being able to change the icon. If I can change the primary sensor value I would think it would be a much or useful device type.

you are correct, on the initial load its null (first entry on bottom):

fa936f70-fe35-42fc-8aae-c9c296a68b18
12:16:05 PM:
debug
Current Preferences: primarySensor - temperature, tempOffset - null, humidityOffset - -4

fa936f70-fe35-42fc-8aae-c9c296a68b18
12:16:05 PM:
debug
Current Preferences: primarySensor - null, tempOffset - null, humidityOffset - null

fa936f70-fe35-42fc-8aae-c9c296a68b18
12:16:05 PM:
debug
Current Preferences: primarySensor - null, tempOffset - null, humidityOffset - null

Hrrm…

You can’t switch out the tile type.

In Nest-Manager we added a def tileSelect() method that you can edit with a value to change to the one you want. There is no way yet to do it programatically though. It is one of the reasons we started using htmlTiles to give us more flexibility in displaying data.

1 Like

Thats unfortunate. Guess I’ll have to have two device types, one that makes Temperature primary and one for Humidity and select the one I want. Would be nice if it could just be a preference that you select and be done with it.

Here was the code which doesn’t really matter at this point.

https://github.com/vseven/SmartThings_VSeven/blob/master/devicetypes/vseven/modified-smartsense-temp-humidity-sensor.src/modified-smartsense-temp-humidity-sensor.groovy

Sucks its a limitation. Hopefully HTML tiles will be taking over and then you will have tons of flexibility in display.

We talked about replacing the multi-tile with a HTMLtile for nest-manager, still may do it as a proof of concept one day. There is no way to update the tile (refresh) once you load the DH in ST.

1 Like

I might be able to do a “hack” and send the wrong values to the tile based on user preferences, i.e. send the humidity to the temperature tile and vice versa based on preferences but it would definitely be a hack. I’ll just make two device types for now, a enhanced version of the stock SmartThings one that has the extra ability to offset the humidity and add a icon and then a second one that lets humidity be primary. Thanks for the replies.

-Allan