On a reboot, my devices are staying in their previous state (at least as I’m still in testing mode, and all my switched are off at the time of reboot). That said after the reboot the icons are all showing on but the switches in the ui are all off.
Unfortunately after installing the mapdb and adding the persistence then performing a remote reboot, the system did not come back up so I now have to wait until the other half will power down and up again. So it is only the icon states that I wanted to retain or refresh.
I’m not sure about the QOS state ado I will have to go read up on that aspect before I know how to answer that one.
Vincent’ s advice to use the expire binding is very useful and an easy solution to signal you the sensor somehow is ofline.
Keep in mind though that if your temperature or humidity are also in e.g. an ‘average’ group, that ‘0’ value will influence the average. Maybe not a big thing but if you have other processes depending on it, it may become a big thing.
Obviously you need to solve why your device is offline, but as it is hanging on an ESP8266, you could have an MQTT message sent when your sensor cant be read.
Also, when it would be the entire ESP8266 that goes offline for whatever reason, that can be checked too with the network binding using lines like (this is for my phone, but works on all sorts of connected devices):
For the tasmota devices in particular, the broker will issue a LWT message (Last Will and Testament) when they disconnect.
I use that to monitor if they are online:
What is this for? I have a similar doubt, I need to extract temperature value from a string data that consists of other information, Can I use the above code to do that.
My data that I subcribe from mqtt looks like the screenshot attached below
rule "Parse Room Temperature"
when
Item home_temp received update
then
val tem = transform("JSONPATH", "$.Object.adc", home_temp)
logInfo("TEST", tem.toString)
end
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)
}
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…