Groovy variables


I’m trying to adapt this DTH to use with my coffee machine (it was written for a kettle)

Given the following in the DTH :

    result = slurper.parseText(bodyString)
   "Here's the result.status"
    	    log.debug result.status

The IDE log shows :

[4b063261-dc96-4bbb-b0ea-2d69a511358e]( 8:54:18 PM: debug {carafe=true, cups=1, enoughwater=1, ready=true, timerevent=false, working=false}

[4b063261-dc96-4bbb-b0ea-2d69a511358e]( 8:54:18 PM: info Here's the result.status

But what I really want to get at is the value of ‘working’ within that data structure. I tried result.status.working but got :

java.lang.NullPointerException: Cannot get property 'working' on null object

Is there any easy way to get at that value ?


What does your code look like for trying to retrieve that value?

What if you did something like this:

	switch (result.status) {
		case "working":
			def workingValue = result.working
            log.debug "Working value returned ${workingValue} or ${result.working}"

This is all purely a guess because I don’t have my own devices to test with!

1 Like

Got it, thanks for your help :

def resultstatus = result.status
log.debug resultstatus
def resultworking = resultstatus.working

switch (resultworking) {
			case "true":
                log.debug "Working is true"

@johnconstantelo, you have your own devices to test. You have hundreds of them. But not a Smarten Coffee machine, yet… :wink:


Lol not yet, but that doesn’t mean I’m not looking!

The iBrew project has a simulator if you’re really bored :slight_smile:

I got the coffee machine turning on via ST last, so I am quite pleased