- Platform information:
- Hardware: Raspberry PI 4
- OS: Raspbian (latest version)
- openHAB version: 3.2
- Issue of the topic: How to get item state in a JSRule automation
Is it possible to read item state in a JSRule automation ?
Right now, I have this script, which works but is bulcky
rules.JSRule({
name: 'draadloze schakelaar slaapkamer 4 - AAN',
triggers: [triggers.ItemCommandTrigger('vlg_cocoSchakelaar', 'ON')],
execute: data => {
items.getItem("vlg_slpk_stefaan").sendCommand("ON")
}
})
rules.JSRule({
name: 'draadloze schakelaar slaapkamer 4 - UIT',
triggers: [triggers.ItemCommandTrigger('vlg_cocoSchakelaar', 'OFF')],
execute: data => {
items.getItem("vlg_slpk_stefaan").sendCommand("OFF")
}
})
I would like to rewrite the script by getting the new item state from the switch sensor and sending it to the actuator, something like this
rules.JSRule({
name: 'draadloze schakelaar slaapkamer 4',
triggers: [triggers.ItemCommandTrigger('vlg_cocoSchakelaar')],
execute: data => {
const status = items.getItem("vlg_slpk_stefaan").status
console.log(status)
}
})
However,
-
items.getItem("vlg_slpk_stefaan").status()
throws -
items.getItem("vlg_slpk_stefaan")
.status isundefined
-
data
looks like below, allthough there is anewState
property, it isnull
{
"eventType": "command",
"triggerType": "ItemCommandTrigger",
"receivedCommand": {},
"oldState": "null",
"newState": "null",
"itemName": "vlg_cocoSchakelaar"
}
Any ideas ?