Showing a value in a tile - please help


(Dce) #1

I am stumped, I have a device type with 2 tiles one showing the state of the level in my cistern (full medium empty)
one showing the actual returned value from the sonar/arduino/thingshield I built
I tried using a value tile, but couldn’t get that to show up at all
In the simulator the 2 tiles show correct, change according the what I want and show the value of the device.CisternLevel
in the app on the phone (after a fair amount of frustration and turning it off and on again) it shows the tiles and the state works but the level shows zero
in neither instance is the units shown
can anyone help, the absolute lack of good examples is killing me here

metadata {
	definition (name: "Cistern2", author: "Dwayne Edwards") {
	}

	tiles {
		standardTile("Cistern", "device.CisternLevelState", width: 2, height: 2, canChangeIcon: true, canChangeBackground: true)
		{
        	state "full", label: 'FULL', backgroundColor: "#00ff00", icon:"st.Appliances.appliances2"
            state "medium", label: 'MEDIUM', backgroundColor: "#ffff00", icon:"st.Appliances.appliances2"
            state "empty", label: 'EMPTY', backgroundColor: "#ff0000", icon:"st.Appliances.appliances2"
        }
        standardTile("level", "device.CisternLevel", width:1, height: 1)
        {
		state "device.CisternLevel" , label:'${currentValue}' , unit:"cm", backgroundColor: "#0000ff"
        }
        main"Cistern"
        details(["Cistern", "level"])
	}
}

// parse events into attributes

def parse(String description) {

	def arduinoMsg = new Integer(zigbee.parse(description)?.text)
	// arduinoMsg = 300
    
    log.debug arduinoMsg
    // log.debug device.CisternLevel
    // log.debug "Parsing '${description}'"
        
    if  (arduinoMsg <= 100) {
    	sendEvent(name:"CisternLevelState", value:"full");
    } else if (arduinoMsg <= 150) {
    	sendEvent(name:"CisternLevelState", value:"medium");
    }
    else  {
    	sendEvent(name:"CisternLevelState", value:"empty");
    }    
    sendEvent(name:"CisternLevel", value:arduinoMsg)
}

(Craig) #2

@dwedward

I’ve gotten this to work by doing the following code:

I put this in my “parse” function. I’m not sure the difference between sendEvent and createEvent.

createEvent(name: "secs", value: msg.substring(msg.length()-3,msg.length()-1))

my tile is defined as:

valueTile("secs", "device.secs") {
	state "default", label:'${currentValue}'
}

I found the “SmartWeather Station Tile” to be the best example as everything is valueTiles and all are set manually. According to the documentation within that application there is (or at least was) a bug that caused ST to not understand updates when the value was zero, which is why I store it as a string rather than a number.


(Dce) #3

Shrek:

Thanks, made the changes but no love on this one
same outcome seems to work fine in simulator, but not on the app, shows a zero
I even made sure there are no zero values coming across
I also have no clue as to the difference between the events probably buried somewhere in the so called documentation


(Craig) #4

Can you repost your code post changes? I’m curious to see what’s different between what I’m doing and what you are doing.


(Dce) #5

sure, to some degree just flailing now, seems to work like I want in the simulator but not the app still
also, I do uninstall from the simulator, but changes don’t always seem to show on the app unless you reboot the phone
pretty frustrating when you are making minor changes in the dark, reminds me of the days of punchcards

metadata {
	definition (name: "Cistern2", author: "Dwayne Edwards") {
	}

	tiles {
		standardTile("Cistern", "device.CisternLevelState", width: 2, height: 2, canChangeIcon: true, canChangeBackground: true)
		{
        	state "full", label: 'FULL', backgroundColor: "#00ff00", icon:"st.Appliances.appliances2"
            state "medium", label: 'MEDIUM', backgroundColor: "#ffff00", icon:"st.Appliances.appliances2"
            state "empty", label: 'EMPTY', backgroundColor: "#ff0000", icon:"st.Appliances.appliances2"
        }
        valueTile("level", "device.CisternLevel") 
        {
        state "default", label:'${currentValue}'
        }
        
        // standardTile("level", "device.CisternLevel", width:1, height: 1)
        // {
		// state "device.CisternLevel" , label:'${currentValue}' , unit:"cm", backgroundColor: "#0000ff"
        // }
        main"Cistern"
        details(["Cistern", "level"])
	}
}

	// TODO: handle 'LevelState' attribute
	// TODO: handle 'LevelValue' attribute

// parse events into attributes

def parse(String description) {

	def arduinoMsg = new Integer(zigbee.parse(description)?.text)

    log.debug arduinoMsg
    // log.debug device.CisternLevel
    // log.debug "Parsing '${description}'"
        
    if  (arduinoMsg <= 100) {
    	sendEvent(name:"CisternLevelState", value:"full");
    } else if (arduinoMsg <= 150) {
    	sendEvent(name:"CisternLevelState", value:"medium");
    }
    else  {
    	sendEvent(name:"CisternLevelState", value:"empty");
    } 
    //createEvent(name:"CisternLevel",value:arduinoMsg)
    sendEvent(name:"CisternLevel", value:arduinoMsg)
}

(Craig) #6

Just to double check did you define Cistern, CisternLevel, CisternLevelState as attributes. I’m not seeing it and may be the reason why it’s not working. If you take a look at the Smart Weather DeviceType example track “Wind”. You’ll see where I got my code from. I honestly think the only thing you are missing is the attribute definition in the metadata.


(Dce) #7

Thanks Craig, perfect, I am probably obviously, new to groovy etc. learned c programming 30 years ago and haven’t coded much since.
The oddity of all this is throwing me, especially type definitions etc. I guess no excuse for not doing it at all.
now I just have to get the app to do a push notification to work


(Craig) #8

Glad i could help. I’m in the same boat trying to learn Groovy it’s all new to me! I’ve found most of my debugging is trying to find the semi-colon I randomly put somewhere


(H.ROSE) #9

Hi. Do u mind if you post your whole ST code and Arduino code separately, because I am facing the same problem, I can’t display the value the ultrasonic sensor gets on arduino to a tile in ST, maybe your response would help me.
Regards