rwblinn Geschrieben February 29, 2016 at 14:36 Share Geschrieben February 29, 2016 at 14:36 Hi, as a test tried to setup openHAB MQTT displaying AmbientLight bricklet Illuminance BUT nothing is displayed. Any idea what could be wrong? Items Number Illuminance "Illuminance [%.0f Lux]" <none> { } String IlluminanceRaw "IlluminanceRaw" [%s] <none> { mqtt="<[mosquitto:tinkerforge/bricklet/ambient_light/mdh/illuminance:state:default]" } Rule import org.openhab.core.library.types.* import org.openhab.core.persistence.* import org.openhab.model.script.actions.* rule "MqttAmbientLightParse" when Item IlluminanceRaw changed then var String json = (IlluminanceRaw.state as StringType).toString logInfo("FILE", json) //{"illuminance":1354,"_timestamp":1456750088.109141} var String il = transform("JSONPATH", "$.illuminance", json) logInfo("FILE", "IL="+il) var String ts = transform("JSONPATH", "$._timestamp", json) logInfo("FILE", "TS="+ts) sendCommand(Illuminance, il) end sitemap sitemap ambientlightmqtt label="MQTT Illuminance" { Frame { Text item=Illuminance Text item=IlluminanceRaw } } Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
rwblinn Geschrieben March 1, 2016 at 06:17 Autor Share Geschrieben March 1, 2016 at 06:17 By... Items Number Illuminance "Illuminance [%.0f Lux]" <none> String IlluminanceTimeStamp "Illuminance Timestamp [%1$tm/%1$td %1$tH:%1$tM]" <none> String IlluminanceRaw "IlluminanceRaw [%s]" <none> { mqtt="<[mosquitto:tinkerforge/bricklet/ambient_light/mdh/illuminance:state:default]" } Sitemap sitemap ambientlightmqtt label="MQTT Illuminance" { Frame { Text item=Illuminance Text item=IlluminanceTimeStamp Text item=IlluminanceRaw } } Rules = UNIX timestamp conversion needs to be improved. import org.openhab.core.library.types.* import org.openhab.core.persistence.* import org.openhab.model.script.actions.* import org.joda.time.* rule "MqttAmbientLightParse" when Item IlluminanceRaw changed then //Convert the raw data to a string var String data = (IlluminanceRaw.state as StringType).toString //Parse the JSON string // { "illuminance":1354,"_timestamp":1456750088.109141 } //Illuminance var String il = transform("JSONPATH", "$.illuminance", data) var iln = new Double(il) iln = iln * 0.1 Illuminance.postUpdate( iln) //Timestamp var String ts = transform("JSONPATH", "$._timestamp", data) //THIS NEEDS TOBE IMPROVED ts = ts.replaceAll("E9", "") ts = ts.replaceAll("[.]", "") //IlluminanceTimeStamp.postUpdate(ts) var DateTime dt = new DateTime(Long::parseLong(ts) * 1000L) IlluminanceTimeStamp.postUpdate(new DateTimeType(dt.toString)) end Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.