<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Unable to catch status variable in a script]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I'm quite new to MyController, and I'm starting working with scripts.</p>
<p dir="auto">I've got 5 status variables.<br />
The first 3 represent PIRs status, and I can work with them as expected.<br />
The last 2 represent a relays status, but every test I do with their value seems to  be false.</p>
<p dir="auto">This is the script I'm using:</p>
<pre><code>var myImports = new JavaImporter(java.io, java.lang, java.util);

with(myImports) {

var PIR_C = mcApi.uidTag().getByUid("P0_PIR_Caldaia").getResource();
var PIR_F = mcApi.uidTag().getByUid("P0_PIR_Finestra").getResource();
var PIR_S = mcApi.uidTag().getByUid("P0_PIR_Studio").getResource();

var Consenso = mcApi.uidTag().getByUid("P0_Consenso_Caldaia").getResource();
var Consenso_C = mcApi.uidTag().getByUid("P0_Consenso_Check").getResource();

var PIR = (PIR_C.value == "0" &amp;&amp; PIR_F.value == "0" &amp;&amp; PIR_S.value == "0");
var Caldaia = (Consenso == "1" || Consenso_C == "1");

mcResult = (PIR &amp;&amp; Caldaia);

}
</code></pre>
<p dir="auto">and this is the result:</p>
<pre><code>{
  "PIR_C": {
    "id": 8,
    "sensor": {
      "id": 9,
      "sensorId": "1",
      "type": "S_BINARY",
      "name": "PIR Caldaia",
      "lastSeen": 1513095387214,
      "node": {
        "id": 8,
        "eui": "1",
        "gatewayTable": {
          "id": 1,
          "enabled": true,
          "name": "MQTT_Gateway",
          "networkType": "MY_SENSORS",
          "state": "UP",
          "statusMessage": "Connected Successfully",
          "statusSince": 1513073882255,
          "type": "MQTT",
          "properties": {
            "p": "",
            "qos": 0,
            "u": "",
            "bh": "tcp://localhost:1883",
            "txDelay": 0,
            "tp": "casa_in",
            "cid": "mygateway1",
            "ts": "casa_out"
          }
        },
        "name": "P0 - PIR Caldaia",
        "version": "1.1",
        "type": "S_ARDUINO_REPEATER_NODE",
        "libVersion": "2.1.1",
        "state": "UP",
        "lastSeen": 1513095504118,
        "properties": {
          "hbTx": 1513095493224
        },
        "parentNodeEui": "0",
        "registrationState": "REGISTERED",
        "smartSleepEnabled": false
      },
      "room": {
        "id": 1,
        "name": "Sala Giochi",
        "fullPath": "Sala Giochi"
      },
      "variableTypes": [
        "Status"
      ],
      "idforVariables": 9
    },
    "variableType": "V_STATUS",
    "metricType": "BINARY",
    "timestamp": 1513095387161,
    "value": "0",
    "previousValue": "0",
    "unitType": "U_NONE",
    "readOnly": false,
    "offset": 0,
    "priority": 100,
    "properties": {
      "marginRight": 20,
      "color": "#ff7f0e",
      "interpolate": "linear",
      "subType": "line",
      "marginBottom": 60,
      "useGlobal": true,
      "type": "lineChart",
      "marginTop": 5,
      "marginLeft": 65
    },
    "metricsGraph": {
      "id": 18,
      "metricName": "Status",
      "type": "lineChart",
      "interpolate": "step-after",
      "subType": "line",
      "color": "#ff7f0e"
    }
  },
  "PIR_S": {
    "id": 1,
    "sensor": {
      "id": 1,
      "sensorId": "1",
      "type": "S_BINARY",
      "name": "PIR Studio",
      "lastSeen": 1513095306409,
      "node": {
        "id": 2,
        "eui": "3",
        "gatewayTable": {
          "id": 1,
          "enabled": true,
          "name": "MQTT_Gateway",
          "networkType": "MY_SENSORS",
          "state": "UP",
          "statusMessage": "Connected Successfully",
          "statusSince": 1513073882255,
          "type": "MQTT",
          "properties": {
            "p": "",
            "qos": 0,
            "u": "",
            "bh": "tcp://localhost:1883",
            "txDelay": 0,
            "tp": "casa_in",
            "cid": "mygateway1",
            "ts": "casa_out"
          }
        },
        "name": "P0 - PIR Studio",
        "version": "1.1",
        "type": "S_ARDUINO_NODE",
        "libVersion": "2.1.1",
        "state": "UP",
        "lastSeen": 1513095503748,
        "properties": {
          "hbTx": 1513095493224
        },
        "parentNodeEui": "0",
        "registrationState": "REGISTERED",
        "smartSleepEnabled": true
      },
      "room": {
        "id": 2,
        "name": "Studio",
        "fullPath": "Studio"
      },
      "variableTypes": [
        "Status"
      ],
      "idforVariables": 1
    },
    "variableType": "V_STATUS",
    "metricType": "BINARY",
    "timestamp": 1513095306351,
    "value": "0",
    "previousValue": "0",
    "unitType": "U_NONE",
    "readOnly": false,
    "offset": 0,
    "priority": 100,
    "properties": {
      "marginRight": 20,
      "color": "#ff7f0e",
      "interpolate": "linear",
      "subType": "line",
      "marginBottom": 60,
      "useGlobal": true,
      "type": "lineChart",
      "marginTop": 5,
      "marginLeft": 65
    },
    "metricsGraph": {
      "id": 18,
      "metricName": "Status",
      "type": "lineChart",
      "interpolate": "step-after",
      "subType": "line",
      "color": "#ff7f0e"
    }
  },
  "myImports": {},
  "PIR": true,
  "mcResult": false,
  "PIR_F": {
    "id": 3,
    "sensor": {
      "id": 6,
      "sensorId": "1",
      "type": "S_BINARY",
      "name": "PIR Finestra",
      "lastSeen": 1513095507060,
      "node": {
        "id": 6,
        "eui": "2",
        "gatewayTable": {
          "id": 1,
          "enabled": true,
          "name": "MQTT_Gateway",
          "networkType": "MY_SENSORS",
          "state": "UP",
          "statusMessage": "Connected Successfully",
          "statusSince": 1513073882255,
          "type": "MQTT",
          "properties": {
            "p": "",
            "qos": 0,
            "u": "",
            "bh": "tcp://localhost:1883",
            "txDelay": 0,
            "tp": "casa_in",
            "cid": "mygateway1",
            "ts": "casa_out"
          }
        },
        "name": "P0 - PIR Finestra",
        "version": "1.1",
        "type": "S_ARDUINO_NODE",
        "libVersion": "2.1.1",
        "state": "UP",
        "lastSeen": 1513095507080,
        "properties": {
          "hbTx": 1513095493224
        },
        "parentNodeEui": "1",
        "registrationState": "REGISTERED",
        "smartSleepEnabled": true
      },
      "room": {
        "id": 1,
        "name": "Sala Giochi",
        "fullPath": "Sala Giochi"
      },
      "variableTypes": [
        "Status"
      ],
      "idforVariables": 6
    },
    "variableType": "V_STATUS",
    "metricType": "BINARY",
    "timestamp": 1513095507017,
    "value": "0",
    "previousValue": "0",
    "unitType": "U_NONE",
    "readOnly": false,
    "offset": 0,
    "priority": 100,
    "properties": {
      "marginRight": 20,
      "color": "#ff7f0e",
      "interpolate": "linear",
      "subType": "line",
      "marginBottom": 60,
      "useGlobal": true,
      "type": "lineChart",
      "marginTop": 5,
      "marginLeft": 65
    },
    "metricsGraph": {
      "id": 18,
      "metricName": "Status",
      "type": "lineChart",
      "interpolate": "step-after",
      "subType": "line",
      "color": "#ff7f0e"
    }
  },
  "Consenso_C": {
    "id": 19,
    "sensor": {
      "id": 21,
      "sensorId": "3",
      "type": "S_BINARY",
      "name": "Consenso Check",
      "lastSeen": 1513095510243,
      "node": {
        "id": 8,
        "eui": "1",
        "gatewayTable": {
          "id": 1,
          "enabled": true,
          "name": "MQTT_Gateway",
          "networkType": "MY_SENSORS",
          "state": "UP",
          "statusMessage": "Connected Successfully",
          "statusSince": 1513073882255,
          "type": "MQTT",
          "properties": {
            "p": "",
            "qos": 0,
            "u": "",
            "bh": "tcp://localhost:1883",
            "txDelay": 0,
            "tp": "casa_in",
            "cid": "mygateway1",
            "ts": "casa_out"
          }
        },
        "name": "P0 - PIR Caldaia",
        "version": "1.1",
        "type": "S_ARDUINO_REPEATER_NODE",
        "libVersion": "2.1.1",
        "state": "UP",
        "lastSeen": 1513095504118,
        "properties": {
          "hbTx": 1513095493224
        },
        "parentNodeEui": "0",
        "registrationState": "REGISTERED",
        "smartSleepEnabled": false
      },
      "room": {
        "id": 1,
        "name": "Sala Giochi",
        "fullPath": "Sala Giochi"
      },
      "variableTypes": [
        "Status"
      ],
      "idforVariables": 21
    },
    "variableType": "V_STATUS",
    "metricType": "BINARY",
    "timestamp": 1513095510222,
    "value": "1",
    "previousValue": "0",
    "unitType": "U_NONE",
    "readOnly": false,
    "offset": 0,
    "priority": 100,
    "properties": {
      "marginRight": 20,
      "color": "#ff7f0e",
      "interpolate": "linear",
      "subType": "line",
      "marginBottom": 60,
      "useGlobal": true,
      "type": "lineChart",
      "marginTop": 5,
      "marginLeft": 65
    },
    "metricsGraph": {
      "id": 18,
      "metricName": "Status",
      "type": "lineChart",
      "interpolate": "step-after",
      "subType": "line",
      "color": "#ff7f0e"
    }
  },
  "Caldaia": false,
  "Consenso": {
    "id": 9,
    "sensor": {
      "id": 10,
      "sensorId": "2",
      "type": "S_BINARY",
      "name": "Consenso Caldaia",
      "lastSeen": 1513094395195,
      "node": {
        "id": 8,
        "eui": "1",
        "gatewayTable": {
          "id": 1,
          "enabled": true,
          "name": "MQTT_Gateway",
          "networkType": "MY_SENSORS",
          "state": "UP",
          "statusMessage": "Connected Successfully",
          "statusSince": 1513073882255,
          "type": "MQTT",
          "properties": {
            "p": "",
            "qos": 0,
            "u": "",
            "bh": "tcp://localhost:1883",
            "txDelay": 0,
            "tp": "casa_in",
            "cid": "mygateway1",
            "ts": "casa_out"
          }
        },
        "name": "P0 - PIR Caldaia",
        "version": "1.1",
        "type": "S_ARDUINO_REPEATER_NODE",
        "libVersion": "2.1.1",
        "state": "UP",
        "lastSeen": 1513095504118,
        "properties": {
          "hbTx": 1513095493224
        },
        "parentNodeEui": "0",
        "registrationState": "REGISTERED",
        "smartSleepEnabled": false
      },
      "room": {
        "id": 1,
        "name": "Sala Giochi",
        "fullPath": "Sala Giochi"
      },
      "variableTypes": [
        "Status"
      ],
      "idforVariables": 10
    },
    "variableType": "V_STATUS",
    "metricType": "BINARY",
    "timestamp": 1513094395164,
    "value": "0",
    "previousValue": "1",
    "unitType": "U_NONE",
    "readOnly": false,
    "offset": 0,
    "priority": 100,
    "properties": {
      "marginRight": 20,
      "color": "#ff7f0e",
      "interpolate": "linear",
      "subType": "line",
      "marginBottom": 60,
      "useGlobal": true,
      "type": "lineChart",
      "marginTop": 5,
      "marginLeft": 65
    },
    "metricsGraph": {
      "id": 18,
      "metricName": "Status",
      "type": "lineChart",
      "interpolate": "step-after",
      "subType": "line",
      "color": "#ff7f0e"
    }
  }
}
</code></pre>
<p dir="auto">As you can see, Consenso_C value is 1 in the output, but the test Consenso_C == "1" is false.</p>
<p dir="auto">It's surely some stupid error, but I cannot see where it is...</p>
<p dir="auto">Daniele</p>
]]></description><link>http://forum.mycontroller.org/topic/240/unable-to-catch-status-variable-in-a-script</link><generator>RSS for Node</generator><lastBuildDate>Wed, 11 Nov 2026 22:31:01 GMT</lastBuildDate><atom:link href="http://forum.mycontroller.org/topic/240.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 12 Dec 2017 16:33:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unable to catch status variable in a script on Wed, 13 Dec 2017 13:12:34 GMT]]></title><description><![CDATA[<p dir="auto">What a stupid error!<br />
Thank  you very much!</p>
]]></description><link>http://forum.mycontroller.org/post/1450</link><guid isPermaLink="true">http://forum.mycontroller.org/post/1450</guid><dc:creator><![CDATA[Daniele]]></dc:creator><pubDate>Wed, 13 Dec 2017 13:12:34 GMT</pubDate></item><item><title><![CDATA[Reply to Unable to catch status variable in a script on Wed, 13 Dec 2017 02:43:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/daniele" aria-label="Profile: daniele">@<bdi>daniele</bdi></a></p>
<p dir="auto">this line[<code>var Caldaia = (Consenso == "1" || Consenso_C == "1");</code>] should be as follows,</p>
<pre><code>var Caldaia = (Consenso.value == "1" || Consenso_C.value == "1");
</code></pre>
]]></description><link>http://forum.mycontroller.org/post/1449</link><guid isPermaLink="true">http://forum.mycontroller.org/post/1449</guid><dc:creator><![CDATA[jkandasa]]></dc:creator><pubDate>Wed, 13 Dec 2017 02:43:56 GMT</pubDate></item></channel></rss>