@guessed
Any ideas what might be causing the following error from my rule (using OpenHAB2)?
2016-12-26 19:45:01.087 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': the given parameters 'JSonPath' and 'source' must not be null
2016-12-26 19:45:01.094 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule Pull Data from Eagle: cannot invoke method public java.lang.String java.lang.String.replaceAll(java.lang.String,java.lang.String) on null
It seems as though all my data is pulling correctly but these two errors consistently pop up every few seconds.
2016-12-26 19:48:30.468 [INFO ] [eclipse.smarthome.model.script.eagle] - PERF Pull-Data-from-Eagle elapsed: 403ms
2016-12-26 19:49:00.359 [INFO ] [eclipse.smarthome.model.script.eagle] - {"meter_status":"Connected",
"demand":"2.4030",
"demand_units":"kW",
"demand_timestamp":"1482781736",
"summation_received":"0.000",
"summation_delivered":"124283.899",
"summation_units":"kWh",
"price":"0.1300",
"price_units":"840",
"price_label":"Set by User",
"message_timestamp":"946684800",
"message_confirmed":"N",
"message_confirm_required":"N",
"message_id":"0",
"message_queue":"active",
"message_read":"Y",
"threshold_upper_demand":"25.885000",
"threshold_lower_demand":"-2.000000",
"fast_poll_frequency":"0x00",
"fast_poll_endtime":"0x00000000"}
My rule is verbatim from the wiki with the addition of the “HouseEnergyDeliveredMidnight” rule appended to the end:
import org.openhab.core.library.types.*
import java.lang.Float
import java.lang.Long
import org.joda.time.DateTime
var DateTime lastTimestamp = null
var float lastDelivered
var float lastReceived
rule "Pull Data from Eagle"
when
Time cron "0 0-59 * * * ?"
then
var t = now
val String EAGLE_MAC = "0xd8d5b90000001340"
val String EAGLE_URL = "http://192.168.1.4/cgi-bin/cgi_manager"
var String postData = String::format("<LocalCommand>
<Name>get_usage_data</Name>
<MacId>%s</MacId>
</LocalCommand>", EAGLE_MAC, EAGLE_MAC)
var result = sendHttpPostRequest(EAGLE_URL, "application/x-www-form-urlencoded", postData)
logDebug("eagle", result)
try {
var long timestamp = Long::parseLong(transform("JSONPATH", "$.demand_timestamp", result))
var DateTime currTimestamp = new DateTime(timestamp * 1000)
var float price = Float::parseFloat(transform("JSONPATH", "$.price", result))
var float currDemand = Float::parseFloat(transform("JSONPATH", "$.demand", result))
var float currDelivered = Float::parseFloat(transform("JSONPATH", "$.summation_delivered", result))
var float currReceived = Float::parseFloat(transform("JSONPATH", "$.summation_received", result))
postUpdate(HousePowerInstant, currDemand * 1000)
if (lastTimestamp != null && !lastTimestamp.equals(currTimestamp)) {
var float used = currDelivered - lastDelivered
var float sent = currReceived - lastReceived
logDebug("eagle", String::format("Energy %s demand=%.3f received=%.3f delivered=%.3f", currTimestamp.toString,
currDemand, used, sent))
postUpdate(HouseEnergySent, sent * 1000)
postUpdate(HouseEnergyDelivered, used * 1000)
postUpdate(HouseEnergyCost, (used - sent) * 1000 * price)
}
postUpdate(HouseEnergyPrice, price)
lastDelivered = currDelivered
lastReceived = currReceived
lastTimestamp = currTimestamp
} catch (NumberFormatException nfe) {
logError("eagle", "Bad Data " + result.replaceAll("\n", " "))
}
var long x = now.getMillis - t.getMillis
logInfo("eagle", "PERF Pull-Data-from-Eagle elapsed: " + String::valueOf(x) + "ms")
end
rule "Set Data from Eagle at midnight"
when
Time is midnight
then
postUpdate(HouseEnergyDeliveredMidnight, lastDelivered)
end