Verwende openHAB 2.5.10-1 + binding-mqtt - 2.5.10
Ich schicke von einem Arduino Mega via MQTT die millisekunden millis().
Die Zahl ist natürlich sehr groß. Deshalb möchte ich z.B. durch 1000 dividieren.
Mir ist klar, das kann ich am Arduino problemlos machen, möchte aber aus Interesse das in OH2 lösen.
Subscribe ich am Broker das topic, wo mein Wert drinnen ist, kommt z.B. "PVX/millis 7394608"
Ich kann das dann in xyz.things mit
Code: Alles auswählen
Thing topic PVX "PVX" @ "PVX" {
Channels:
Type number : PVX_millis "PXV_millis" [stateTopic="PVX/millis" ]
}
Code: Alles auswählen
Number PV_millis "PV millis" <temperature> (fast) { channel="mqtt:topic:mosquitto:PVX:PVX_millis", autoupdate="false"}
Nun möchte ich durch z.b. 1000 dividieren und habe gelesen ,das soll via Profile? und JS gehen.
Dazu JS-file erstellt .....transform/divide_by_1000.js
Code: Alles auswählen
(function(i) {
var test = parseFloat(i) /1000.0;
return test;
})(input)
Code: Alles auswählen
Number PV_millis "PV millis" <temperature> (fast) { channel="mqtt:topic:mosquitto:PVX:PVX_millis"[profile="transform:JS", function="divide_by_1000"]}
Schon mehrere Varianten ausprobiert, aber ich komm nicht weiter.Could not transform state '7669508' with function 'divide_by_1000' and format '%s'
wo muss ich schrauben?
Danke, solong.