- Platform information:
- Hardware: Pi4
- OS: Raspbian buster
- Java Runtime Environment:OpenJDK Zulu 8.25
- openHAB version: 2.5.1
- Issue of the topic:JSONPATH transformation behaving as if it not installed when used inside a rule
- Please post configurations (if applicable):
- Items configuration related to the issue
STUCK A TRIPLE BACKTICK here to force raw format from now on !!!
Clicking on </> has some weird effects. If anyone knows how to get rid of invisible formatting in the editor I would love to know.
Switch sonoff_one "Lounge Light" <switch> (gLounge) [ "Lighting" ]
String sonoff_one_startup "Startup"
String sonoff_one_pulse "Pulse"
Number sonoff_one_pulseWidth
String sonoff_one_ssid "SSID"
String sonoff_one_otaUnlock "OTA Lock"
* Sitemap configuration related to the issue
sitemap sonoff label="sonoff_one" {
Frame label="Lounge" {
Switch item=sonoff_one icon="light"
Switch item=sonoff_one_startup label="Power on State" icon="none" mappings=[on="ON",off="OFF",stay="KEEP"]
Switch item=sonoff_one_pulse icon="none" label="Pulse/ Run timer enable" mappings=[on="ON",off="OFF"]
Setpoint item=sonoff_one_pulseWidth icon="time" label="Pulse time max 1 hr [JS(msToTime.js):%s]" minValue=1000 maxValue=36000000 step=1000
Text item=sonoff_one_ssid icon="none" label="SSID [%s]"
Text item=sonoff_one_otaUnlock icon="none" label="OTA Unlock [%s]"
}
}
* Rules code related to the issue
rule "Sonoff_one Polling"
when
Time cron "0/3 * * * * ?" // Run every 3 seconds
then
try {
var CommandURL = 'http://' + Ip +':8081/zeroconf/info'
var String CommandData = '{"deviceid": "'+ Deviceid +'", "data": {}}'
var String UpdateResult
var Number Attempts = 0
var CommandExec = 'curl@@-sSH@@"Accept: */*"@@-H@@"Content-Type: text/plain"@@-X@@POST@@-d@@' + CommandData + '@@' + CommandURL
var String JSONdata
var String update_sswitch
var String update_startup
var String update_pulse
var String update_pulseWidth
var String update_ssid
var String update_otaUnlock
do {
Attempts += 1
UpdateResult = "[" + executeCommandLine(CommandExec, 1500) + "]"
logInfo("Sonoff Poll UpdateResult", UpdateResult)
if (UpdateResult.contains('"error":0')) {
JSONdata = transform("JSONPATH", "$.data", UpdateResult)
logInfo("Sonoff Poll JSONdata", JSONdata)
if (JSONdata != Last_update) {
update_sswitch = transform("JSONPATH", "$.switch", JSONdata)
update_startup = transform("JSONPATH", "$.startup", JSONdata)
update_pulse = transform("JSONPATH", "$.pulse", JSONdata)
update_pulseWidth = transform("JSONPATH", "$.pulseWidth", JSONdata)
update_ssid = transform("JSONPATH", "$.ssid", JSONdata)
update_otaUnlock = transform("JSONPATH", "$.otaUnlock", JSONdata)
if (update_sswitch != sonoff.state.toString.toLowerCase) {
logInfo("sonoff switch", " Syncing state to " + update_sswitch)
sonoff.postUpdate(update_sswitch.toString.toUpperCase)
}
if (update_startup != startup.state.toString) {
logInfo("sonoff switch", " Syncing startup to " + update_startup)
startup.postUpdate(update_startup.toString)
}
if (update_pulse != pulse.state.toString) {
logInfo("sonoff switch", " Syncing pulse to " + update_pulse )
pulse.postUpdate(update_pulse.toString)
}
if (update_pulseWidth != pulseWidth.state.toString) {
logInfo("sonoff switch", " Syncing pulseWidth to " + update_pulseWidth + "ms")
pulseWidth.postUpdate(update_pulseWidth.toString)
}
if (update_ssid != ssid.state.toString) {
logInfo("sonoff switch", " Syncing ssid")
ssid.postUpdate(update_ssid.toString)
}
if (update_otaUnlock != otaUnlock.state.toString) {
logInfo("sonoff switch", " Syncing otaUnlock")
otaUnlock.postUpdate(update_otaUnlock.toString)
}
Last_update = JSONdata
}
}
} while (!UpdateResult.contains('"error":0') && Attempts < 2) // Attempt to send 2 times
if (Attempts == 2) {
logError("Sonoff Poll Switch", "2 failures polling sonoff_one ")
}
if (UpdateResult.contains('"error":400')) {
logError("Sonoff ID:"+ Deviceid +" Error", "The operation failed and the request was formatted incorrectly. The request body is not a valid JSON format")
} else if (UpdateResult.contains('"error":401')) {
logError("Sonoff Error", "The operation failed and the request was unauthorized. Device information encryption is enabled on the device, but the request is not encrypted")
} else if (UpdateResult.contains('"error":404')) {
logError("Sonoff Error", "The operation failed and the device does not exist. The device does not support the requested deviceid")
} else if (UpdateResult.contains('"error":422')) {
logError("Sonoff Error", "The operation failed and the request parameters are invalid. For example, the device does not support setting specific device information")
}
}
catch(Exception e){
logError("Polling", "Error occured in Sonoff Poling Rule! " + e.toString)
}
Here is a an extract of the log.
2020-02-06 20:30:34.593 [INFO ] [internal.service.FeaturesServiceImpl] - Installing bundles:
2020-02-06 20:30:34.595 [INFO ] [internal.service.FeaturesServiceImpl] - mvn:org.openhab.addons.bundles/org.openhab.transform.jsonpath/[2.5.0,2.6)
2020-02-06 20:30:35.232 [INFO ] [internal.service.FeaturesServiceImpl] - mvn:org.openhab.addons.bundles/org.openhab.transform.map/[2.5.0,2.6)
2020-02-06 20:30:35.334 [INFO ] [internal.service.FeaturesServiceImpl] - Starting bundles:
2020-02-06 20:30:35.337 [INFO ] [internal.service.FeaturesServiceImpl] - org.openhab.transform.map/2.5.1
2020-02-06 20:30:35.365 [INFO ] [internal.service.FeaturesServiceImpl] - org.openhab.transform.jsonpath/2.5.1
2020-02-06 20:30:35.397 [INFO ] [internal.service.FeaturesServiceImpl] - org.openhab.core.voice/2.5.0
2020-02-06 20:30:35.465 [INFO ] [internal.service.FeaturesServiceImpl] - org.openhab.core.transform/2.5.0
2020-02-06 20:30:35.472 [INFO ] [internal.service.FeaturesServiceImpl] - org.threeten.extra/1.4.0
2020-02-06 20:30:35.478 [INFO ] [internal.service.FeaturesServiceImpl] - org.openhab.core.ui/2.5.0
2020-02-06 20:30:45.427 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'sonoff_one.rules'
2020-02-06 20:30:45.566 [INFO ] [org.quartz.core.QuartzScheduler ] - JobFactory set to: org.eclipse.smarthome.model.rule.runtime.internal.engine.GuiceAwareJobFactory@1aba61a
2020-02-06 20:30:45.572 [INFO ] [org.quartz.core.QuartzScheduler ] - Scheduler openHAB-job-scheduler_$_NON_CLUSTERED paused.
2020-02-06 20:30:48.180 [INFO ] [vice.internal.HttpServiceFactoryImpl] - Binding bundle: [org.openhab.core.boot_2.5.0 [137]] to http service
2020-02-06 20:30:48.189 [INFO ] [rg.ops4j.pax.web.utils.ClassPathUtil] - Ignoring bundle scan for /META-INF/services javax.servlet.ServletContainerInitializer.
2020-02-06 20:30:48.191 [INFO ] [ce.jetty.internal.HttpServiceContext] - registering context DefaultHttpContext [bundle=org.openhab.core.boot_2.5.0 [137], contextID=default], with context-name:
2020-02-06 20:30:48.193 [INFO ] [ce.jetty.internal.HttpServiceContext] - registering JasperInitializer
2020-02-06 20:30:48.257 [INFO ] [.jetty.server.handler.ContextHandler] - Started HttpServiceContext{httpContext=DefaultHttpContext [bundle=org.openhab.core.boot_2.5.0 [137], contextID=default]}
2020-02-06 20:30:52.788 [INFO ] [org.quartz.core.QuartzScheduler ] - Scheduler openHAB-job-scheduler_$_NON_CLUSTERED started.
2020-02-06 20:30:54.205 [INFO ] [odel.script.Sonoff Poll UpdateResult] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:30:54.205 [INFO ] [odel.script.Sonoff Poll UpdateResult] - [curl: (56) Recv failure: Connection reset by peer]
2020-02-06 20:30:54.205 [INFO ] [odel.script.Sonoff Poll UpdateResult] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:30:54.281 [INFO ] [odel.script.Sonoff Poll UpdateResult] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:30:54.336 [INFO ] [me.model.script.Sonoff Poll JSONdata] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:30:54.336 [INFO ] [me.model.script.Sonoff Poll JSONdata] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:30:54.336 [INFO ] [me.model.script.Sonoff Poll JSONdata] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:30:54.351 [INFO ] [smarthome.model.script.sonoff switch] - Syncing state to [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:30:54.357 [INFO ] [smarthome.model.script.sonoff switch] - Syncing state to [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:30:54.360 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert '[{"SEQ":2,"ERROR":0,"DATA":"{\"SWITCH\":\"OFF\",\"STARTUP\":\"OFF\",\"PULSE\":\"OFF\",\"PULSEWIDTH\":500,\"SSID\":\"PEGLEGPETE\",\"OTAUNLOCK\":FALSE}"}]' to a state type which item 'sonoff_one' accepts: [OnOffType, UnDefType].
2020-02-06 20:30:54.360 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert '[{"SEQ":2,"ERROR":0,"DATA":"{\"SWITCH\":\"OFF\",\"STARTUP\":\"OFF\",\"PULSE\":\"OFF\",\"PULSEWIDTH\":500,\"SSID\":\"PEGLEGPETE\",\"OTAUNLOCK\":FALSE}"}]' to a state type which item 'sonoff_one' accepts: [OnOffType, UnDefType].
2020-02-06 20:30:54.364 [INFO ] [smarthome.model.script.sonoff switch] - Syncing state to [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:30:54.364 [INFO ] [smarthome.model.script.sonoff switch] - Syncing startup to [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:30:54.366 [INFO ] [smarthome.model.script.sonoff switch] - Syncing startup to [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:30:54.367 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert '[{"SEQ":2,"ERROR":0,"DATA":"{\"SWITCH\":\"OFF\",\"STARTUP\":\"OFF\",\"PULSE\":\"OFF\",\"PULSEWIDTH\":500,\"SSID\":\"PEGLEGPETE\",\"OTAUNLOCK\":FALSE}"}]' to a state type which item 'sonoff_one' accepts: [OnOffType, UnDefType].
2020-02-06 20:30:54.370 [INFO ] [smarthome.model.script.sonoff switch] - Syncing startup to [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:30:54.373 [INFO ] [smarthome.model.script.sonoff switch] - Syncing pulse to [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:30:54.376 [INFO ] [smarthome.model.script.sonoff switch] - Syncing pulse to [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:30:54.380 [INFO ] [smarthome.model.script.sonoff switch] - Syncing pulseWidth to [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]ms
2020-02-06 20:30:54.381 [INFO ] [smarthome.model.script.sonoff switch] - Syncing pulseWidth to [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]ms
2020-02-06 20:30:54.398 [INFO ] [smarthome.model.script.sonoff switch] - Syncing pulse to [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:30:54.428 [INFO ] [smarthome.model.script.sonoff switch] - Syncing pulseWidth to [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]ms
2020-02-06 20:30:54.455 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert '[{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]' to a state type which item 'sonoff_one_pulseWidth' accepts: [DecimalType, QuantityType, UnDefType].
2020-02-06 20:30:54.455 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert '[{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]' to a state type which item 'sonoff_one_pulseWidth' accepts: [DecimalType, QuantityType, UnDefType].
2020-02-06 20:30:54.455 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert '[{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]' to a state type which item 'sonoff_one_pulseWidth' accepts: [DecimalType, QuantityType, UnDefType].
2020-02-06 20:30:54.459 [INFO ] [smarthome.model.script.sonoff switch] - Syncing ssid
2020-02-06 20:30:54.459 [INFO ] [smarthome.model.script.sonoff switch] - Syncing ssid
2020-02-06 20:30:54.459 [INFO ] [smarthome.model.script.sonoff switch] - Syncing ssid
2020-02-06 20:30:54.465 [INFO ] [smarthome.model.script.sonoff switch] - Syncing otaUnlock
2020-02-06 20:30:54.465 [INFO ] [smarthome.model.script.sonoff switch] - Syncing otaUnlock
2020-02-06 20:30:54.471 [ERROR] [home.model.script.Sonoff Poll Switch] - 2 failures polling sonoff_one
2020-02-06 20:30:57.121 [INFO ] [odel.script.Sonoff Poll UpdateResult] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:30:57.126 [INFO ] [me.model.script.Sonoff Poll JSONdata] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:31:00.118 [INFO ] [odel.script.Sonoff Poll UpdateResult] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:31:00.121 [INFO ] [me.model.script.Sonoff Poll JSONdata] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:31:03.200 [INFO ] [af.deployer.kar.KarArtifactInstaller] - Found a .kar file to deploy.
2020-02-06 20:31:03.203 [INFO ] [af.deployer.kar.KarArtifactInstaller] - KAR openhab-addons-2.5.1.kar is already installed. Please uninstall it first.
2020-02-06 20:31:03.881 [INFO ] [odel.script.Sonoff Poll UpdateResult] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:31:03.887 [INFO ] [me.model.script.Sonoff Poll JSONdata] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:31:06.119 [INFO ] [odel.script.Sonoff Poll UpdateResult] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:31:06.138 [INFO ] [me.model.script.Sonoff Poll JSONdata] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:31:09.132 [INFO ] [odel.script.Sonoff Poll UpdateResult] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:31:09.137 [INFO ] [me.model.script.Sonoff Poll JSONdata] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:31:12.118 [INFO ] [odel.script.Sonoff Poll UpdateResult] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:31:12.123 [INFO ] [me.model.script.Sonoff Poll JSONdata] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:31:15.377 [INFO ] [odel.script.Sonoff Poll UpdateResult] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
2020-02-06 20:31:15.380 [INFO ] [me.model.script.Sonoff Poll JSONdata] - [{"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"peglegpete\",\"otaUnlock\":false}"}]
The JSONPATH transforms behave as though it has not been installed, or the JSON is malformed.
What am I doing wrong? What have I missed?
All help gratefully received.
R.