[SOLVED] Mqtt Temp and humidity setup


(Vincent Regaud) #32

New item:

String MQTTTest { mqtt="<[mosquitto:application/2/node/0000000000000013/rx:state:default" }

Rule:

rule "Parse Room Temperature"
when
    Item home_temp received update
then
    val tem = transform("JSONPATH", "$.Object.adc", home_temp)
    logInfo("TEST", tem.toString)
end

What do you see in the log?


(minnu maria) #35

The variable tem is just used in rules… Is that wrong??


(minnu maria) #36

Logs look like this

2018-08-09 15:51:58.000 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'outlet.rules'
2018-08-09 15:51:58.012 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'outlet.rules' is either empty or cannot be parsed correctly!
2018-08-09 15:51:58.084 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'outlet.rules'
2018-08-09 15:53:16.886 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'oulet.items'
2018-08-09 15:53:16.894 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'oulet.items'
2018-08-09 15:53:41.199 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'outlet.sitemap'
2018-08-09 15:53:41.201 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'outlet.sitemap' is either empty or cannot be parsed correctly!
2018-08-09 15:53:41.244 [ERROR] [.core.internal.folder.FolderObserver] - Error handling update of file 'C:\openHAB2\conf\sitemaps\outlet.sitemap': null.
java.lang.NullPointerException
	at org.eclipse.smarthome.io.rest.sitemap.internal.PageChangeListener.getAllItems(PageChangeListener.java:125)[117:org.eclipse.smarthome.io.rest.sitemap:0.9.0.b5]
	at org.eclipse.smarthome.io.rest.sitemap.internal.PageChangeListener.updateItemsAndWidgets(PageChangeListener.java:75)[117:org.eclipse.smarthome.io.rest.sitemap:0.9.0.b5]
	at org.eclipse.smarthome.io.rest.sitemap.internal.PageChangeListener.sitemapContentChanged(PageChangeListener.java:217)[117:org.eclipse.smarthome.io.rest.sitemap:0.9.0.b5]
	at org.eclipse.smarthome.io.rest.sitemap.SitemapSubscriptionService.modelChanged(SitemapSubscriptionService.java:277)[117:org.eclipse.smarthome.io.rest.sitemap:0.9.0.b5]
	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:286)[122:org.eclipse.smarthome.model.core:0.9.0.b5]
	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:136)[122:org.eclipse.smarthome.model.core:0.9.0.b5]
	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:234)[122:org.eclipse.smarthome.model.core:0.9.0.b5]
	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processWatchEvent(FolderObserver.java:297)[122:org.eclipse.smarthome.model.core:0.9.0.b5]
	at org.eclipse.smarthome.core.service.WatchQueueReader.run(WatchQueueReader.java:206)[98:org.eclipse.smarthome.core:0.9.0.b5]
	at java.lang.Thread.run(Unknown Source)[:1.8.0_171]
2018-08-09 15:53:41.258 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'outlet.sitemap'

My rules file have the following code

rule "Parse Room Temperature"
when
        Item home_temp received update
then
        val tem = transform("JSONPATH", "$.Object.adc", home_temp.toString)
		home_temp.postUpdate(tem)
       
end
rule "Parse Room Temperature1"
when
    Item home_temp received update
then
    val tem = transform("JSONPATH", "$.Object.adc", home_temp)
    logInfo("TEST", tem.toString)
end
rule "secure"
when 
  Item Office_temp received update
 then
  
      try{
	  val temper=(Office_temp.state as Number)
	  if(temper>=1){
	  sendNotification("xxxx@gmail.com", "security: someone has entered")
	  }
	  
	  }
	  catch(Exception e){
        logError("ID", "Error calculating next Node ID: " + e.toString)
    }

(Vincent Regaud) #37

No need for the sitemap. Just monitor the log file


(minnu maria) #38

I did, not sure what the error means though, it says rules file is either empty or cannot be parsed correctly.


(Vincent Regaud) #39

OK post the rule file, please


(CM6.5 H102) #40

The rules file above is missing an “end” at the end of last rule.


(minnu maria) #41

The rules file doesn’t give errors now but neither does it show the logs of mqtt subscription. Although I can see the data in mqtt lens. I even get info in logs as starting mqtt broker connection mosquitto. Although there is an info that

2018-08-10 14:11:36.860 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'b.items'
2018-08-10 14:11:37.143 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mysql.persist'
2018-08-10 14:11:39.438 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'b.rules', using it anyway:
The value of the local variable tem is not used


My rules file currently look like this


rule "Parse Room Temperature"
when
        Item home_temp received update
then
        val tem = transform("JSONPATH", "$.Object.adc", home_temp)    
end

rule "Parse Room Temperature_1"
when
    Item home_temp received update
then
    val tem = transform("JSONPATH", "$.Object.adc", home_temp)
    logInfo("TEST", tem.toString)
end```

so i edited it like this

```php
when
        Item home_temp received update
then
        val tem = transform("JSONPATH", "$.Object.adc", home_temp)    
        home_temp.postUpdate(tem)
end

now i don’t get that info in logs but it’s still now displaying the value in openhab or logs.
Any help on what could be the issue…


(Vincent Regaud) #42

Can you post the current definition of the item home_temp, please?


(minnu maria) #43
Number home_temp "Living Room [%.1f °C]" <temperature> ["CurrentTemperature"] {mqtt="<[mosquitto:application/2/node/0000000000000013/rx:state:JSONPATH($.object.adc)]"}


(Vincent Regaud) #44

Ok, so you are getting home temp from the binding as number already transofrmed and then you are trying to transform it again in the rule.

Create this item:

String JsonString { mqtt="<[mosquitto:application/2/node/0000000000000013/rx:state:default" }

Add a space it the {} of the home_temp item just in case. It helps sometimes. And remove the tag. And comment out the binding temporarily.

Number home_temp "Living Room [%.1f °C]" <temperature> //{ mqtt="<[mosquitto:application/2/node/0000000000000013/rx:state:JSONPATH($.object.adc)]" }

Then change the rule to:

rule "Parse Room Temperature_1"
when
    Item jsonString received update
then
    val tem = transform("JSONPATH", "$.Object.adc", home_temp)
    logInfo("TEST", tem.toString)
    home_temp.postUpdate(tem)
end

(minnu maria) #45

I have done it like you said…

rule "Parse Room Temperature_1"
when
    Item JsonString received update
then
	logInfo("TEST", "running")
	logInfo("TEST1", JsonString)
    val  tem = transform("JSONPATH","$.object.adc",JsonString)
    logInfo("TEST", tem)
    home_temp.postUpdate(tem)
end


That’s the rules file

Number home_temp "Living Room [%.1f °C]" <temperature> 


String JsonString {mqtt="<[mosquitto:application/2/node/0000000000000013/rx:state:default]"}

That’s the items file

2018-08-14 12:43:03.948 [INFO ] [.eclipse.smarthome.model.script.TEST] - running
2018-08-14 12:43:03.949 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Parse Room Temperature_1': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null
2018-08-14 12:43:04.923 [INFO ] [.eclipse.smarthome.model.script.TEST] - running
2018-08-14 12:43:04.924 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Parse Room Temperature_1': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null

Thts log . I’n not sure what causes these errors… any help…


(Vincent Regaud) #46

Try that:

rule "Parse Room Temperature_1"
when
    Item JsonString received update
then
	logInfo("TEST", "running")
	logInfo("TEST1", JsonString.toString)
    val  tem = transform("JSONPATH", "$.object.adc", JsonString.toString)
    logInfo("TEST", tem)
    home_temp.postUpdate(tem)
end

(minnu maria) #47
2018-08-14 16:05:38.940 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'b.rules'
2018-08-14 16:05:44.621 [INFO ] [.eclipse.smarthome.model.script.TEST] - running
2018-08-14 16:05:44.622 [INFO ] [eclipse.smarthome.model.script.TEST1] - JsonString (Type=StringItem, State={
  "applicationID": "2",
  "applicationName": "",
  "deviceName": "0",
  "devEUI": "",
  "rxInfo": [
    {
      "mac": "b827ebfffe0edf3b",
      "rssi": -119,
      "loRaSNR": 4.5,
      "name": "wizsen-",
      "latitude": ,
      "longitude":,
      "altitude": 40
    }
  ],
  "txInfo": {
    "frequency": ,
    "dataRate": {
      "modulation": "LORA",
      "bandwidth": 125,
      "spreadFactor": 12
    },
    "adr": true,
    "codeRate": "4/5"
  },
  "fCnt": 139,
  "fPort": 11,
  "data": "",
  "object": {
    "adc": "1071"
  }
}, Label=null, Category=null)
2018-08-14 16:05:44.669 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': Invalid path '$.object.adc' in 'JsonString (Type=StringItem, State={
  "applicationID": "2",
  "applicationName": "India-Lecture",
  "deviceName": "0000000000000013",
  "devEUI": "0000000000000013",

I’m able to get the entire data…

2018-08-14 16:05:45.339 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert 'JsonString (Type=StringItem, State={
, Label=null, Category=null)' to a state type which item 'home_temp' accepts: [DecimalType, UnDefType].

I suppose i need to convert it into a decimal type… because it’s not updating in openhab… is there any command to do that?


(Vincent Regaud) #48

Again. use .toString

rule "Parse Room Temperature_1"
when
    Item JsonString received update
then
	logInfo("TEST", "running")
	logInfo("TEST1", JsonString.toString)
    val  tem = transform("JSONPATH", "$.object.adc", JsonString.toString)
    logInfo("TEST", tem)
    home_temp.postUpdate(tem.toString)
end

(Vincent Regaud) #49

But now that we have established that

  • mqtt works
  • binding syntax is correct

You can try this directly and bypass the rule:

Number home_temp "Living Room [%.1f °C]" <temperature>  {mqtt="<[mosquitto:application/2/node/0000000000000013/rx:state:JSONPATH($.object.adc)]"}

(minnu maria) #50


(Vincent Regaud) #51

Cool that works!
Now are you sure that this is a temperature?


(minnu maria) #52

No temperature is not being sent, But Thank you , couldn’t have done it without your help :smiley:


(minnu maria) #53

Earlier I tried sending from mqtt broker and it worked fine…
So I tried sending directly from LoRa gateway,that has different mqtt IP address and this issue popped up . Any help on what it might be…

2018-08-21 16:37:42.707 [ERROR] [org.apache.felix.configadmin        ] - Cannot use configuration org.openhab.mqtt for [org.openhab.core.scriptengine.action.ActionService, org.osgi.service.cm.ManagedService, id=312, bundle=207/mvn:org.openhab.action/org.openhab.action.mqtt/1.10.0]: No visibility to configuration bound to mvn:org.openhab.io/org.openhab.io.transport.mqtt/1.10.0