# Ninja Sphere and Ninja Blocks with openHAB

**URL:** <https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330>\
**Category:** Home Automation\
**Created:** [August 13, 2015, 12:07am UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330 "2015-08-13T00:07:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![perrin](https://community.openhab.org/user_avatar/community.openhab.org/perrin/32/179_2.png) [@perrin](https://community.openhab.org/u/perrin)\
**Post date:** [August 13, 2015, 12:07am UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/1 "2015-08-13T00:07:52Z")

</div>

Hi all,

We had a good conversation here about using the ninja sphere or blocks in the openHAB world -  
[https://discuss.ninjablocks.com/t/openhab-vs-open-source-sphere/3680/136](https://discuss.ninjablocks.com/t/openhab-vs-open-source-sphere/3680/136)

I’d suggest that conversation moves to this new forum!

---

<div class="post-metadata">

**Author:** ![marklavercombe](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@marklavercombe](https://community.openhab.org/u/marklavercombe)\
**Post date:** [August 13, 2015, 3:54am UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/2 "2015-08-13T03:54:50Z")

</div>

@perrin

I have been using your script to transport 433 data to MQTT and thus into openhab, and it’s been perfect, thanks!

The only thing: I am also using eventghost with the MQTT client plugin, and that requires that topics be started with a slash as in /ninjaCape/# rather than ninjaCape/#.

I modified my local version last night, which is of course simple, but wonder if it should go in the github version of your script?

Cheers!

---

<div class="post-metadata">

**Author:** ![perrin](https://community.openhab.org/user_avatar/community.openhab.org/perrin/32/179_2.png) [@perrin](https://community.openhab.org/u/perrin)\
**Post date:** [August 13, 2015, 4:05am UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/3 "2015-08-13T04:05:30Z")

</div>

Thanks! Glad it is useful 😄

Interesting nuance between mqtt brokers. I’d have to test with mosquitto and see if it complains about a leading slash. Does that mean your items in openhab are configured like:

```
Switch PIR_1 "Motion Sensor 1" (Persist_Change) {mqtt="<[mosquitto:ninjaCape/input/11:state:ON:010101010101010101010101]"}

```

(Notice there’s no leading slash.. )

---

<div class="post-metadata">

**Author:** ![perrin](https://community.openhab.org/user_avatar/community.openhab.org/perrin/32/179_2.png) [@perrin](https://community.openhab.org/u/perrin)\
**Post date:** [August 13, 2015, 4:09am UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/4 "2015-08-13T04:09:06Z")

</div>

Think I answered my own question -

> **[MQTT Topics, Wildcards, & Best Practices – MQTT Essentials: Part 5](https://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices/)**
>
> Learn about MQTT Topics, naming conventions, MQTT $SYS topics, MQTT Prefix, MQTT Topic Wildcards, and more in this MQTT Essentials article.

Looks like there _shouldn’t_ be a leading slash for ‘best practise’

EDIT: found a few other links with definitions including the leading slash.. so 😖

---

<div class="post-metadata">

**Author:** ![marklavercombe](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@marklavercombe](https://community.openhab.org/u/marklavercombe)\
**Post date:** [August 13, 2015, 4:13am UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/5 "2015-08-13T04:13:22Z")

</div>

😃  
I looked and found conflicting info too…

I did have the config as you have it, but last night changed to

Switch PIR\_1 “Motion Sensor 1” (Persist\_Change) {mqtt=“\<[mosquitto:/ninjaCape/input/11:state:ON:010101010101010101010101]”}

note, with leading slash. This is working with mosquitto as the broker. I needed to do this as I want to have some communication between openhab and eventghost and the EG pluging requires a leading slash.

Maybe you shouldn’t change it if it isn’t clearly best practise, as it’s working fine for me with simple modification! Thanks again 🙂

---

<div class="post-metadata">

**Author:** ![perrin](https://community.openhab.org/user_avatar/community.openhab.org/perrin/32/179_2.png) [@perrin](https://community.openhab.org/u/perrin)\
**Post date:** [August 13, 2015, 4:17am UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/6 "2015-08-13T04:17:46Z")

</div>

No worries, maybe I’ll add it as a configurable item instead of hardcoding it.  
Ill add it to the github repo as a ‘todo item’

I actually need to add another level to the topics at some point as well, as the “GID” which I assumed was always ‘1’ in the script changes if you have more than one of the ninja temperature/humidity sensors.

---

<div class="post-metadata">

**Author:** ![marklavercombe](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@marklavercombe](https://community.openhab.org/u/marklavercombe)\
**Post date:** [August 13, 2015, 4:24am UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/7 "2015-08-13T04:24:54Z")

</div>

Yeah, it was me that told you that, on the NB forum 😉

Thanks again!

---

<div class="post-metadata">

**Author:** ![Neko22](https://community.openhab.org/user_avatar/community.openhab.org/neko22/32/524_2.png) [@Neko22](https://community.openhab.org/u/Neko22)\
**Post date:** [August 14, 2015, 11:52am UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/8 "2015-08-14T11:52:30Z")

</div>

Just writing a message to add my support!

---

<div class="post-metadata">

**Author:** ![csanchez](https://community.openhab.org/user_avatar/community.openhab.org/csanchez/32/70927_2.png) [@csanchez](https://community.openhab.org/u/csanchez)\
**Post date:** [August 21, 2015, 8:27am UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/9 "2015-08-21T08:27:54Z")

</div>

I got the v1 and v2 running with the mqttbridge, updated the wiki page with my experience

> **[Setting up OpenHAB on rpi (and BBB)](https://github.com/perrin7/ninjacape-mqtt-bridge/wiki/Setting-up-OpenHAB-on-rpi-(and-BBB))**
>
> Python script for grabbing the JSON data over serial from the NinjaCape and publishing it as MQTT messages - perrin7/ninjacape-mqtt-bridge

In the BBB I left OpenHab v1 running, just because it is easier to install with apt-get. Only thing I had to do is limit the memory in JAVA\_OPTS and create a swap file, otherwise OpenHab was crashing every day, killed by the kernel

---

<div class="post-metadata">

**Author:** ![CyberneticianDave](https://community.openhab.org/user_avatar/community.openhab.org/cyberneticiandave/32/70953_2.png) [@CyberneticianDave](https://community.openhab.org/u/CyberneticianDave)\
**Post date:** [August 30, 2015, 10:10pm UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/10 "2015-08-30T22:10:43Z")

</div>

Hi

Followed you from the NinjaBlocks forum. I’ve ditched the Ninja image on my Pi, started with a fresh raspbian image, installed everything as per the instructions - with a couple of changes (openhab installed itself in /etc/openhab not /opt/openhab and I had to install upstart to get the services to start).

I can see that the messages are making it to MQTT by subscribing to them, but the connection with openhab doesn’t seem to be there.

Can anyone give me any tips on debugging this, like where are the logs I need to be looking at etc?

I can tell I’m pretty close. The combination of OpenHab and the PiCrust seems like it will be pretty powerful.

---

<div class="post-metadata">

**Author:** ![perrin](https://community.openhab.org/user_avatar/community.openhab.org/perrin/32/179_2.png) [@perrin](https://community.openhab.org/u/perrin)\
**Post date:** [September 3, 2015, 6:58am UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/11 "2015-09-03T06:58:30Z")

</div>

So you have a MQTT broker installed and can subscribe to the messages? All thats left is to configure the openHAB MQTT binding to subscribe to the broker, and start configuring items!

If you need some help doing this, reply and all see what I can do 🙂

---

<div class="post-metadata">

**Author:** ![CyberneticianDave](https://community.openhab.org/user_avatar/community.openhab.org/cyberneticiandave/32/70953_2.png) [@CyberneticianDave](https://community.openhab.org/u/CyberneticianDave)\
**Post date:** [September 3, 2015, 9:33am UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/12 "2015-09-03T09:33:38Z")

</div>

Thanks, I’d appreciate a bit of help. Haven’t had a chance to have a play since I wrote my last message.

I managed to get everything set up. I can view the OpenHab interface in the browser and I can view the messages successfully using `mosquitto_sub`.

OpenHab was configured using the instructions from the wiki page, i.e.

```
#default stuff    
folder:items=10,items
folder:sitemaps=10,sitemap
folder:rules=10,rules
folder:scripts=10,script
folder:persistence=10,persist
#mqtt stuff. In all my examples, broker name is mosquitto - this is customisable.
# if you need to add in authentication here, you can do that also - see default config for required lines
mqtt:mosquitto.url=tcp://127.0.0.1:1883

```

OpenHAB doesn’t reflect changes to RF devices and changing things in OpenHAB web interface doesn’t have any effect.

I’ll try and get it going this evening if I get a chance and see if I can pull anything useful out of the logs.

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![marklavercombe](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@marklavercombe](https://community.openhab.org/u/marklavercombe)\
**Post date:** [September 3, 2015, 10:29pm UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/13 "2015-09-03T22:29:55Z")

</div>

It looks like your openhab.cfg is ok.  
Can you post your item and sitemap definitions?  
I assume your item doesn’t have a mis-spelled _mosquitto_ as the broker? 🙂

---

<div class="post-metadata">

**Author:** ![CyberneticianDave](https://community.openhab.org/user_avatar/community.openhab.org/cyberneticiandave/32/70953_2.png) [@CyberneticianDave](https://community.openhab.org/u/CyberneticianDave)\
**Post date:** [September 4, 2015, 8:23am UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/14 "2015-09-04T08:23:54Z")

</div>

I wouldn’t be at all surprised! it’s bound to be something simple like that.

I had a quick go last night, although I forgot to pull off the log and the config files, so I’ll do that this evening.

It looks like the sitemap doesn’t seem to be able to find the relevant items, so it must be a problem in the item definition.

---

<div class="post-metadata">

**Author:** ![marklavercombe](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@marklavercombe](https://community.openhab.org/u/marklavercombe)\
**Post date:** [September 4, 2015, 8:28am UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/15 "2015-09-04T08:28:55Z")

</div>

if you can post the items and sitemap entries it should something easy enough

---

<div class="post-metadata">

**Author:** ![nick\_wootton](https://community.openhab.org/user_avatar/community.openhab.org/nick_wootton/32/70745_2.png) [@nick\_wootton](https://community.openhab.org/u/nick_wootton)\
**Post date:** [September 25, 2015, 8:19pm UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/16 "2015-09-25T20:19:11Z")

</div>

Silly question - I’ve got one of the original Ninjablocks (white Beaglebone board - Rev A6a) - not a cape on a RPi or Arduino. Can I install Ubuntu & OpenHAB on it and use the Ninjacape-mqtt-bridge on it?

Is it possible to run the bridge on the NB and have it talk to a mqtt broker/OH instance on another machine?

---

<div class="post-metadata">

**Author:** ![federic0](https://community.openhab.org/user_avatar/community.openhab.org/federic0/32/895_2.png) [@federic0](https://community.openhab.org/u/federic0)\
**Post date:** [September 26, 2015, 9:15am UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/17 "2015-09-26T09:15:31Z")

</div>

I too have a Beaglebone white (ninjablock), I haven’t tried installing openhab on it, however, I have installed mosquito and the mqttbridge on the beaglebone and openhab on a separate server and it works. Installing mosquito somewhere else should work too.

---

<div class="post-metadata">

**Author:** ![marklavercombe](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@marklavercombe](https://community.openhab.org/u/marklavercombe)\
**Post date:** [September 26, 2015, 12:40pm UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/18 "2015-09-26T12:40:48Z")

</div>

Also on BBW, have the bridge on that, mosquitto and openhab running elsewhere. Works well…

---

<div class="post-metadata">

**Author:** ![federic0](https://community.openhab.org/user_avatar/community.openhab.org/federic0/32/895_2.png) [@federic0](https://community.openhab.org/u/federic0)\
**Post date:** [September 28, 2015, 4:34pm UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/19 "2015-09-28T16:34:26Z")

</div>

I’m trying to configure, the thermometers that come with the NB (I own two thermometers). I am able to get the temperature though mqttbridge, however, when using the following item:

```
Number Thermo_1 “Thermo 1 [%.1f °C]" <temperature> (Kitchen) {mqtt=" <[mosquitto:ninjaCape/input/31:state:default]"}

```

I get readings from both sensors, so I am trying to set a regex in order to identify the right sensor, this is what mqttbridge outputs for the sensors:  
Thermometer 1:

```
 line to decode: {"DEVICE":[{"G":"0202","V":0,"D":31,"DA":21.50000}]}
 json decoded: {u'DEVICE': [{u'DA': 21.5, u'D': 31, u'G': u'0202', u'V': 0}]}

```

Thermometer 2:

```
line to decode: {"DEVICE":[{"G":"0301","V":0,"D":31,"DA":22.30000}]}
json decoded: {u'DEVICE': [{u'DA': 22.3, u'D': 31, u'G': u'0301', u'V': 0}]}

```

As you can see both sensors can be identified by the G id (0202 & 0301).

Would appreciate any help in writing the correct regex in order to get the data from the right thermometer.

---

<div class="post-metadata">

**Author:** ![perrin](https://community.openhab.org/user_avatar/community.openhab.org/perrin/32/179_2.png) [@perrin](https://community.openhab.org/u/perrin)\
**Post date:** [September 28, 2015, 10:55pm UTC](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330/20 "2015-09-28T22:55:05Z")

</div>

Hi @federic0

Yeah this is a known issue and I haven’t spent any time fixing it - its actually Issue #1 😄[GID assumed to be '1' when it can be different · Issue #1 · perrin7/ninjacape-mqtt-bridge · GitHub](https://github.com/perrin7/ninjacape-mqtt-bridge/issues/1)

Its a really simple fix - just need to add another level to the mqtt addressing - which will break everyone’s rules ☹

I didn’t realise that the ninja cape used the GID to identify items (i only have one temperature sensor!), so I hardcoded it to be ‘1’

[Next page](https://community.openhab.org/t/ninja-sphere-and-ninja-blocks-with-openhab/330.md?page=2)
