Switch Rules

Hi All,

I currently have the following rule running to determine when I am home or at work.

rule "Home Transform" 
when
Item NathanHome received update
then
if (NathanHome.state == ON){
NathanHomeTransformed.postUpdate("Nathan is Home")
}
else{
NathanHomeTransformed.postUpdate("Nathan is Out")
}
end

rule "Work Transform" 
when 
Item NathanWork received update 
then 
if (NathanWork.state == ON){ 
NathanWorkTransformed.postUpdate("Nathan is at Work")
}
else{ NathanWorkTransformed.postUpdate("Nathan is not at Work")
}
end

What I would like to do is combine the 2 rules so that I get the following outputs on one central item.

Either Nathan is home, At work, Out.

I’ve tried a few different ways but cannot get the desired output.

Thanks

Assuming you want to display all those three states using item NathanHomeTransformed I’d do it like that:

rule "Home-Work Transform"
when
Item NathanHome received update or NathanWork received update
then
if (NathanHome.state == ON){
NathanHomeTransformed.postUpdate(“Nathan is Home”)
}
else{
if (NathanWork.state == ON){
NathanHomeTransformed.postUpdate(“Nathan is at Work”)
}
else{ NathanHomeTransformed.postUpdate(“Nathan is Out”)
}
}
end

1 Like

Implemented and tested!

Works perfectly!

Thank You!