- Platform information:
- VM, QEMU Virtual CPU version 2.5+
- OS: Fedora Linux 35 (Server Edition)
- Java Runtime Environment: java-11-openjdk 1:11.0.13.0.8-2.fc35
- openHAB version: openhab 3.2.0-1
Hello,
I have been using openHAB for some time now (about 2 Years) and is so far happy with it, but this is my first post here.
I have some configurations in text-files (Eg. items & rules) that was migrated from openHAB2 to my current openHAB3 confuguration, other things are only in openHAB’s internal DB.
Now I wanted to start using MQTT for some homemade hardware (Wateralarm).
This is how the message from the device looks like
{"sensor":"Wateralarm","time":1640868995,"status":"OK"}
“sensor” is just a label
“time” is the last updated time in seconds since epoch
“status” is the status of the sensor
But I have some problems creating “usable” rules for it.
Here is what I have done:
- Install MQTT-Binding
- Configured my mosquitto-MQTT-Broker (not the “System MQTT Broker”) as a Thing
UID: mqtt:broker:b98cdf62cd
label: MQTT Broker
thingTypeUID: mqtt:broker
configuration:
lwtQos: 0
publickeypin: false
clientid: a0d03faa-eaba-4324-9585-cc629b212a33
keepAlive: 60
secure: false
certificatepin: false
password: xxxxxxxxxx
qos: 0
reconnectTime: 60000
host: ###.###.###.###
lwtRetain: true
enableDiscovery: true
username: xxxxxxxx
- Created a Thing (Wateralarm) with two channels:
UID: mqtt:topic:b98cdf62cd:0f40334c67
label: Wateralarm
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:b98cdf62cd
channels:
- id: Watchdog
channelTypeUID: mqtt:datetime
label: Watchdog
description: ""
configuration:
qos: 0
stateTopic: basement/wateralarm/state
transformationPattern: JSONPATH:$.time
- id: Status
channelTypeUID: mqtt:string
label: Status
description: ""
configuration:
allowedStates: OK,WARNING,CRITICAL,ERROR
qos: 0
stateTopic: basement/wateralarm/state
transformationPattern: JSONPATH:$.status
- In the events.log I can see that openHAB recieves the messages:
2021-12-30 13:28:59.980 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Wateralarm_Watchdog' changed from 2021-12-30T13:26:41.925616+0100 to 2021-12-30T13:28:59.977570+0100
2021-12-30 13:31:18.036 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Wateralarm_Watchdog' changed from 2021-12-30T13:28:59.977570+0100 to 2021-12-30T13:31:18.032917+0100
- I have started to create a rule (and here is where my problem starts…)
configuration: {}
triggers:
- id: "2"
configuration:
cronExpression: 0 * * * * ? *
type: timer.GenericCronTrigger
- id: "3"
configuration:
itemName: Wateralarm_Watchdog
type: core.ItemStateChangeTrigger
conditions: []
actions:
- inputs: {}
id: "1"
configuration:
type: application/vnd.openhab.dsl.rule
script: >-
logInfo("Wateralarm_Watchdog", "Triggered Status:" + Wateralarm_Watchdog);
type: script.ScriptAction
- I can see the logentries in openhab.log
2021-12-30 13:28:59.983 [INFO ] [ore.model.script.Wateralarm_Watchdog] - Triggered Status:Wateralarm_Watchdog (Type=DateTimeItem, State=2021-12-30T13:28:59.977570+0100, Label=Watchdog, Category=, Tags=[Point])
2021-12-30 13:29:00.877 [INFO ] [ore.model.script.Wateralarm_Watchdog] - Triggered Status:Wateralarm_Watchdog (Type=DateTimeItem, State=2021-12-30T13:28:59.977570+0100, Label=Watchdog, Category=, Tags=[Point])
2021-12-30 13:30:00.878 [INFO ] [ore.model.script.Wateralarm_Watchdog] - Triggered Status:Wateralarm_Watchdog (Type=DateTimeItem, State=2021-12-30T13:28:59.977570+0100, Label=Watchdog, Category=, Tags=[Point])
2021-12-30 13:31:00.877 [INFO ] [ore.model.script.Wateralarm_Watchdog] - Triggered Status:Wateralarm_Watchdog (Type=DateTimeItem, State=2021-12-30T13:28:59.977570+0100, Label=Watchdog, Category=, Tags=[Point])
2021-12-30 13:31:18.039 [INFO ] [ore.model.script.Wateralarm_Watchdog] - Triggered Status:Wateralarm_Watchdog (Type=DateTimeItem, State=2021-12-30T13:31:18.032917+0100, Label=Watchdog, Category=, Tags=[Point])
Now for my problem: How can I “access” the information in the status-message?
I want to be able to compare the DateTime in the “message” with the current DateTime to be able to detect a “stale” device (the DateTime in the message are more then 10 Minutes old).
Any suggestions or a link to an up2date dokumentation?
Regards,
Dan Johansson