ThomDietrich/miflora-mqtt-daemon

"NULL" values in openhab2

Closed this issue · 6 comments

First of all, I think your work as awesome and I would like to say thanks for all your effort.

I'm trying to get the deamon running with openhab2. I'm using Mosquitto and everything seems to be working fine, except for the openhab side.
I've already subscribed to my Mosquitto broker with a external MQTT client (MQTTlens) and I can see the messages coming in perfectly fine.
Also I can see openhab connect to the broker:
New client connected from ::1 as be50527e-cf77-4ddb-b94b-30057bdcbeca (c1, k60, u'openhabian').

However when I try to define a dummy component in HABPanel, it keeps saying "NULL".

My configurations for the mqtt binding and openhab are as follows:

services/mqtt.cfg:

mosquitto.url=tcp://127.0.0.1:1883
mosquitto.user=openhabian
mosquitto.pwd=xxx
mosquitto.qos=1
mosquitto.retain=true
mosquitto.async=false

items/miflora.items:

Group gMiFlora "All Mi Flora sensors and elements" (gAll)
Group gLightIntensity "Mi Flora Sunlight Intensity elements" (gAll, gMiFlora)
Group gAirTemperature "Mi Flora Air Temperature elements" (gAll, gMiFlora)
Group gSoilMoisture "Mi Flora Soil Moisture elements" (gAll, gMiFlora)
Group gSoilConductivity "Mi Flora Soil Conductivity/Fertility elements" (gAll, gMiFlora)
Group gBattery "Mi Flora Sensor Battery Level elements" (gAll, gMiFlora)

// Mi Flora "Groot" (C4:7C:8D:65:C1:AA)
Group gGroot "Mi Flora Sensor Groot" (gMiFlora)
Number Groot_LightIntensity "Groot Sunlight Intensity [%d lux]" <text> (gGroot, gLightIntensity) {mqtt="<[mosquitto:miflora/Groot:state:JSONPATH($.light)]"}
Number Groot_AirTemperature "Groot Air Temperature [%.1f °C]" <text> (gGroot, gAirTemperature) {mqtt="<[mosquitto:miflora/Groot:state:JSONPATH($.temperature)]"}
Number Groot_SoilMoisture "Groot Soil Moisture [%d %%]" <text> (gGroot, gSoilMoisture) {mqtt="<[mosquitto:miflora/Groot:state:JSONPATH($.moisture)]"}
Number Groot_SoilConductivity "Groot Soil Conductivity/Fertility [%d µS/cm]" <text> (gGroot, gSoilConductivity) {mqtt="<[mosquitto:miflora/Groot:state:JSONPATH($.conductivity)]"}
Number Groot_Battery "Groot Sensor Battery Level [%d %%]" <text> (gGroot, gBattery) {mqtt="<[mosquitto:miflora/Groot:state:JSONPATH($.battery)]"}

Any suggestions?

Thanks in advance!

Hey Bart 👋
thanks for the encouragement! ;)

First of all, please check with this Tutorial to cover the basis: https://community.openhab.org/t/mqtt-binding-v1-11-getting-started-101/33958

Remove the settings qos, retain and async. They are not needed, the default is okay. After going through the Tutorial you should be confident everything is ready.

You should now compare the data you are seeing in your standalone client and your openHAB log. Are values published to the broker also stored in the respective Items? If not, why? That should be easy to figure out.

AFTER this is settled, you can bother about HABPanel.

Btw. Love your plant name ;)

Hmmm I didn't know about the log viewer yet, good to know!
It seems that my events.log isn't being created at all.... It's showing up empty in the log viewer and it doesn't exists in /var/log/openhab2/. I tried searching the forums and setting the log lever in the Karaf shell, but couldn't get it to generate.

Edit:
Alright I finally got it working. Did an upgrade from openhabian config and replaced org.ops4j.pax.logging.cfg files.

I can completely walk through that tutorial now. I can get:
MQTT_Test changed from NULL to ON

When doing:
Switch MQTT_Test "Testing..." { mqtt="<[broker:miflora/Groot:state:default]" }
And publishing ON or OFF I also get a change in the log.
However the jsons from the deamon that are incoming are not triggering any event in the log... (I also have miflora.items running)

Edit 2
Hmmmmm.... This (String instead of Number):
String MQTT_Test "Testing..." <text> { mqtt="<[broker:miflora/Groot:state:JSONPATH($.light)]" }
Produces:
MQTT_Test changed from NULL to JSONPATH($.light)
Looks like it's not using the jsonpath format function correctly, and since it's a number it's not showing any change.

Edit 3
I installed the jsonpath transformation (didn't know it needed installing, maybe add it to the readme?)
It now throws me the following error:

MQTT connection to broker was lost
org.eclipse.paho.client.mqttv3.MqttException: MqttException
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:197) [200:org.openhab.io.transport.mqtt:1.11.0.201709060110]
	at java.lang.Thread.run(Thread.java:745) [?:?]
Caused by: java.lang.NoClassDefFoundError: net/minidev/json/writer/JsonReaderI
	at com.jayway.jsonpath.internal.DefaultsImpl.<init>(DefaultsImpl.java:17) ~[?:?]
	at com.jayway.jsonpath.internal.DefaultsImpl.<clinit>(DefaultsImpl.java:15) ~[?:?]
	at com.jayway.jsonpath.Configuration.getEffectiveDefaults(Configuration.java:48) ~[?:?]
	at com.jayway.jsonpath.Configuration.defaultConfiguration(Configuration.java:173) ~[?:?]
	at com.jayway.jsonpath.internal.JsonContext.<init>(JsonContext.java:52) ~[?:?]
	at com.jayway.jsonpath.JsonPath.read(JsonPath.java:502) ~[?:?]
	at org.eclipse.smarthome.transform.jsonpath.internal.JSonPathTransformationService.transform(JSonPathTransformationService.java:49) ~[?:?]
	at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:65) ~[?:?]
	at org.openhab.binding.mqtt.internal.MqttMessageSubscriber.processMessage(MqttMessageSubscriber.java:138) ~[?:?]
	at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.messageArrived(MqttBrokerConnection.java:556) ~[?:?]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:475) ~[?:?]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:379) ~[?:?]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:183) ~[?:?]
	... 1 more
Caused by: java.lang.ClassNotFoundException: net.minidev.json.writer.JsonReaderI cannot be found by com.jayway.jsonpath.json-path_2.1.0
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461) ~[?:?]
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372) ~[?:?]
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364) ~[?:?]
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161) ~[?:?]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:?]
	at com.jayway.jsonpath.internal.DefaultsImpl.<init>(DefaultsImpl.java:17) ~[?:?]
	at com.jayway.jsonpath.internal.DefaultsImpl.<clinit>(DefaultsImpl.java:15) ~[?:?]
	at com.jayway.jsonpath.Configuration.getEffectiveDefaults(Configuration.java:48) ~[?:?]
	at com.jayway.jsonpath.Configuration.defaultConfiguration(Configuration.java:173) ~[?:?]
	at com.jayway.jsonpath.internal.JsonContext.<init>(JsonContext.java:52) ~[?:?]
	at com.jayway.jsonpath.JsonPath.read(JsonPath.java:502) ~[?:?]
	at org.eclipse.smarthome.transform.jsonpath.internal.JSonPathTransformationService.transform(JSonPathTransformationService.java:49) ~[?:?]
	at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:65) ~[?:?]
	at org.openhab.binding.mqtt.internal.MqttMessageSubscriber.processMessage(MqttMessageSubscriber.java:138) ~[?:?]
	at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.messageArrived(MqttBrokerConnection.java:556) ~[?:?]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:475) ~[?:?]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:379) ~[?:?]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:183) ~[?:?]
	... 1 more

Ps: The plant actually looked quite a bit like Groot when it didn't have any leaves ;) Will add picture later.

Hi. may be this topic not rightfor my question, but after reboot Pi miflora service did'n start with openhab.
sudo systemctl status miflora.service

● miflora.service - Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
   Loaded: loaded (/etc/systemd/system/miflora.service; enabled)
   Active: failed (Result: exit-code) since Wed 2017-09-06 22:12:51 MSK; 4min 46s ago
     Docs: https://github.com/ThomDietrich/miflora-mqtt-daemon
  Process: 440 ExecStart=/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py (code=exited, status=1/FAILURE)
 Main PID: 440 (code=exited, status=1/FAILURE)
   Status: "Sep 06 22:12:51 - MQTT connection error. Please check your settings in the configuration file "config.ini"."

Sep 06 22:12:50 openHABianPi systemd[1]: Starting Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon...
Sep 06 22:12:51 openHABianPi miflora-mqtt-daemon.py[440]: [2017-09-06 22:12:51] MQTT connection error. Please c...ni"
Sep 06 22:12:51 openHABianPi systemd[1]: miflora.service: main process exited, code=exited, status=1/FAILURE
Sep 06 22:12:51 openHABianPi systemd[1]: Failed to start Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon.
Sep 06 22:12:51 openHABianPi systemd[1]: Unit miflora.service entered failed state.
Hint: Some lines were ellipsized, use -l to show in full.

How to make miflora service start with the system?(I new with *nix system, but wona now how it work) Because after command:
sudo systemctl start miflora.service
All start work fine!
Can you push me in right way?

Finallyyy I got it working.

According to the last post in this thread: https://community.openhab.org/t/problem-with-mqtt-jsonpath-transformation/32833/7

There are some errors with openhab installations that have been updated. Therefore deleting the /var/lib/openhab2/config/org/openhab/mqtt.config resolved it.

For anyone else reading this:
This all had to do my openhab installing and nothing with this extremely powerful tool.

@ThomDietrich I think it would be nice add the installation of the JSONPATH transformation to the readme.

Thanks a lot mate!

Hey @bartvollebregt,
sorry I missed to answer in time - but I'm glad you got it working! I'll add a note regarding JSONPATH to the README. Additionally I've added the issue with the mqtt.config to the Tutorial linked above. Thanks for reminding me.

Last thing: I'm always intrigued to improve the functionality and usability of this tool. So if you ever see something that you think could be changed or added, don't hesitate to open an issue ticket ;)

@Nickolay40 could you please open a new issue with the message from above?