Java Runtime Environment: openjdk version “11.0.6” 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Raspbian-1deb10u1)
OpenJDK Server VM (build 11.0.6+10-post-Raspbian-1deb10u1, mixed mode)
openHAB version: 2.5.4
I have a map file which allows me to match the JSON received from an external box with my items in OH2
Itemtobox.map
0=Item1
1=item2 …
when receiving the JSON I extract the values:
“kakusensors”: [
{
“id”: 0,
“status”: “ON”,
},
{
“id”: 1,
“status”: “OFF”,
}
] I recover the name of the switch and its status
status returns me "ON"
map -> id = 0 returns me "item1"
and I match the status of OH2 with that received from box
item1.sendCommand(cmde)
All this is perfectly functional !!! my problem is to get the status of my item before sendingCommand
I can not do :
if ( contact.state.toString !==“ON” ) { instruction … }
I’m not trying to send a command or change a state … but to read the state of a switch the same way I send the command: I use a variable string which is the name of the String such as: items:
String String1 “[% s]”
sitemap:
sitemap test label = “Test”
{
Text item = String1
}
variable named “Item_Name” which has the value “String1” (the name of the String) and my order =>
Item_Name.sendcommand (“ON”) … this works!
But my problem is that I want to read the state of the switch and I tried the same way: variable named “Item_Name” which has the value “String1” (the name of the String) and my order which is refused =>
From your example, it looked like you were comparing the state of the Item to make sure it was different than the new state that you want to change it to. My previous response covers that. If you just want to get an Item from its name to check its state, then use the post @rossko57 linked to.
(@rossko57, what’s your name… other than rossko57?)