Jump to content

Recommended Posts

Geschrieben

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
}
} 

 

Geschrieben

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Reply to this topic...

×   Du hast formatierten Text eingefügt.   Formatierung jetzt entfernen

  Only 75 emoji are allowed.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Clear editor

×   Du kannst Bilder nicht direkt einfügen. Lade Bilder hoch oder lade sie von einer URL.

×
×
  • Neu erstellen...