[SOLVED] Help with simple rule If logic


Maybe its late, but I keep looking at this and its still confusing me.

Take this rule

rule "Google Home Notification Play Sound"
	Item GH_Notifications_AudioFile received command
	if (Presence.state == ON && (vTimeOfDay.state != "RELAX" || vTimeOfDay.state != "BED"))
		playSound("chromecast:audiogroup:ab6e4b10-3831-4914-86c5-4a9b84a44144", receivedCommand.toString())

Presence is currently ON
vTimeOfDay is currently BED

Can anyone tell me why the code inside the “if” is still running? The idea is I dont get notifications when we are winding down for bed and during sleep.


Because (vTimeOfDay.state != "RELAX" || vTimeOfDay.state != "BED") evaluates to True if vTimeOfDay is "BED" because that means vTimeOfDay is not "RELAX".
|| is OR.

Try this:

if (Presence.state == ON && vTimeOfDay.state != "RELAX" && vTimeOfDay.state != "BED")
1 Like

Thanks, I knew it was something with the logic, but you know when you stare at some thing too long.

This has been bugging me for a while.

Because it just occurred to me, I think what you thought you had was more like this (which will also work):

if (Presence.state == ON && !(vTimeOfDay.state == "RELAX" || vTimeOfDay.state == "BED"))

In words that is:
if Presence is ON and not ( TimeOfDay is "RELAX" or TimeOfDay is "BED" ) then

Ahh ok, that might actually read better. I’ll have a look at changing it.

Thank you :slight_smile: