[SOLVED]GPS-Tracker - homestate rule does not work

Hello together,

im trying to get a rule to work, but switching the gpstracker region switch does only update the switch status itself but not the switches and strings i created to detect if anybody ist home.

rule "Home"
when
Item GPSTrackerLars_RegionTrigger received command or
Item GPSTrackerWalli_RegionTrigger received command
then
if (GPSTrackerLars_homeLars == OFF && GPSTrackerWalli_homeWalli == OFF)
{
	homeState_Home.sendCommand(OFF)
}
else if (GPSTrackerLars_homeLars == ON || GPSTrackerWalli_homeWalli == ON)
{
	homeState_Home.sendCommand(ON)
}
end


rule "Home Lars"
when
Item GPSTrackerLars_homeLars received command
then
if (GPSTrackerLars_homeLars == OFF)
{
	homeState_Lars.postUpdate("Unterwegs")
}
else if (GPSTrackerLars_homeLars == ON)
{
	homeState_Lars.postUpdate("Zuhause")
}
end

rule "Home Walli"
when
Item GPSTrackerWalli_homeWalli received command
then
if (GPSTrackerWalli_homeWalli == OFF)
{
	homeState_Walli.postUpdate("Unterwegs")
}
else if (GPSTrackerWalli_homeWalli == ON)
{
	homeState_Walli.postUpdate("Zuhause")
}
end

Items are complex objects with labels, names, types etc.
In a comparison, you are most often interested in its state.

if (GPSTrackerLars_homeLars.state == OFF && ...

Thank you for the hint. It works, but not reliable.

The both switches for GPSTracker_NAME do update itself, but the corresponding homeState_NAME text only every 2nd or 3rd time I switch the state. So sometimes it is updated to “away” when the switch is on for “home” (the corresponding rule is not fired evertime or wrong)

The first rule still doesnt work at all, the switch doesnt turn on or off.

Changed the first rule to:

rule "Home"
when
    Item GPSTrackerLars_RegionTrigger changed or
    Item GPSTrackerWalli_RegionTrigger changed
then
    if (GPSTrackerLars_homeLars.state == OFF && GPSTrackerWalli_homeWalli.state == OFF) {
	homeState_Home.postUpdate(OFF)
    } else if (GPSTrackerLars_homeLars == ON || GPSTrackerWalli_homeWalli == ON) {
	homeState_Home.postUpdate(ON)
    }
end

And the second one:

rule "Home Lars"
when
    Item GPSTrackerLars_homeLars changed
then
    if (GPSTrackerLars_homeLars.state == OFF) {
        homeState_Lars.postUpdate("Unterwegs")
    } else if (GPSTrackerLars_homeLars.state == ON) {
	homeState_Lars.postUpdate("Zuhause")
    }
end

You should be able to figure out the third one by yourself

Ok thank you. So the 2nd and 3rd rule is working now, string updates corresponding to the swith state.

But the first still doesnt work:

Items:

String homeState_Lars "Anwesenheit Lars [%s]"

String homeState_Walli "Anwesenheit Walli [%s]"

Switch homeState_Home "Status Zuhause"

Rule:

when
    Item GPSTrackerLars_RegionTrigger changed or
    Item GPSTrackerWalli_RegionTrigger changed
then
    if (GPSTrackerLars_homeLars.state == OFF && 
        GPSTrackerWalli_homeWalli.state == OFF)
{
	homeState_Home.postUpdate(OFF)
}
else if (GPSTrackerLars_homeLars.state == ON || 
                GPSTrackerWalli_homeWalli.state == ON)
{
	homeState_Home.postUpdate(ON)
}
end

Another question: What is the difference between postUpdate and sendCommand? Especially related to a switch.

Changed the firtst rule to:

rule "Home" 
when
    Item GPSTrackerLars_homeLars changed or
    Item GPSTrackerWalli_homeWalli changed
then
    if (GPSTrackerLars_homeLars.state == OFF && 
GPSTrackerWalli_homeWalli.state == OFF) {
	homeState_Home.postUpdate(OFF)
    } else if (GPSTrackerLars_homeLars == ON || 
GPSTrackerWalli_homeWalli == ON) {
	homeState_Home.postUpdate(ON)
    }
end

Now it works like it should

Yep that makes sense

I assume that homeState_Home is a virtual item. meaning that there is no binding attached to it.
To change the state of that switch a postUpdate is enough. The code is clearer.
the sendCommand is useful with items with a binding. the command will be sent through the binding. The item will not necessarily update it’s state straight away and wait until the binding replies with the new state. (There are ways around this behaviour, look for autoupdate)

Okay, thanks for the explanation!