<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <article-id pub-id-type="doi">10.1109/MIC.2015.73</article-id>
      <title-group>
        <article-title>Extending Task Automation Systems with Event-State-Condition-Action Capabilities</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Giuseppe Desolda</string-name>
          <email>giuseppe.desolda@uniba.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Francesco Greco</string-name>
          <email>francesco.greco@uniba.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Massimo Zancanaro</string-name>
          <email>massimo.zancanaro@unitn.it</email>
          <xref ref-type="aff" rid="aff1">1</xref>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Maria F. Costabile</string-name>
          <email>maria.costabile@uniba.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Computer Science Department, University of Bari Aldo Moro</institution>
          ,
          <country country="IT">Italy</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Department of Psychology and Cognitive Science, University of Trento</institution>
          ,
          <country country="IT">Italy</country>
        </aff>
        <aff id="aff2">
          <label>2</label>
          <institution>Fondazione Bruno Kessler</institution>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2015</year>
      </pub-date>
      <volume>20</volume>
      <issue>1</issue>
      <fpage>52</fpage>
      <lpage>58</lpage>
      <abstract>
        <p>Trigger-Action programming recently emerged as a paradigm for supporting end-users in defining the behavior of Internet-of-Things devices. It is often implemented by allowing users to define Event-Condition-Action rules visually. The possibility of using either states or events in triggers has already been discussed in the literature and their distinction may be difficult to understand for users. In this paper, we discuss how the definition of Event-State-ConditionAction (ESCA) rules to customize the behavior of IoT devices could be implemented in a Task Automation System (TAS), by adding a lay-er for monitoring events/states.</p>
      </abstract>
      <kwd-group>
        <kwd>1 End-User Development</kwd>
        <kwd>Internet of Things</kwd>
        <kwd>Trigger Action Programming</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>
        Trigger-Action programming (TAP) is emerging as a paradigm for supporting end-users, particularly
those without programming skills, in defining the behavior of Internet-of-Things devices and digital
web services. TAP is a simplified form of the Event Condition Action (ECA), a common approach for
rule-based systems, originally employed to manage databases [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] and control industrial processes [2].
However, when applied in the form of Trigger-Action rules, the Condition part is usually left out for
the sake of simplicity, and the rules take the simple form of “IF &lt;a trigger occurs&gt; THEN &lt;an action
is executed&gt;”.
      </p>
      <p>A source of complexity in the TAP paradigm derives from the fact that triggers can indicate both
instantaneous events or states [3], and users are not always able to understand the difference between
the two [4, 5]. One of the most important causes is the temporal aspect of triggers and actions [4, 5]
since users are often confused when they have to distinguish triggers based on events (i.e., that occur
in a specific moment in time) and states (i.e., that are true over a time span).</p>
    </sec>
    <sec id="sec-2">
      <title>2. A middleware to Monitor Events and States</title>
      <p>Task Automation Systems (TAS) [6] are web-based tools that support users in defining smart objects’
behavior through visual interfaces. Among the most popular ones there are IFTTT [7], Zapier [8], and
EFESTO-5W [9-11]. They typically support users in the definition of the smart object's behavior
through the visual creation of Event-Condition-Action (ECA) rules. From a technical point of view,
one of the most critical aspects of TASs is trigger monitoring. Let us consider the following ECA rule:</p>
      <p>IF the alarm is turned on</p>
      <p>THEN switch off all the lights</p>
      <p>Two main solutions are currently adopted by TASs to monitor the triggering events, and this depends
on the technology implemented by the smart devices. The simplest and less effective solution consists
of periodically invoking the smart object’s API related to the triggering event. Considering the previous
rule, a TAS must invoke the API of the alarm to check if it is turned on. This is a low-effective solution
because of the overloading of connection and the overusing of device energy. A more efficient and
effective solution is the use of a Publish-Subscribe architecture, such as the MQTT protocol. In this
architecture, there are three main actors, i.e., the publisher, the subscribers, and the broker. The
publisher is an entity, a smart object in our case, that sends a message to other subscribed entities. The
subscriber is an entity, a TAS in our scenario, that receives the messages from the publisher. The broker
is a virtual component hosted on a web server that implements the publish/subscribe mechanism: the
publisher notifies the broker only when an event occurs (e.g., the alarm is turned on) and the subscribers
are notified by the broker only when the event is triggered. An advantage of this architecture is that
several entities can subscribe to the same publisher, in our case several rules can subscribe to the same
event without overloading the smart object.
2.1.</p>
    </sec>
    <sec id="sec-3">
      <title>Generate states of a smart object starting from its events</title>
      <p>The majority of the smart objects expose sensors data to third party-applications as (instantaneous)
events. In order to allow TASs to monitor the states of those smart objects exposing only events, the
proposed solution is to create a middleware in the TAS rule engine where, for each smart object, the
internal representation of the device is extended to generate states starting from its events. As reported
in the following code, the first time a smart object is connected with the TAS, there is an initialization
phase: for each event i, its API is invoked and the variable statei is set according to a mapping between
the event values and the state values, previously defined by the TAS administrator. For example, in the
device Smart light, the API of the event “Is turned on” can return two values, i.e., true or false; these
values are mapped in the values “Is on” and “Is off” that can be associated with the variable state.</p>
      <p>Then, every n seconds, the event value is read through the API and the state variable is updated if
differs from the previous value. The device states are made available to the TAS through MQTT APIs
automatically generated so that, if the state value changes, all the subscribers are notified.
Initialization:</p>
      <p>Var statei = map(eventi)
loop:
if (map(eventi) != statei) then:</p>
      <p>statei = map(eventi);
endif;
endloop;</p>
    </sec>
    <sec id="sec-4">
      <title>Generate the events of a smart object from its states</title>
      <p>Although most of the smart objects expose their sensor data as events, in some cases, smart objects
could provide API for monitoring only their states. Similar to the solution presented in the previous
section, in the middleware the internal representation of the smart objects must be extended to provide
its states as events. In this case, to generate the eventi starting from the statei, a specific component in
the middleware has to continuously query the API of statei and, if the state value is changed with respect
to the last query, the eventi is triggered. For example, in the smart device Thermostat, the state
“Temperature hot” would be associated with the event “Temperature goes above 25°C”; if the state
changes from False to True (e.g., if the temperature goes from 24°C to 26°C), then the event is triggered.
This behavior is summarized more formally in the following pseudocode:</p>
      <p>Initialization:</p>
      <p>Var eventi = map(statei)
loop:
new_statei = API_state(i)
if (statei != new_statei) then:
trigger(eventi);</p>
      <p>statei &lt;- new_statei;
endif;
endloop;</p>
    </sec>
    <sec id="sec-5">
      <title>3. Conclusions</title>
      <p>In this position paper, it has been proposed an approach to enrich a TAP architecture with coordinated
states and events for a more expressive definition of ECA rules. The main goal is to inform designers
and developers of TASs of the possibilities offered by the Event-State-Condition-Action paradigm and
on the possible technical solutions to implement it in their TAS.</p>
    </sec>
    <sec id="sec-6">
      <title>Acknowledgements References</title>
      <p>This work is partially supported by the Italian Ministry of University and Research (MIUR) under
grant PRIN 2017 “EMPATHY: EMpowering People in deAling with internet of THings ecosYstems.”.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>G.</given-names>
            <surname>Ghiani</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Manca</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Paternò</surname>
          </string-name>
          , and
          <string-name>
            <given-names>C.</given-names>
            <surname>Santoro</surname>
          </string-name>
          ,
          <article-title>"Personalization of Context-Dependent Applications Through Trigger-Action Rules," ACM Transaction on Computer-Human Interaction</article-title>
          , vol.
          <volume>24</volume>
          , no.
          <issue>2</issue>
          , p.
          <volume>33</volume>
          <fpage>pages</fpage>
          ,
          <year>2017</year>
          , Art no.
          <source>Article</source>
          <volume>14</volume>
          (
          <year>April 2017</year>
          ), doi: 10.1145/3057861.
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          <string-name>
            <given-names>B.</given-names>
            <surname>Joonsoo</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Hyerim</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Suk-Ho</surname>
          </string-name>
          , and
          <string-name>
            <given-names>K.</given-names>
            <surname>Yeongho</surname>
          </string-name>
          ,
          <article-title>"Automatic control of workflow processes using ECA rules,"</article-title>
          <source>IEEE Transactions on Knowledge and Data Engineering</source>
          , vol.
          <volume>16</volume>
          , no.
          <issue>8</issue>
          , pp.
          <fpage>1010</fpage>
          -
          <lpage>1023</lpage>
          ,
          <year>2004</year>
          , doi: 10.1109/TKDE.
          <year>2004</year>
          .
          <volume>20</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          <string-name>
            <given-names>W.</given-names>
            <surname>Brackenbury</surname>
          </string-name>
          et al.,
          <article-title>"How Users Interpret Bugs in Trigger-Action Programming," in Human Factors in Computing Systems</article-title>
          , Glasgow, Scotland Uk,
          <year>2019</year>
          :
          <article-title>Association for Computing Machinery</article-title>
          , p.
          <source>Paper</source>
          <volume>552</volume>
          , doi: 10.1145/3290605.3300782. [Online]. Available: https://doi.org/10.1145/3290605.3300782
          <string-name>
            <given-names>B.</given-names>
            <surname>Ur</surname>
          </string-name>
          et al.,
          <article-title>"Trigger-Action Programming in the Wild: An Analysis of 200,000 IFTTT Recipes,"</article-title>
          <source>in SIGCHI Conference on Human Factors in Computing Systems</source>
          , San Jose, California, USA,
          <year>2016</year>
          , New York, NY, USA: ACM, pp.
          <fpage>3227</fpage>
          -
          <lpage>3231</lpage>
          , doi: 10.1145/2858036.2858556.
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>