I want to get item value in rules file

Hello everyone!
I’m beginner in openhab2 so I need your help.
The main problem is getting item value in rules file
For example: I can get the state of user_label_1 item in the openhab console.
openhab> smarthome:state user_label_1
But I don’t know how to get this value in example.rules file.
If you know about the solution of this problem, please help me.
The sample code will be very helpful.
Looking forward to hearing from you.
Regards.

Maybe this helps:


rule "Battery Status Check"
when
    Item gBatteries changed
then
    var String msg = ""
    var triggertDevices = gBatteries.members.filter[s|s.state <= 20]

    triggertDevices.forEach [ i |
        msg = msg + (transform("MAP", "batteries.map", i.name) + ': ' + i.state.toString) + '%\n'
        logInfo("Battery Check","Low battery at " + i.name + ": " + i.state.toString + "%")
    ]

    if (msg != "") {
sendBroadcastNotification(msg + " of your battery remaining")
    }
end

I think you are looking for this at the relevant part…
Or look at the documentation

this is item object.
{
“link”: “http://192.168.0.3:8080/rest/items/user_label_1”,
“state”: “Sam”,
“editable”: false,
“type”: “String”,
“name”: “user_label_1”,
“tags”: [],
“groupNames”: []
},

in this case, how can I get the state of item?

Really?

I’ve been pulling different strings from items by using this syntax

SayItem.state

For example

rule "test"
Item StringItem received update
then
NewStringItem.sendCommand(StringItem.state)
end

I think there’s a bit of confusion in the question and replies about whether we want to get the state of some Item myItem , or we have a string “myItem” and want to get the state of an Item by that name.

1 Like

You are right. To not confuse the OP I deleted my posts. Thx.