Hi @perrin, thanks a lot for the quick reply! Just tested your new code, it’s not working for me… I’m trying to see what’s going on but here’s an error I get when I try to actuate a wall plug:
ubuntu@ninjablock:/opt/openhab$ ./ninjaCapeSerialMQTTBridge.py
Connecting... /dev/ttyO1
Connected
Traceback (most recent call last):
File "./ninjaCapeSerialMQTTBridge.py", line 132, in <module>
ser.write(mqtt_to_JSON_output(outputData.pop()))
File "./ninjaCapeSerialMQTTBridge.py", line 69, in mqtt_to_JSON_output
json_data = '{"DEVICE": [{"G":"'+ topics[3] +'","V":0,"D":' + topics[2] + ',"DA":"' + mqtt_message.payload + '"}]})'
IndexError: list index out of range
Otherwise, there’s no output generated from ninjaCapeSerialMQTTBridge.py
The error I just cited is coming from my actuator’s topic missing the GID, the code is expecting an array of size 4. @perrin, in order not to break other’s rules and items you could probably test for the size of topics and when size is 3 go with your previous code.
The code is working, I had a typo in my item declarations for the thermometers. Sorry. However, you need to add a GID of ‘0’ and not ‘1’ to other items with the new script, i.e.:
@federic0 Nice! thanks for testing this. Yeah, i’ll put a test in that if there is no GID specified then use zero - which should allow backwards compatibility.
Once I get around to it…
Hi guys, I’m struggling with some sensors (cheap rf 433 Mhz PIRs and door sensors). When triggered they send a burst of signals (can be 4 signals within a second) and they seem to be activating my rules “in parallel”. The items are coming from the mqtt broker which receives them from the NinjaBlock. Anyone with NB with the same issue?
(I started a topic on this with more details here)
I have a working setup using OpenHAB and MQTT running on a RPi and a gateway on an Arduino as a receiver/transmitter for 433Mhz for FSK modulation. Now I want to my NB as a “gateway” for 433Mhz ASK modulation. If I got it right I just need to install MQTT client, shutdown Ninjablocks and install the script to collect the data from the receiver/transmitter and send through MQTT, is that right?
The script is working with some issues. The first time I run it I get an error that there is no route to route. If I just run the same command again (with no change) it works (see below). When I start it as service I have the same symptom and even when it starts as a service, it works for few minutes and stop sending messages to MQTT (running in another server). I have other gateways sending message to this MQTT server without problems and the Ninja blocks is connected to the same network and I monitored the connectivity and couldn’t find any network error. Any thoughts?
Thanks in advance!!!
root@ninjablock:/home/ubuntu# python /opt/openhab/ninjaCapeSerialMQTTBridge.py
Connecting… /dev/ttyO1
Traceback (most recent call last):
File “/opt/openhab/ninjaCapeSerialMQTTBridge.py”, line 117, in
mqttc.connect(broker, port, 60)
File “/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py”, line 612, in connect
return self.reconnect()
File “/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py”, line 734, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File “/usr/lib/python2.7/socket.py”, line 571, in create_connection
raise err socket.error: [Errno 113] No route to host
root@ninjablock:/home/ubuntu# python /opt/openhab/ninjaCapeSerialMQTTBridge.py
Connecting… /dev/ttyO1
Connected
Subscribed. mid: 1
line to decode: {“DEVICE”:[{“G”:“0”,“V”:0,“D”:1007,“DA”:“000000”}]}
looks like its the MQTT client thats crashing out, which is odd. Make sure you have the latest version from here: https://eclipse.org/paho/clients/python/
or do a
pip install paho-mqtt
The “no route to host” suggests an issue with your network - could you have a duplicate IP address or something simple thats interfering with it?
I did a full update/upgrade of the ubuntu and updated paho-mqtt as well. I’ll run some tests later today but it is working fine as a background job with a &.
I don’t have any other device with the same IP and I started a ping session from the Ninja to the MQTT server before I had run the script meaning that there is connectivity between both devices and it is still showing the same error. I’ll let you know how it will behavior after the upgrade.
Sorry for the huge delay, I’ve been distracted by a bunch of other projects. I’m still having problems with my OpenHab config, I’m pretty sure it’s my items file that’s wrong.
Here’s my default.items:
Group All
Group mainFloor (All)
Switch Doorbell "Doorbell" (All) <bell> {mqtt="<[mosquitto:ninjaCape/input/11:state:ON:010001000101010101010011],
>[mosquitto:ninjaCape/output/11:command:ON:010001000101010101010011]"
}
Switch smoke_1 "Lower Smoke Detector" (All) {mqtt="<[mosquitto:ninjaCape/input/11:state:ON:010101000101000100110000],
>[mosquitto:ninjaCape/output/11:command:ON:010101000101000100110000]"
}
Group frontroom "Front Room" (mainFloor)
Switch TV_Socket "TV Socket" (frontroom) {mqtt="<[mosquitto:ninjaCape/input/11:state:ON:000101010101010001010101],
<[mosquitto:ninjaCape/input/11:state:OFF:000101010101010001010100],
>[mosquitto:ninjaCape/output/11:command:OFF:000101010101010001010100],
>[mosquitto:ninjaCape/output/11:command:ON:000101010101010001010101]"
}
Color NinjaEyes (frontroom) {mqtt="<[mosquitto:ninjaCape/input/1007:state:JS(ninjaEyesColor.js)],
>[mosquitto:ninjaCape/output/1007:command:*:JS(ninjaEyesOutput.js)]"}
Color StatusLight (frontroom) {mqtt="<[mosquitto:ninjaCape/input/999:state:JS(ninjaEyesColor.js)],
>[mosquitto:ninjaCape/output/999:command:*:JS(ninjaEyesOutput.js)]"}
Group kitchen "Kitchen" (mainFloor)
Switch DW_Socket "Dishwasher Socket" (kitchen) {mqtt="<[mosquitto:ninjaCape/input/11:state:ON:000101010001010101010101],
<[mosquitto:ninjaCape/input/11:state:OFF:000101010001010101010100],
>[mosquitto:ninjaCape/output/11:command:OFF:000101010001010101010100],
>[mosquitto:ninjaCape/output/11:command:ON:000101010001010101010101]"
}
After the update/upgrade it is stable running as a background job (&) but still not working when I start it as a service. I’ll try to troubleshoot it more this weekend.
If it works running by hand but not as a service the problem is almost certainly one of permissions. When you are running it by hand I assume you are running it as the root user. But when it starts as a service (assuming you installed using apt-get) it runs as the openhab user. So you have to give openhab access to read and write to all the things it needs access to.
For example, a common problem with z-wave is that the openhab user needs to be added to the dialout group so it can read and write to /dev/ttyUSB0 (or whereever the z-wave controller appears). Another problem might be openhab doesn’t have permission to write to /var/log/openhab or read from /etc/openhab.
On a Raspberry Pi one problem can be that you need to be root to access the GPIO pins. If this is the case, you may need to update the openhab script in /etc/init.d so it starts with the root user and group instead.
Thanks for your reply. I’m running OpenHAB in a different RPi. The problem is to start the Python script wrote by Perrin. The script starts it as ubuntu user (sudo) so I don’t believe that it’s related to permissions. I’ll write a new start/stop script to test. I’ll let you know the outcome.