Simple rule help

Gday,

I am having a go at putting some rules in place for a simple home alarm that will have switch type inputs and a switch output for a siren along with a bunch of notifications.

I have set up all the items as switches and have this in the sitemap, to switch off, on(window, door & PIR) and internal (just window & door reed switches) modes.

Switch item=Alarmmode label="Alarm mode selection" mappings=[1=OFF, 2=ON, 3=Internal] icon="settings"

The first rule works well and changes state of the 3 switches. The second rule “Alarm triggers” does not seem to work.
Could someone point me in the right direction?

//Alarm Rules

rule "Alarm Mode"
when
	Item Alarmmode received command
then
	if(receivedCommand==1) {
		sendCommand(AlarmOFF, ON)
		sendCommand(AlarmON, OFF)
		sendCommand(Alarminternal, OFF)
		} 
	else
		if(receivedCommand==2) {
		sendCommand(AlarmOFF, OFF)
		sendCommand(AlarmON, ON)
		sendCommand(Alarminternal, OFF)
		}
	else
		if(receivedCommand==3) {
		sendCommand(AlarmOFF, OFF)
		sendCommand(AlarmON, OFF)
		sendCommand(Alarminternal, ON)
		} 
end

rule "Alarm triggers" 
when
	Item AlarmON received command ON
then
	if(Windows==ON) {
		sendCommand(Alarmtriggered, ON)
		}
	if(Doors==ON) {
		sendCommand(Alarmtriggered, ON)
		}	 
	if(PIR1==ON) {
		sendCommand(Alarmtriggered, ON)
		}	
end

Kind Regards,
George

Hi George,

I assume that Windows, Doors and PIR are items. If so, the right syntax is:

if (Windows.state==ON) { // Do something }

You missed the .state

Thomas

Thomas,

Thanks for that, much appreciated. I am still quite new to rules.

Do you know if there is summary sheet or similar on the syntax for the most common type of things in rules?

Cheers,
George

George,

i don’t think so, just use the Wiki with the examples and ask if you do not find a solution.

Thomas

The closest you will get to a summary is the Rules wiki page. For more in depth stuff you can read the Xtend language docs (linked to on the Rules page). But as @Dibbler42 says, examples will be a large part of your learning.

No worries, thanks for that.

Cheers,
George

hi george , did you ever finish your alarm ?
if so , i think this can be a very intresting project as i have not seen many rules about that topic yet.
would you be so kind to a post about your working configuration ?

kindest regards