IFTTT Alarm integration

owning an ismartalarm that have no direct api the only way to set it setup inside openhab is ifttt

i ended up coding the following setup:

items:

    //ALARM
    String Alarm

sitemap

	Frame label="Alarm" {
		Switch item=Alarm label="Alarm" icon="alarm" mappings=["Arm"="Arm", "Disarm"="Disarm", "Home"="Home"]
	}

Basically the alarm have 3 statuses that i replicated in sitemap
i also allowed the Alarm item to be exposed to IFTTT via myopenhab
i also created the 6 actions needed in ifttt (3 that set alarm status from openhab, 3 that write the status to openhab, in case the status is changed from official app or ir command)

The setup work correctly, when i change the status from the openhab app it sends the ifttt command
when i change the status from official app, openhab receive the command (via ifttt)

next i wrote this set of rules to manage the command received from ifttt

rule "Alarm control from IFTTT"
when
	Item Alarm received command
then
	logInfo("alarm.rules", "command received: "+receivedCommand)

	if (receivedCommand.toString == 'Disarm') {
		logInfo("alarm.rules", "Command Disarm, status: "+Alarm.state)
		if (Alarm.state.toString != 'Disarm') {
			Alarm.postUpdate(Disarm)
		}
	}
	else if (receivedCommand.toString == 'Arm') {
		logInfo("alarm.rules", "Command Arm, status: "+Alarm.state)
		if (Alarm.state.toString != 'Disarm') {
			Alarm.postUpdate(Arm)
		}

	}
	else if (receivedCommand.toString == 'Home') {
		logInfo("alarm.rules", "Command Home, status: "+Alarm.state)
		if (Alarm.state.toString != 'Home') {
			Alarm.postUpdate(Home)
		}

	}

end

basically, it updates the status of the switch in openhab and try not to send the command back, but i still have 2 problems:
setting the status from openhab tooks minutes, that could be ok when i arm, but make it totally useless for disarming! inside IFTTT these applet have the following txt “This Applet usually runs within an hour”

if i set the status from the official app, an ifttt applet is triggered, it talks to openhab, openhab update the switch status and trigger the action again sending it back to ifttt and the to the alarm, the alarm set it again to same status and trigger back again to openhab, but this time my rule find that the command update to the current status, so ignore it. anyway it bounce back 2 times at least… any suggestion to improve the code? i just need that the rule get the command and update switch status, without executing any command

thank you

I haven’t used IFTTT since before OH 2.0. but what you need to do is have iftt issue an update, not a command. Otherwise you need to live with this behavior or do something more complex like Design Pattern: Manual Trigger Detection. Pay attention to approach 3.

Thank you for the suggestion, IFTTT seems only able to send command to OpenHab
it seems i can only reduce the number of calls.
Probably i will dig down on the detection of who is instatiating the command

thank you again

Following your suggestion i modified the rule file adding a proxy
now if use openhab to set a status it trigger the ifttt action, if the command is received by ifttt the switch only update its status

this is (part) of the new rule

rule "Alarm control from IFTTT"
when
	Member of AlarmCtrl received command
then
    val source = triggeringItem.name.split("_").get(1)
	logInfo("alarm.rules", "command received: "+receivedCommand+" "+source)

	if (receivedCommand.toString == 'Disarm') {
		logInfo("alarm.rules", "Command Disarm, status: "+Alarm.state+"-"+triggeringItem.name)
		Alarm_Proxy.postUpdate(receivedCommand)
		if (source == 'Proxy') {
			logInfo("alarm.rules", "Execute Proxy")
			sendHttpGetRequest("https://maker.ifttt.com/trigger/alarm_disarm/with/key/XXXXX")
		}

	}
...
end

it seems to work correctly from OpenHab to IFTTT
but the from IFTTT to OpenHab i receive the following error

2018-06-04 10:35:18.378 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Alarm control from IFTTT': 1

Alarm is updated but Alarm_Proxy is not (since it is updated by the rule that is stoppede by the error

ok found it!