Jump to content
View in the app

A better way to browse. Learn more.

Tinkerunity

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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
  • Autor

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.