Hi there, first of all, thanks for OpenHab, it’s a great piece of software, if a little daunting for the beginner!
Some background, I’ve managed to install and configure Openhab, it’s currently displaying weather in my area from Openweathermap, and also displaying the temp and humidity of an Arduino device with a DHT11 sensor on it (this is via an Arduino gateway, then into a Raspberry Pi via MQTT)
Since the temp/humidity node is battery powered, I wanted to know when the last update was (it’s set to 60 second updates). In simple terms, how do I achieve this? I’m persisting the data on each update of the node, so I have that setup and working.
I’m not completely sure on how to do it entirely, but my method would be to capture the time on the temp node (through maybe a clock module), take the time from the module as your node is creating the message to send, then when it sends the message, with the time inside of the message, get your controller to pull the time out of the message and then either print it to the console or even set yourself a item on the webapp called something like “Time of temperature reading on Node1”. That is my two cents, and i’m sure that someone else would come up with a better/sleeker/more efficient method.
From my Items file:
Number itm_temp1_mqtt “Temperature [%.2f]” (Indoor, Temp) {mqtt="<[mymosquitto:home/rfm_gw/nb/node10/dev48:state:default]"}
Number itm_hum1_mqtt “Humidity [%.2f]” (Indoor) {mqtt="<[mymosquitto:home/rfm_gw/nb/node10/dev49:state:default]"}
DateTime sensor1_LastUpdate “Sensor-1 Last Update [%1$ta %1$tR]” (Update)
From my rules file:
rule “sensor1_lastupdate”
when
Item itm_temp1_mqtt received update or
Item itm_light1_mqtt received update
then
postUpdate(sensor1_LastUpdate, new DateTimeType())
end
From my sitemap file:
Frame label=“Sensor-1”
{
Text item=itm_temp1_mqtt icon=“temperature”
Text item=itm_hum1_mqtt icon=“temperature”
Text item=sensor1_LastUpdate icon=“clock-on”
}
Thanks, I tried this too and nothing is happening! Copied everything, only thing I changed was the Item names in the rules file. Does the rules file get picked up automatically?
Thanks, it appears they are, but I’m getting this error
2015-11-15 16:01:47.236 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'sensor1_lastupdate' java.lang.NullPointerException: null
That did the trick…thanks, much appreciated - next question, can I combine 2 items in a single sitemap items? I simply want to display the temp and humidity together with the last updated in brackets, on the same line.
rules file:
rule “wind_speed”
when
Item Wind_Direction changed or
Item Wind_Speed_Mph changed or
then
var Number speed = Wind_Speed_Mph.state
var String dir = Wind_Direction.state
postUpdate(Wind_Out, dir + " at " + speed + " Mph")
end
Thanks! Much appreciated, there is a quite a learning curve, but I think it’ll be worth it. Last (well maybe not), how do I, instead of passing the date that it was last updated, but instead say last updated, for example, 1 minute ago?