Use Wirelesstag sensors with OpenHAB?

@pahansen, Can you post the logs now? Is the rule able to parse any of the json string? or is it failing from the very beginning?

I’m struggling to figure this one out. The error isn’t always the same.

09:12:06.704 [INFO ] [clipse.smarthome.model.script.Sensor] - Wireless Tag Payload arrived...
09:12:06.705 [ERROR] [.script.engine.ScriptExecutionThread] - Error during the execution of rule 'UnpackWirelesstagPayload': An error occured during the script execution: The name 'sensor_Payload' cannot be resolved to an item or type.
09:12:06.811 [INFO ] [marthome.event.ItemStateChangedEvent] - sensor_Payload changed from NULL to
09:12:14.729 [ERROR] [.script.engine.ScriptExecutionThread] - Error during the execution of rule 'UnpackWirelesstagPayload': Script interpreter couldn't be obtain

I still think my troubles might be related to this.

Note that I am doing all of this in OH2b3, but have also tried a recent snapshot which has similar issues.

I stripped my rule right back to:

rule UnpackWirelesstagPayload
when
Item sensor_Payload received update
then
logInfo(“Sensor”, “Wireless Tag Payload arrived…”)

My script is:

#!/bin/bash
curl --silent -X POST -H "host: mytaglist.com" -H "Content-Type: application/json; charset=utf-8" -H "Authorization: bearer 9cb01305-xxxx-xxxx-xxxx-614f04749838" -H "d: """ -H "Cache-Control: no-cache" -H "Postman-Token: 7f208f85-2c1f-96ce-2ca7-033fab5b83fe" -d '' "http://mytaglist.com/ethClient.asmx/GetTagList"

And my item is:

String sensor_Payload { exec=“<[c:/Openhab/OpenHAB2/conf/scripts/getTagList.sh:10000:REGEX((.*?))]” }

From what I’m reading in that thread, the error is thrown yet the rule appears to be working correctly. Maybe you can try to ignore the error for the time being, add more lines back in to your rule and continue to watch the log to see if the json is parsed and your items get updated correctly.

Using the latest 408 snapshot I have the JSON error again, while using the same rule as above.

11:16:25.277 [INFO ] [clipse.smarthome.model.script.Sensor] - Wireless Tag Payload arrived...
11:16:25.304 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'UnpackWirelesstagPayload': json string can not be null or empty
11:16:34.234 [INFO ] [clipse.smarthome.model.script.Sensor] - Wireless Tag Payload arrived...
11:16:34.244 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'UnpackWirelesstagPayload': json string can not be null or empty
11:16:44.291 [INFO ] [clipse.smarthome.model.script.Sensor] - Wireless Tag Payload arrived...
11:16:44.300 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'UnpackWirelesstagPayload': json string can not be null or empty
11:16:54.346 [INFO ] [clipse.smarthome.model.script.Sensor] - Wireless Tag Payload arrived...
11:16:54.350 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'UnpackWirelesstagPayload': json string can not be null or empty
11:17:04.402 [INFO ] [clipse.smarthome.model.script.Sensor] - Wireless Tag Payload arrived...
11:17:04.406 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'UnpackWirelesstagPayload': json string can not be null or empty

I wonder if it’s not parsing my curl script nicely, even though using cygwin it outputs the data just fine.

What exactly does your rule look like now? Probably need to start from the beginning, check to see if your sensor_Payload item holds a value after the cURL script is executed. Based on that error, it sure looks like it’s coming back NULL. You should just be able to:

rule UnpackWirelesstagPayload
when
Item sensor_Payload received update
then 
logInfo("Sensor", "Wireless Tag Payload arrived...")
logInfo("Sensor", sensor_Payload.state.toString)

Does that log the entire returned json string? It does for me.

Hmm, Good point there. I get nothing in the log. Just an entry with no content.

I might try a few different curl scripts to see if I can figure it out as my script works great when calling from other means (cygwin).

I thought I would append some info to this thread.

I have been able to get the curl script working in OH2 by making a couple of changes.

curl --silent -H "Host: mytaglist.com" -X POST -H "Content-Type: application/json; charset=utf-8" -H "Authorization: bearer xxxx-xxxx-xxxx-xxxx-xxxx" -H "d: "" " -H "Cache-Control: no-cache" -H "Postman-Token: 7f208f85-2c1f-96ce-2ca7-033fab5b83fe" -d {} "Wireless Tag App Login"

You will see that I have had to escape all the " symbols. And I have had to use curly brackets instead of single quotes in the last -d post sequence.

I’ve been using it inside an executeCommanLine(“curl script”, 5000) line in my rule but don’t see why this shouldn’t work fine as a script as per the original guide.

Another interesting note…

I tried to use my settings on a Pi (Raspbian) install and it appears to run, however the log is full of:

[INFO ] [clipse.smarthome.model.script.Sensor] - Wireless Tag Payload (name: null, slaveId: null, temp: null, cap: null, batt: null)

I get the same if I run it from OSX, however in windows (running at the same time as the others) it works fine:

[INFO ] [clipse.smarthome.model.script.Sensor] - Wireless Tag Payload (name: Carport Door, slaveId: 6, temp: 10.872475624084473, cap: 73.18326568603516, batt: 0.93)

All I did was copy my conf folder from the windows test machine to the pi, so not quite sure what’s going on there. Will have to investigate further

This weekend I got a new RPi3, originally with the intention of installing OH2 on it and migrating everything over. Unfortunately, OH2 isn’t compatible with my Insteon Hub so I decided to just install OH 1.8 and move everything over from my RPi2.

At any rate, I was getting the same errors as you @pahansen: “json string can not be null or empty”. It turns out that the issue was in fact the set permissions.sh script that @mhill mentioned above, in post #39. Each time OH restarts, permissions are reset such that the scripts are no longer executable. My solution was to create a rule that makes the scripts executable again, triggered by the “System Started” event.

rule Startup
    when 
        System started
    then
        //reset script file permissions to make scripts executable...
        var results = executeCommandLine("/bin/chmod u+x -R /etc/openhab/configurations/scripts/", 5000)
        logInfo("StartupRules", "Resetting file permissions completed" + results) 
    end

I don’t think you need to make the changes to the curl command that you made (escaping special characters, etc.). The only change I made, which wasn’t even really necessary, was to remove the part about the Postman-Token. I was never sure why that was in there so I wanted to test if it was required. Confirmed, it works just fine without it. So my curl command looks like this now:

curl --silent -X POST -H "host: mytaglist.com" -H "Content-Type: application/json; charset=utf-8" -H "Authorization: bearer xxx-xxx-xxx-xxx-xxx" -H "d: """ -H "Cache-Control: no-cache" -d '' "http://mytaglist.com/ethClient.asmx/GetTagList"

After those minor changes, I’m reading and updating my Wireless Tag items without issue. Hope that helps!

-Pete

1 Like

I still get a bunch of errors using your method @peteraquino But I did hack it together over breakfast this morning so might warrant some more attention.

The closest I have been able to get is the info logs below.

[INFO ] [clipse.smarthome.model.script.Sensor] - Wireless Sensor Payload arrived...
[INFO ] [clipse.smarthome.model.script.Sensor] - Wireless Tag Payload (name: null, slaveId: null, temp: null, cap: null, batt: null)

Running my config on a windows machine gives me full data readings, but using it on a Mac or my Pi3 gives me the above.

I’ve shelved the task of getting this to work for a week or two while I focus on some other things. Perhaps the time away will help me figure it out.

Hi,

I’ve decided to move across to OpenHAB2 and also from Linux to Windows whilst at the same time adopting Peter’s more elegant solution.

I’ve had some issues with getting CURL to present the data in the same format and ended up with the following command line

curl --silent -g -X POST -H “host: mytaglist.com” -H “Content-Type: application/json; charset=utf-8” -H “Content-Length: 0” -H “Authorization: bearer XXXXXXX” -H “d: “”” -H “Cache-Control:no-cache” -H “Postman-Token:XXXXXX” -d “” “http://mytaglist.com/ethClient.asmx/GetTagList

My item has

String wtPayload { exec="<[getTagList.cmd:100000:REGEX((.*?))]" }

However it is giving an error

2016-10-06 10:36:05.498 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘UnpackWirelesstagPayload’: json string can not be null or empty

I suspect that it isn’t finding the cmd file as when I change the exec line to a file that doesn’t exist e.g. getTagListxx.cmd, I get the same error…

Does anyone know which directory it is expecting the cmd script to sit in? I’ve got it in scripts and also included that in the path

Cheers

@a8ree,
Did you ensure that the script permissions are set correctly so that the file is executable? You should be able to set permissions on the file manually and see if that fixes it. In my last post, I talk about how this was affecting my recent install.

@peteraquino,
I’m running in Windows and just to check permissions, I have run openhab with admin rights and also ensured that ‘everyone’ has full control - no difference however

I was able to strip the curl down quite a lot and still have it work. This works for me in Windows, Mac, and Linux. But beware that to have it work in Raspbian I had to re-type it all rather than copy paste. I think there was something odd going on with my unicode characters for the quote marks etc.

Script

curl -s -X POST -H "Content-Type: application/json; charset=utf-8" -H "Authorization: bearer xxxx-xxxx-xxxx-xxxx-xxxx" -d "" "http://mytaglist.com/ethClient.asmx/GetTagList"

Items

String        wirelesstagPayload      { exec="<[/etc/openhab2/scripts/getTagList.sh:900000:REGEX((.*?))]" }

Note the location of the script in the exec binding item…

Not quite related, but has anyone been able to get http calling working for PIR motion alerts? I’ve tried a few different methods to have the call change a switch state via the rest api but nothing I do has any effect.

I have, although I’ve only tried it with 1.8, and I believe things have changed in 2.0 that may stop it working.

Here’s a copy of one of my working entries from the wireless tag interface: http://192.168.0.113:8080/CMD?WT_PIR_Kitchen=ON

Note you need to change it to match the ip your OH runs at, change the WT_PIR_Kitchen to match one of your items, and make sure private IP is checked

I’ve moved a bit further forward, I’ve now got the payload coming into the script successfully. As suggested above, I’ve added this to the loginfo

Now, I’m getting
016-10-07 19:14:28.413 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘UnpackWirelesstagPayload’: cannot invoke method public int java.lang.String.length() on null

Here is my output
{“d”:[{"__type":“MyTagList.Tag”,“notificationJS”:"",“name”:“Back Door”,“uuid”:“395eac08-3a39-4df0-9b32-8007a8d03712”,“comment”:"",“slaveId”:3,“tagType”:13,“lastComm”:131203375093281886,“alive”:true,“signaldBm”:-79,“batteryVolt”:2.8438254936935978,“beeping”:false,“lit”:false,“migrationPending”:false,“beepDurationDefault”:5,“eventState”:4,“tempEventState”:0,“OutOfRange”:false,“lux”:0,“temperature”:18.508745193481445,“tempCalOffset”:0,“capCalOffset”:0,“image_md5”:null,“cap”:63.20623779296875,“capRaw”:0,“az2”:0,“capEventState”:1,“lightEventState”:0,“shorted”:false,“thermostat”:null,“playback”:null,“postBackInterval”:900,“rev”:14,“version1”:2,“freqOffset”:-15381,“freqCalApplied”:18424,“reviveEvery”:24,“oorGrace”:2,“LBTh”:2.5,“enLBN”:true,“txpwr”:255,“rssiMode”:false,“ds18”:false,“batteryRemaining”:0.88},{"__type":“MyTagList.Tag”,“notificationJS”:"",“name”:“Front Door”,“uuid”:“a73fc3da-89b0-4537-8543-1e4c4eb417b4”,“comment”:"",“slaveId”:2,“tagType”:13,“lastComm”:131090996181611151,“alive”:false,“signaldBm”:-120,“batteryVolt”:2.7126537052616704,“beeping”:false,“lit”:false,“migrationPending”:false,“beepDurationDefault”:5,“eventState”:4,“tempEventState”:0,“OutOfRange”:true,“lux”:0,“temperature”:18.304967880249023,“tempCalOffset”:0,“capCalOffset”:0,“image_md5”:null,“cap”:59.25421142578125,“capRaw”:0,“az2”:0,“capEventState”:2,“lightEventState”:0,“shorted”:false,“thermostat”:null,“playback”:null,“postBackInterval”:900,“rev”:14,“version1”:2,“freqOffset”:-141,“freqCalApplied”:21337,“reviveEvery”:24,“oorGrace”:2,“LBTh”:2.5,“enLBN”:true,“txpwr”:255,“rssiMode”:false,“ds18”:false,“batteryRemaining”:0.24},{"__type":“MyTagList.Tag”,“notificationJS”:"",“name”:“My Keys”,“uuid”:“a84ea7f9-06fe-4fc7-8f6b-5bb03e37f3e3”,“comment”:"",“slaveId”:6,“tagType”:13,“lastComm”:131106038629255376,“alive”:false,“signaldBm”:-120,“batteryVolt”:2.7408466488344163,“beeping”:false,“lit”:false,“migrationPending”:false,“beepDurationDefault”:10,“eventState”:3,“tempEventState”:0,“OutOfRange”:true,“lux”:0,“temperature”:18.1011905670166,“tempCalOffset”:0,“capCalOffset”:0,“image_md5”:null,“cap”:56.84332275390625,“capRaw”:0,“az2”:0,“capEventState”:0,“lightEventState”:0,“shorted”:false,“thermostat”:null,“playback”:null,“postBackInterval”:900,“rev”:14,“version1”:2,“freqOffset”:-13879,“freqCalApplied”:16122,“reviveEvery”:24,“oorGrace”:2,“LBTh”:2.5,“enLBN”:true,“txpwr”:111,“rssiMode”:false,“ds18”:false,“batteryRemaining”:0.38},{"__type":“MyTagList.Tag”,“notificationJS”:"",“name”:“Tag 5”,“uuid”:“cb0f78db-e9f0-4cbe-9c84-c0d55774f061”,“comment”:"",“slaveId”:5,“tagType”:13,“lastComm”:130963036652188222,“alive”:false,“signaldBm”:-120,“batteryVolt”:2.47269217344349,“beeping”:false,“lit”:false,“migrationPending”:false,“beepDurationDefault”:15,“eventState”:1,“tempEventState”:1,“OutOfRange”:true,“lux”:0,“temperature”:15.8918209075928,“tempCalOffset”:0,“capCalOffset”:0,“image_md5”:null,“cap”:57.34686279296875,“capRaw”:0,“az2”:0,“capEventState”:0,“lightEventState”:0,“shorted”:false,“thermostat”:null,“playback”:null,“postBackInterval”:900,“rev”:14,“version1”:2,“freqOffset”:-239,“freqCalApplied”:4041,“reviveEvery”:24,“oorGrace”:2,“LBTh”:2.5,“enLBN”:true,“txpwr”:255,“rssiMode”:false,“ds18”:false,“batteryRemaining”:0.12},{"__type":“MyTagList.Tag”,“notificationJS”:"",“name”:“Front Room PIR”,“uuid”:“40eede82-bbbe-4e2f-961a-42ef27db8b46”,“comment”:"",“slaveId”:8,“tagType”:72,“lastComm”:131203371457656474,“alive”:true,“signaldBm”:-77,“batteryVolt”:2.9228289150440681,“beeping”:false,“lit”:false,“migrationPending”:false,“beepDurationDefault”:15,“eventState”:6,“tempEventState”:0,“OutOfRange”:false,“lux”:0,“temperature”:17.479135513305664,“tempCalOffset”:0,“capCalOffset”:0,“image_md5”:null,“cap”:64.57952880859375,“capRaw”:0,“az2”:0,“capEventState”:0,“lightEventState”:0,“shorted”:false,“thermostat”:null,“playback”:null,“postBackInterval”:900,“rev”:143,“version1”:2,“freqOffset”:-16911,“freqCalApplied”:22141,“reviveEvery”:4,“oorGrace”:2,“LBTh”:2.5,“enLBN”:true,“txpwr”:66,“rssiMode”:false,“ds18”:false,“batteryRemaining”:0.92},{"__type":“MyTagList.Tag”,“notificationJS”:"",“name”:“Hall PIR”,“uuid”:“c86b7a79-2b4a-4ba9-8811-22748f618c93”,“comment”:"",“slaveId”:7,“tagType”:72,“lastComm”:131203375193594197,“alive”:true,“signaldBm”:-74,“batteryVolt”:2.9885736379998096,“beeping”:false,“lit”:false,“migrationPending”:false,“beepDurationDefault”:15,“eventState”:6,“tempEventState”:0,“OutOfRange”:false,“lux”:0,“temperature”:18.176267623901367,“tempCalOffset”:0,“capCalOffset”:0,“image_md5”:null,“cap”:64.281982421875,“capRaw”:0,“az2”:0,“capEventState”:0,“lightEventState”:0,“shorted”:false,“thermostat”:null,“playback”:null,“postBackInterval”:900,“rev”:143,“version1”:2,“freqOffset”:479,“freqCalApplied”:3190,“reviveEvery”:4,“oorGrace”:2,“LBTh”:2.5,“enLBN”:true,“txpwr”:16,“rssiMode”:false,“ds18”:false,“batteryRemaining”:0.94},{"__type":“MyTagList.Tag”,“notificationJS”:"",“name”:“Back Room PIR”,“uuid”:“dd2eb71c-d614-4697-a301-0b15a31ae0c1”,“comment”:"",“slaveId”:9,“tagType”:72,“lastComm”:131203377552187733,“alive”:true,“signaldBm”:-75,“batteryVolt”:2.9712186470843114,“beeping”:false,“lit”:false,“migrationPending”:false,“beepDurationDefault”:15,“eventState”:6,“tempEventState”:0,“OutOfRange”:false,“lux”:0,“temperature”:19.463279724121094,“tempCalOffset”:0,“capCalOffset”:0,“image_md5”:null,“cap”:65.258544921875,“capRaw”:0,“az2”:0,“capEventState”:0,“lightEventState”:0,“shorted”:false,“thermostat”:null,“playback”:null,“postBackInterval”:900,“rev”:143,“version1”:2,“freqOffset”:577,“freqCalApplied”:-1250,“reviveEvery”:4,“oorGrace”:2,“LBTh”:2.5,“enLBN”:true,“txpwr”:57,“rssiMode”:false,“ds18”:false,“batteryRemaining”:0.93},{"__type":“MyTagList.Tag”,“notificationJS”:null,“name”:“Kitchen Thermostat”,“uuid”:“9c352334-3811-4bab-8295-6047a15407d8”,“comment”:"@Home",“slaveId”:-1,“tagType”:62,“lastComm”:131203373037000000,“alive”:true,“signaldBm”:-60,“batteryVolt”:3,“beeping”:false,“lit”:false,“migrationPending”:false,“beepDurationDefault”:15,“eventState”:5,“tempEventState”:1,“OutOfRange”:false,“lux”:0,“temperature”:20,“tempCalOffset”:0,“capCalOffset”:0,“image_md5”:null,“cap”:55,“capRaw”:0,“az2”:0,“capEventState”:0,“lightEventState”:0,“shorted”:false,“thermostat”:{“nest_id”:“YucPu7ZCFhaC9-ezLcJTouwLnnHJaWv9”,“honeywell_device_id”:0,“th_low”:18,“th_high”:24,“threshold_q”:{"__type":“MyTagList.Tag+ThresholdQuantization”,“min”:9,“max”:32,“step”:0.1,“sample1”:18,“sample2”:24},“targetUuid”:“9c352334-3811-4bab-8295-6047a15407d8”,“turnOff”:false,“fanOn”:false,“disableLocal”:false,“issuedState”:0},“playback”:null,“postBackInterval”:600,“rev”:0,“version1”:3,“freqOffset”:-18153,“freqCalApplied”:0,“reviveEvery”:4,“oorGrace”:2,“LBTh”:2.5,“enLBN”:true,“txpwr”:0,“rssiMode”:false,“ds18”:false,“batteryRemaining”:0.94}]}

Any ideas?

I’ve got URL calling going on with my old Openhab installation

http://username:password@externalIPADDRESS:8085/CMD?EventState06=DetectedMovement

Mine has authentication enabled. Remember that the port needs to be opened externally if not getting the tag manager to call it…

What does your rule file look like? Are you 100% positive all the items and vars are named EXACTLY the same? Even with the same capitalization? Those tend to be my biggest errors. Regardless, the rule is finding a null entry and failing.

[quote=“a8ree, post:58, topic:6790”]
I’ve got URL calling going on with my old Openhab installation

http://username:password@externalIPADDRESS:8085/CMD?EventState06=DetectedMovement
[/quote] Do you use mapping to have the item state DetectedMovement map to an On state with a switch? Whether I use On, ON, on, Open, OPEN or any variation of after the CMD?itemname= I get no change to the item state. I’m calling the URL from a local tag manager and without any authentication. shrug

I use a string rather than a switch for my items so I can have multiple states