Temporized rule

good morning, I have a problem with this rule. I have two routines: entry and exit. With the gptracker binding I would like it to activate the “entry” rule when I am close to home. I use the “distance” channel for the position and the “region” channel as the flag. The problem is that in the exit phase, I should time the rule to give you time to “exit” from region and distance, otherwise it reactivates “entry” for me. I attach the code, thanks for the suggestions.
I forgot… the radius is 10

configuration: {}
triggers:
  - id: "1"
    configuration:
      itemName: Tracker_Device_System_Distance
    type: core.ItemStateChangeTrigger
conditions: []
actions:
  - inputs: {}
    id: "3"
    configuration:
      blockSource: <xml xmlns="https://developers.google.com/blockly/xml"><block
        type="oh_log" id="*Xrd#%3svH^4y6m.Ik#b" x="328" y="179"><field
        name="severity">info</field><value name="message"><shadow type="text"
        id="FQCl`15FD#D3gV]tNtSG"><field name="TEXT">abc</field></shadow><block
        type="oh_getitem_state" id="iizx-/C=y!hbk==KxRq5"><value
        name="itemName"><shadow type="oh_item"
        id="[G.t%ieECVaH)vDM`o08"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id=";I(z?%hy?PBGYXHX*OlI"><mutation
        itemName="Tracker_Device_Region_Trigger" itemLabel="Region
        Trigger"></mutation><field
        name="itemName">Tracker_Device_Region_Trigger</field></block></value></block></value><next><block
        type="oh_log" id="Ole3*._aF%4rc5)5xbb2"><field
        name="severity">info</field><value name="message"><shadow type="text"
        id=".}tcn)wsC$2}Dt`r[478"><field name="TEXT">abc</field></shadow><block
        type="oh_getitem_state" id="4x]8_;YyE4N_R.um]gp9"><value
        name="itemName"><shadow type="oh_item"
        id="[#!@og__`[7N]h?b.Jyf"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="fq+)ZtNKQ@|C3U0l1+R7"><mutation
        itemName="Tracker_Device_System_Distance" itemLabel="System
        Distance"></mutation><field
        name="itemName">Tracker_Device_System_Distance</field></block></value></block></value><next><block
        type="controls_if" id="D2`K:maRqe1|82z%Jjsr"><mutation
        elseif="1"></mutation><value name="IF0"><block type="logic_compare"
        id="iJeiAxe][uaB)m+wQraf"><field name="OP">LT</field><value
        name="A"><block type="oh_getitem_state" id="dQivryc|mK1L@kX*Ik?4"><value
        name="itemName"><shadow type="oh_item"
        id="R)sApZr!u2.S.]ILtYx+"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="UT9B.2AWUpe;N3PDmI.h"><mutation
        itemName="Tracker_Device_System_Distance" itemLabel="System
        Distance"></mutation><field
        name="itemName">Tracker_Device_System_Distance</field></block></value></block></value><value
        name="B"><block type="text" id="iX8/3w^ieG9TKo]+NA8="><field
        name="TEXT">15.0</field></block></value></block></value><value
        name="IF1"><block type="logic_compare" id="t0)ypc(`t[I}^TKF?q95"><field
        name="OP">EQ</field><value name="A"><block type="oh_getitem_state"
        id="/3;WF`^feK8:am57T,{W"><value name="itemName"><shadow type="oh_item"
        id="Ci2*%kv,7$d5.P1%W2pj"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="}$uz{Ek4^ehpjTFl9qxn"><mutation
        itemName="Tracker_Device_Region_Trigger" itemLabel="Region
        Trigger"></mutation><field
        name="itemName">Tracker_Device_Region_Trigger</field></block></value></block></value><value
        name="B"><block type="text" id="?Z=t3`nU*^D(C(ExLlCt"><field
        name="TEXT">OFF</field></block></value></block></value><statement
        name="DO1"><block type="oh_event" id="p{i`g^VnX]pp%yY1Iplx"><field
        name="eventType">sendCommand</field><value name="value"><shadow
        type="text" id="pYQ(s9cYCLH%JOp=x/QI"><field
        name="TEXT">value</field></shadow><block type="text"
        id="f)2bV$sl?ZEOl.g!|9M,"><field
        name="TEXT">ON</field></block></value><value name="itemName"><shadow
        type="oh_item" id=".IF^:Rmt,.DE^K[u7}VK"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="*ZgY%IP~NDk*NjUu.oNw"><mutation itemName="routine_entrata"
        itemLabel="routine entrata"></mutation><field
        name="itemName">routine_entrata</field></block></value></block></statement></block></next></block></next></block></xml>
      type: application/javascript
      script: >
        console.info(items.getItem('Tracker_Device_Region_Trigger').state);

        console.info(items.getItem('Tracker_Device_System_Distance').state);

        if (items.getItem('Tracker_Device_System_Distance').state < '15.0') {

        } else if (items.getItem('Tracker_Device_Region_Trigger').state == 'OFF') {
          items.getItem('routine_entrata').sendCommand('ON');
        }
    type: script.ScriptAction

If I understand the problem correctly there are two potential approaches you can use:

  1. Set a timer before updating the Item to indicated exit. If the location changes and you are back inside the geofence cancel the timer. So it will only update the exit Item when you have been outside of the geofence for a given amount of time.

  2. Set a hysteresis. For example, set enter at 10 but set exit to 12.

Looking at your code it doesn’t make much sense. Can you post the blocks?

You have an if state to check the distance is < 15 but then you don’t do anything and jump straight to the else if.

It’s also comparing Strings, and not Numbers so, for example which can lead to wrong answers. For example “10” < “2”. You need to be getting the numberic state of the Item (the get [name] from item block) and comparing to a number (in the Math category of blocks).

Do you mean AND here?

Right now what your code does, in English.

  1. log the state of trigger
  2. log the state of distance
  3. if the distance is less than the string “15”
    a. do nothing
  4. else if trigger is OFF
    a. command enteata to ON

At the very least that’s an odd formulation, why have an if that doesn’t do anything?

Do you mean “if the distance is less than the number 15 AND trigger is OFF then command enteata to ON”?

Exactly. I put a shared timer on the “Exit” rule
and I rewrote the rule like this:

After a lot of test, i become to a Simply rule, with a region trigger. And now it’s work …for my use, i Hope :sweat_smile:… thanks for your help