Use Wirelesstag sensors with OpenHAB?

I have a couple of sensors that I would like to use for some automation rules

http://wirelesstag.net/

They can be set to call a URL when moved and they also have an API
http://wirelesstag.net/media/mytaglist.com/apidoc.html

Will I be able to make use of these relatively easily if I setup openHAB?

The sort of thing I am looking to do is;

  • Switch on Hue light (if they are in an off state) if the sensor moves (on door) when it is after sunset (and before sunrise) for 2 minutes

Is OpenHAB capable of this?

Thanks

1 Like

Quick answers: inwoukd say yes. If the tag can send a status change to openhab as you said via REST then i dont see any issues

The easiest approach is to use their IFTTT integration, and use my.openhab.org to set up “if wirelesstag moved, then send command to openHAB item”. You might also be able to use their API with a binding written to update item states in openHAB.

Great - thanks for the quick feedback!

I will go ahead and kick off an install. As a Newbie, am I best to go direct to 2.0?

Is there a virtual appliance or a quick start guide?

As a newbie, I recommend 1.8, as 2.0 is still in a state of major changes. Visit the wiki at https://github.com/openhab/openhab/wiki and use the apt-get instructions if you are on Linux.

Thanks again for the advice. I will have a go this evening!

1 Like

I managed to get this working via IFTTT as you described - THANKS!

I am able to query my tags

e.g. curl -X POST http://www.mytaglist.com/ethClient.asmx/StopBeep -d ‘{id:3}’ -H ‘Content-Type: application/json’ -H ‘Authorization: Bearer d6702ad6-ab3a-4497-8eae-22b6229dfe03’

(I know I have left my auth in - I will change later)

How can I get the all data items to read in directly to OpenHAB and refreshed periodically?

I entered your curl command and it returned your sensors! Give me a few minutes and I will append this post with a suggestion…

…here’s the suggestion, polls every two minutes. Untested against openHAB, and only a starting point for you to take forward.

Install the exec binding:

sudo apt-get install openhab-addon-binding-exec

###Create a tiny bash script /home/openhab/grabit.sh (or wherever):

#!/bin/bash
curl --silent -X POST http://www.mytaglist.com/ethClient.asmx/StopBeep -d '{id:3}' -H 'Content-Type: application/json' -H 'Authorization: Bearer d6702ad6-ab3a-4497-8eae-22b6229dfe03'

Make sure to chmod +x /home/openhab/grabit.sh.
###Add the following items:

Group gWT
String WirelesstagPayload { exec="<[/home/openhab/grabit.sh:120000:REGEX((.*?))]" }
Number Temperature "Temperature [%.1f °C]" (gWT)
Number Cap "Cap [%.1f]" (gWT)
Number BatteryRemaining "Battery remaining [%.1f]" (gWT)
Contact EventState "Event state [%s]" (gWT)

###Add the following rules file:

import org.openhab.core.library.types.*

rule UnpackWirelesstagPayload
when
  Item WirelesstagPayload received update
then
  val String payload = WirelesstagPayload.state.toString
  // logInfo("wt", transform("JSONPATH", "$.d.temperature", payload))
  // logInfo("wt", transform("JSONPATH", "$.d.cap", payload))
  // logInfo("wt", transform("JSONPATH", "$.d.batteryRemaining", payload))
  // logInfo("wt", transform("JSONPATH", "$.d.eventState", payload))
  Temperature.postUpdate(new DecimalType(transform("JSONPATH", "$.d.temperature", payload)))
  Cap.postUpdate(new DecimalType(transform("JSONPATH", "$.d.cap", payload)))
  BatteryRemaining.postUpdate(new DecimalType(transform("JSONPATH", "$.d.batteryRemaining", payload)))
  val String eventState = transform("JSONPATH", "$.d.eventState", payload)
  switch eventState {
    case "3" : EventState.postUpdate(OPEN) // guessing
    case "4" : EventState.postUpdate(CLOSED) // guessing
    // API doc says values are Disarmed or Armed or Moved or Opened or Closed or DetectedMovement or TimedOut or Stabilizing, but they are numbers!
    // so you will have to find or figure out the mappings
  }
end

Wow, thanks!

I am getting an error but I guess its something to do with the formatting on the exec command…

016-01-29 18:39:09.032 [DEBUG] [.o.b.exec.internal.ExecBinding] - exit code ‘0’, result ’ % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 180 100 172 100 8 635 29 --:–:-- --:–:-- --:–:-- 641

Object moved

Object moved to here.

' 2016-01-29 18:39:09.034 [DEBUG] [i.s.RegExTransformationService] - about to transform ' % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 180 100 172 100 8 635 29 --:--:-- --:--:-- --:--:-- 641 Object moved

Object moved to here.

' by the function '(.*?)' 2016-01-29 18:39:09.039 [DEBUG] [.o.b.exec.internal.ExecBinding] - transformed response is '% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 180 100 172 100 8 635 29 --:--:-- --:--:-- --:--:-- 641 Object moved

Object moved to here.

' 2016-01-29 18:39:09.040 [DEBUG] [o.o.i.m.i.MyOpenHABServiceImpl] - store(WirelesstagPayload), state = % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 180 100 172 100 8 635 29 --:--:-- --:--:-- --:--:-- 641 Object moved

Object moved to here.

I will play around with the formating and let you know how I get on

If you want to send me your working key privately, I will try the example here to see what results. One thing to add would be --silent to curl command line, but there may be more not working.

Thanks I will give that a go - when you say private key, do you mean for the SSH session?

I just updated my example above and it works here. There were a few typos, and I had completely forgotten about binding string parsing issues, so I made a small bash script and have the exec binding use that instead of calling curl directly.

You could improve it by adding a command line argument to the grabit.sh script, and using that as the numeric ID for the sensor you want. So then just make more items and and another rule for another sensor. You might also find ways to optimise the request so you perform fewer queries.

Give it a try!

Wow - just tried this and it is working! Great stuff - Thanks so much for doing this for me, it is really appreciated. I will have a play with it and optimise for collecting the other sensors

1 Like

Excellent! If you haven’t yet changed your API key you published here, now would be a good time! :wink:

…also, if you get this down to a nice, concise “recipe” for how to integrate Wirelesstag sensors to openHAB, would you be able to write a new wiki page, in the same spirit as the one for integrating Doorbird devices? Would be nice to add it to the cookbook!

1 Like

Yep, I will do that shortly

I have discovered that I can retrieve all tags in one call using

mytaglist.com/ethClient.asmx/GetTagList

curl -X POST -H “host: mytaglist.com” -H “Content-Type: application/json; charset=utf-8” -H “Authorization: bearer d6702ad6-ab3a-4497-8eae-22b6229dfe03” -H “d: “”” -H “Cache-Control: no-cache” -H “Postman-Token: 7f208f85-2c1f-96ce-2ca7-033fab5b83fe” -d ‘’ “http://mytaglist.com/ethClient.asmx/GetTagList

Is there a way of differentiating between the different items as each tag has the same data items

i.e. temperature is listed multiple times as it is present on all tags

You can use JSONPath expressions that let you choose which tag you want from the JSON that contains data for multiple tags.

Brilliant - THANKS again

1 Like

I managed to read multiple items in using

Temperature.postUpdate(new DecimalType(transform(“JSONPATH”, “$.d[”+i+"].temperature", payload)))

in a while loop

and obviously only the last data item is stored as they are overwritten

I have tried
Temperature+i.postUpdate
and other variations without any success

Can you tell me where I am going wrong?

In the items configuration file, is it possible to programatically list the items rather than reference each individually? Like using a while statement?

Does it work to

postUpdate( String::format("Temperature%02d", i), new DecimalType(...))

in the loop where you have sequentially named items like Temperature00, Temperature01, etc.?

When storing it is giving the error

ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘UnpackWirelesstagPayload’: The name ’ … ’ cannot be resolved to an item or type.

I have items defined for
Temperature00 > 04 and the loop is only to 2 at the moment