Internal Server Error

So here is a bit of my app that is giving me headaches

mappings {

	path("/setVal/:thevalue") {
		action: [
			GET: "resetAtomic"
	path("/runLog/:myvalue") {
		action: [
			GET: "logData"

def resetAtomic() {
	log.debug "running resetAtomic"

def logData() {
log.debug "Running Log Data"

This URL works fine

This URL gives the Server error.


The codes in the URL have been replaced with xxxx but they were/are identical for each url. I am totally confused why one url works fine while the other does not

What is the :myValue and :the value being used for?

If you remove “atomicState.previousEnergy=0” does it work?

In the example I showed above, nothing.

Yes!!! The above example is a stripped down version of the actual app. The function resetAtomic() show is identical to the actual code. Removing the line atomicState.previousEnergy=0 will eliminate the error suggesting a problem with assigning atomic state values this way. However…

The “complete” function logData() does exactly the same further down in the code.

def logData() {
log.debug "Running Log Data"
	def hourMinus1=now() - 3600000
	def stamp = new Date(hourMinus1).format('dd-MMM-yyyy HH:mm:ss',location.timeZone)
    def power1 = sensor1.currentValue("power1")
    def power2 = sensor1.currentValue("power2")
	def latestPower = sensor1.currentValue("power")
	def current1= sensor1.currentValue("current1")
    def current2= sensor1.currentValue("current2")
	def totAmps = sensor1.currentValue("current")

    def lineLossFactor=adjustFactor.toDouble()

	def latestVoltage = sensor1.currentValue("voltage")
	def curEnergy=sensor1.currentValue("current").toDouble()
 	def cumilativeCurrent = sensor1.currentValue("energy")
   	def hourlyEnergyUsage=Math.round((cumilativeCurrent-atomicState.previousEnergy) * 100) /100
    def hourlyEnergyAdjusted=hourlyEnergyUsage * lineLossFactor
    def hourlyCost=hourlyEnergyUsage * atomicState.currentRate
    def rateUsed = atomicState.currentRate


This atomic assignment does not raise the same error Makes no sense to me

does it work with state instead of atomicState?

EDIT: Also if I remember correctly setting


Will do nothing, previousEnergy will not be stored (it’s got to be a non 0, non null, non empty value for it to save the value to atomicState), unless the behavior has changed in the past few months.

Wondering if previousEnergy is a protect name. Ran into that yesterday trying to set a variable to “switch”. (stab in the dark)

Whats the full error in live logging?

Maybe atomicState.previousEnergy can’t take a number/double. Try sending a string. Maybe it was initialized as a string before. log.debug out its value, same with cumilativeCurrent.

Now that is very possible. I gave up looking for the reason as I found an alternate way of doing this. The only reason for the atomicState.previousEnergy=0 statement is to clear (reset) the old value after the device (and its values such as cumulativeEnergy) itself is “reset” within the Device Handler. I found that this statement was unnecessary and handled it differently.

Thanks everyone for your suggestions and getting me thinking :slight_smile:

1 Like