<?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[Scripts]]></title><description><![CDATA[Scripts]]></description><link>http://forum.mycontroller.org/category/24</link><generator>RSS for Node</generator><lastBuildDate>Wed, 11 Nov 2026 22:14:00 GMT</lastBuildDate><atom:link href="http://forum.mycontroller.org/category/24.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 28 May 2020 21:32:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[NODEMANAGER OTA CONFIGURATION per java script]]></title><description><![CDATA[@jkandasa Thanks a lot for the example. The delay doesn't matter. I had already found a solution. But I didn't think this was good enough to publish. I take advantage of the fact that the mysensors nodes do not necessarily need a request message for the Ota function. So I got along with mcApi.sensor (). SendPayload ().
When I have time again I'll try your better solution.
]]></description><link>http://forum.mycontroller.org/topic/462/nodemanager-ota-configuration-per-java-script</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/462/nodemanager-ota-configuration-per-java-script</guid><dc:creator><![CDATA[TRex-600]]></dc:creator><pubDate>Thu, 28 May 2020 21:32:15 GMT</pubDate></item><item><title><![CDATA[How to play an mp3 file on condition?]]></title><description><![CDATA[@skywatch You can follow this example
]]></description><link>http://forum.mycontroller.org/topic/458/how-to-play-an-mp3-file-on-condition</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/458/how-to-play-an-mp3-file-on-condition</guid><dc:creator><![CDATA[jkandasa]]></dc:creator><pubDate>Sat, 11 Apr 2020 11:12:07 GMT</pubDate></item><item><title><![CDATA[How to open a webpage &#x2F; place a http request?]]></title><description><![CDATA[Thanks very much for your reply with the streamlined version!
To be honest, I now had to settle for calling the actions like this
var command="echo 'b8:27:eb:b7:29:4a mixer volume -2' | nc -q0 192.168.1.2 9090"
mcApi.osCommandExecuter().executeLinuxCommand(command);

Meaning, the command get's "netcat'ed" to the server - is there just by chance a comparable API call as well?
Thanks again very much for your work,
Joost
]]></description><link>http://forum.mycontroller.org/topic/454/how-to-open-a-webpage-place-a-http-request</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/454/how-to-open-a-webpage-place-a-http-request</guid><dc:creator><![CDATA[Joost]]></dc:creator><pubDate>Fri, 27 Mar 2020 08:51:02 GMT</pubDate></item><item><title><![CDATA[How to delete a sensor variable from script]]></title><description><![CDATA[@fsgrazzutti Currently I am actively working in V2.
I will have a look in to this soon and update you
]]></description><link>http://forum.mycontroller.org/topic/361/how-to-delete-a-sensor-variable-from-script</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/361/how-to-delete-a-sensor-variable-from-script</guid><dc:creator><![CDATA[jkandasa]]></dc:creator><pubDate>Tue, 16 Oct 2018 11:36:16 GMT</pubDate></item><item><title><![CDATA[Script Pause Keywords]]></title><description><![CDATA[@faelanstevie I guess this is irrelevant to MyController scripts
]]></description><link>http://forum.mycontroller.org/topic/276/script-pause-keywords</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/276/script-pause-keywords</guid><dc:creator><![CDATA[jkandasa]]></dc:creator><pubDate>Wed, 21 Mar 2018 11:05:20 GMT</pubDate></item><item><title><![CDATA[Using Automation Server]]></title><description><![CDATA[@faelanstevie Is the question related to MyController.org server?
]]></description><link>http://forum.mycontroller.org/topic/264/using-automation-server</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/264/using-automation-server</guid><dc:creator><![CDATA[jkandasa]]></dc:creator><pubDate>Wed, 07 Feb 2018 12:04:42 GMT</pubDate></item><item><title><![CDATA[Simple custom button]]></title><description><![CDATA[@jkandasa Thanks for the tip. I'm not familiar with AngularJS. I will try to learn a bit about this and make something!
]]></description><link>http://forum.mycontroller.org/topic/235/simple-custom-button</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/235/simple-custom-button</guid><dc:creator><![CDATA[heyjay]]></dc:creator><pubDate>Wed, 29 Nov 2017 21:43:25 GMT</pubDate></item><item><title><![CDATA[Location Name]]></title><description><![CDATA[@naguraob Sure, I will fix this. Kindly create an issue to track this. So that I won't forget 
]]></description><link>http://forum.mycontroller.org/topic/196/location-name</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/196/location-name</guid><dc:creator><![CDATA[jkandasa]]></dc:creator><pubDate>Tue, 19 Sep 2017 17:28:29 GMT</pubDate></item><item><title><![CDATA[Custom Output to display]]></title><description><![CDATA[Thank you thank you!
you are the best!
]]></description><link>http://forum.mycontroller.org/topic/165/custom-output-to-display</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/165/custom-output-to-display</guid><dc:creator><![CDATA[Darvos]]></dc:creator><pubDate>Fri, 02 Jun 2017 04:57:32 GMT</pubDate></item><item><title><![CDATA[Display text based on sensor value, is that possible?]]></title><description><![CDATA[@jkandasa
Just tested and it works like a charm!!!
Really great examples, that are easy to implement.
Mycontroller was already great, now it is even better!!.
Thank you!!
]]></description><link>http://forum.mycontroller.org/topic/124/display-text-based-on-sensor-value-is-that-possible</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/124/display-text-based-on-sensor-value-is-that-possible</guid><dc:creator><![CDATA[Tag]]></dc:creator><pubDate>Fri, 24 Feb 2017 07:24:04 GMT</pubDate></item><item><title><![CDATA[AC&#x2F;Heatpump control]]></title><description><![CDATA[Hi @jkandasa
Sorry for not posting the feedback yet...
But yes - It works like a charm. And the timestamp solution seems to do what its supposed to 
]]></description><link>http://forum.mycontroller.org/topic/99/ac-heatpump-control</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/99/ac-heatpump-control</guid><dc:creator><![CDATA[ksga]]></dc:creator><pubDate>Sun, 01 Jan 2017 17:11:48 GMT</pubDate></item><item><title><![CDATA[Sunrize sunset forward]]></title><description><![CDATA[@adulovic
Hi,
As jkandasa said, you should probably download the last SNAPSHOT version again. Your error message seems to be because you don't have the SNAPSHOT with his modification.
As for the step-by-step i can try to explain the way i did it:

First, i'm using a Raspberry Pi Zero for the controller with an up-to-date Raspbian distro.
I have the last 0.0.3.Final-SNAPSHOT of MyController.org(at least the one from 24 days ago with jkandasa's modification).
I'm using the 2.0.0 version of MySensors (soon to be updated to the last version).
On MyControler.org i created 2 UID tags (sunrize and sunset) which point to 2 dummy sensors (child of a MySensors node).
Then i have the java script which send the sunrize and sunset value to this UID tags:

var myImports = new JavaImporter(java.io, java.lang, java.util);

with(myImports) {
  //Get Sunrise/Sunset details
  var locSettings = mcApi.utils().getServerLocationSettings();

  //Get sensor variables for sunrise and sunset
  var sensorSunRise = mcApi.uidTag().getByUid("sunrize").getSensorVariable();
  var sensorSunSet = mcApi.uidTag().getByUid("sunset").getSensorVariable();

  //Update timezone offset values (by default gives GMT timestamp values)
  //sensorSunRise.value = locSettings.sunriseTime + locSettings.timezoneOffset;
  //sensorSunSet.value = locSettings.sunsetTime + locSettings.timezoneOffset;

  var dtr = new Date(locSettings.sunriseTime);
  sensorSunRise.value = dtr.getHours() + ':' + dtr.getMinutes();

  var dts = new Date(locSettings.sunsetTime);
  sensorSunSet.value = dts.getHours() + ':' + dts.getMinutes();

  //Send/Update thise sensorvariable with updated value
  mcApi.sensor().sendPayload(sensorSunRise);
  mcApi.sensor().sendPayload(sensorSunSet);
}


On MyControler.org i created an Operation to execute the java script
and a Timer to start the Operation before Sunrize every day.

For your java script you just need to add an if statement comparing the sunrize and sunset values with the current time, and you should be good.
]]></description><link>http://forum.mycontroller.org/topic/86/sunrize-sunset-forward</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/86/sunrize-sunset-forward</guid><dc:creator><![CDATA[loic13]]></dc:creator><pubDate>Thu, 08 Dec 2016 23:44:01 GMT</pubDate></item><item><title><![CDATA[Monitoring electricity consumption]]></title><description><![CDATA[@rjad

Ok,I tested this but couldn't get it to work. Presumably I didn't follow the instructions properly.

When you do changes on HTML additional headers, you have to reload the browser. I hope you did this.

With some work it could be better, so for example, I lose the hover information, I had trouble getting two of these plots on one dashboard with different bins.

For hover information, I do nit get any clue. As I never worked directly with the D3 chart.
For the multiple of charts on same dashboard issue, you might have chart id issue.
Maybe because of this one,
 &lt;canvas id="simpled3" style="display: none;"&gt;&lt;/canvas&gt;

]]></description><link>http://forum.mycontroller.org/topic/85/monitoring-electricity-consumption</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/85/monitoring-electricity-consumption</guid><dc:creator><![CDATA[jkandasa]]></dc:creator><pubDate>Thu, 08 Dec 2016 10:28:38 GMT</pubDate></item><item><title><![CDATA[Temperature MIN&#x2F;MAX&#x2F;AVG]]></title><description><![CDATA[Wonderful !!!
Option 1 works for me like a charm !
Many thanks, MyController is the best 
]]></description><link>http://forum.mycontroller.org/topic/79/temperature-min-max-avg</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/79/temperature-min-max-avg</guid><dc:creator><![CDATA[Tetnobic]]></dc:creator><pubDate>Tue, 22 Nov 2016 15:29:18 GMT</pubDate></item><item><title><![CDATA[Battery level in rules or chart? [Script Rule to check battery level]]]></title><description><![CDATA[@jkandasa I'm using the 0.0.3.Final-SNAPSHOT - does this mean I dont need to create a script like above but find a rule/condition about battery levels of nodes? If so, I cannot find that, but I am currently using your script example, which works, but is of course a little cumbersome compared to another option of using a node's battery level directly somewhere in the rules panel...
]]></description><link>http://forum.mycontroller.org/topic/77/battery-level-in-rules-or-chart-script-rule-to-check-battery-level</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/77/battery-level-in-rules-or-chart-script-rule-to-check-battery-level</guid><dc:creator><![CDATA[Velo17]]></dc:creator><pubDate>Thu, 17 Nov 2016 18:23:02 GMT</pubDate></item><item><title><![CDATA[Control&#x2F;display operations via script]]></title><description><![CDATA[<h4>To list operations on Dashboard.</h4>
<h5>Script: <code>JavaScript</code></h5>
<pre><code>var myImports = new JavaImporter(java.io, java.lang, java.util);

with(myImports) {
  var filters = new HashMap();
  filters.put("orderBy", "name");
  filters.put("order", "asc");
  filters.put("pageLimit", new Long(10));
  //Get operations data
  var operations = mcApi.operation().getAll(filters);
}
</code></pre>
<h5>Template:</h5>
<pre><code>&lt;table class="table table-hover table-bordered table-striped mc-table"&gt;
  &lt;thead&gt;
    &lt;th&gt;{{ 'STATUS' | translate }}&lt;/th&gt;
    &lt;th&gt;{{ 'ID' | translate }}&lt;/th&gt;
    &lt;th&gt;{{ 'NAME' | translate }}&lt;/th&gt;
    &lt;th&gt;{{ 'OPERATION' | translate }}&lt;/th&gt;
    &lt;th&gt;{{ 'LAST_EXECUTION' | translate }}&lt;/th&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;#list operations.data as item&gt;
      &lt;tr ui-sref="operationsAddEdit({id: ${item.id} })"&gt;
        &lt;td class="text-center"&gt;
          &lt;#if item.enabled&gt;
            &lt;i class="text-success fa fa-circle fa-lg" uib-tooltip="{{ 'ENABLED' | translate }}"&gt;&lt;/i&gt;
          &lt;#else&gt;
            &lt;i class="text-danger fa fa-circle-o fa-lg" uib-tooltip="{{ 'DISABLED' | translate }}"&gt;&lt;/i&gt;
          &lt;/#if&gt;
        &lt;/td&gt;
        &lt;td&gt;${item.id}&lt;/td&gt;
        &lt;td&gt;${(item.name)!}&lt;/td&gt;
        &lt;td ng-bind-html="'${(item.operationString)!}' | mcResourceRepresentation"&gt;&lt;/td&gt;
        &lt;td&gt;&lt;span uib-tooltip="{{ ${(item.lastExecution?c)!"Never"} | date:mchelper.cfg.dateFormat:mchelper.cfg.timezone}}" tooltip-placement="left" am-time-ago="${(item.lastExecution?c)!"Never"}"&gt;&lt;/span&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/#list&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
</code></pre>
<h4>To enable/disable list of operations:</h4>
<h5>JavaScript</h5>
<p dir="auto"><strong>Script bindings:</strong> <code>{options:{name:"operation-name", enable:false}}</code><br />
<strong>Important</strong>: It is important to pass <code>Script bindings</code> when executing this script. In the binding you can include your operation <code>name</code> to filter. Please note in Mycontroller all filters are working with case sensitive. In the name filed you can put any words where operation name contains.</p>
<p dir="auto">For example I want to enable or disable following operations,</p>
<ul>
<li><code>my send email notification operation</code></li>
<li><code>notification: pushbullet</code></li>
</ul>
<p dir="auto">In the above names I have <code>notification</code> word in common. So I can use this name in filter to get these operations exactly.</p>
<h6>To disable:</h6>
<p dir="auto"><code>{options:{name:"notification", enable:false}}</code></p>
<h6>To enable:</h6>
<p dir="auto"><code>{options:{name:"notification", enable:true}}</code></p>
<pre><code>var myImports = new JavaImporter(java.io, java.lang, java.util);

with(myImports) {
  var filters = new HashMap();
  var names = new ArrayList();
  names.add(options.name);

  filters.put("orderBy", "name");
  filters.put("order", "asc");
  filters.put("pageLimit", new Long(10));
  filters.put("name", names)

  //Get operations data
  var operations = mcApi.operation().getAll(filters);
  
  var operationIds = new ArrayList();
  for(var count =0 ; count&lt;operations.data.length;count++){
    //You can do some filter here
     operationIds.add(operations.data[count].id);
  }
  
  if(options.enable){
   mcApi.operation().enableIds(operationIds);
  }else{
   mcApi.operation().disableIds(operationIds);
  }
}
</code></pre>
<p dir="auto"><strong>SOURCE:</strong> refer <a href="https://github.com/mycontroller-org/mycontroller/issues/235" rel="nofollow ugc">this issue</a> for complete details.</p>
]]></description><link>http://forum.mycontroller.org/topic/46/control-display-operations-via-script</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/46/control-display-operations-via-script</guid><dc:creator><![CDATA[jkandasa]]></dc:creator><pubDate>Wed, 31 Aug 2016 18:25:18 GMT</pubDate></item><item><title><![CDATA[Timers and scripts]]></title><description><![CDATA[@imedia I guess it should be a bug with recent pi4j driver. Let me setup serial gateway locally and narrow down the issue. Thank you so much for your support!
]]></description><link>http://forum.mycontroller.org/topic/45/timers-and-scripts</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/45/timers-and-scripts</guid><dc:creator><![CDATA[jkandasa]]></dc:creator><pubDate>Wed, 31 Aug 2016 06:21:26 GMT</pubDate></item><item><title><![CDATA[Introduction]]></title><description><![CDATA[<p dir="auto">Using scripts we can configure <code>Rule</code> &gt;&gt; <code>Condition</code>, <code>Operations</code>, <code>Dashboard custom widget</code> data.</p>
<p dir="auto">List of <a href="http://www.mycontroller.org/files/docs/javadoc/apidocs/index.html?org/mycontroller/standalone/scripts/api/McScriptApi.html" rel="nofollow ugc">supported API's</a></p>
<p dir="auto">API's are added in script environment. You can access any supported API's with <code>mcApi</code> object.</p>
<p dir="auto"><strong>Note:</strong>  Here I am listing only few API's. For complete set of API's please refer <a href="http://www.mycontroller.org/files/docs/javadoc/apidocs/index.html?org/mycontroller/standalone/scripts/api/McScriptApi.html" rel="nofollow ugc">API's document</a>.</p>
<h4>Examples:</h4>
<h4><code>Java script</code></h4>
<p dir="auto">Take an example I want to display last seen of node details in dashboard.</p>
<pre><code>var myImports = new JavaImporter(java.io, java.lang, java.util);  // &lt;1&gt;

with(myImports) {  // &lt;2&gt;
  var options = new HashMap(); // &lt;3&gt;
  //Sort by lastSeen.
  options.put("orderBy", "lastSeen"); // &lt;4&gt;
  //Order by descending
  options.put("order", "desc"); // &lt;5&gt;
  //Page limit, only 5 result
  options.put("pageLimit", new Long(5)); // &lt;6&gt;
  //Get nodes data
  var nodes = mcApi.node().getAll(options); // &lt;7&gt;
}
</code></pre>
<p dir="auto">&lt;1&gt; Import required packages for our coding. <code>JavaImporter</code> is used to import packages.<br />
You can import any numbe of packages with comma separated.<br />
&lt;2&gt; Add our imports <code>with</code> loop<br />
&lt;3&gt; Create a <code>HashMap</code> to add our query filter values.<br />
&lt;4&gt; Adding a filter <code>orderBy</code> as <code>lastSeen</code><br />
&lt;5&gt; Adding another filter <code>order</code> as <code>desc</code><br />
&lt;6&gt; Adding another filter <code>pageLimit</code> as <code>5</code><br />
&lt;7&gt; Store queried results in the variable <code>nodes</code>, can be used in templates(refer templates section)<br />
<code>mcApi</code> already binded with script engine, you can use it to query/set values from/to MyController.</p>
<h4><code>Groovy script</code></h4>
<p dir="auto">I want to print serial gateways on MyController log file.</p>
<pre><code>import org.mycontroller.standalone.gateway.GatewayUtils.GATEWAY_TYPE // &lt;1&gt;
def filters = [name: 'Serial-gateway',  pageLimit: 10L, type: GATEWAY_TYPE.SERIAL] // &lt;2&gt;
def queryResponse = mcApi.gateway().getAll(filters) // &lt;3&gt;
mcApi.logger().info("Quesry Response:{}", queryResponse) // &lt;4&gt;
</code></pre>
<p dir="auto">&lt;1&gt; Import <code>GATEWAY_TYPE</code> enum, will be used to filter<br />
&lt;2&gt; Create filter list with filter values, Filtering with gateway<br />
<code>name</code> contains <code>Serial-gateway</code> (case sensitive), <code>type</code> as <code>GATEWAY_TYPE.SERIAL</code><br />
and limiting count on request as 10 <code>10L</code> with the key <code>pageLimit</code><br />
&lt;3&gt; Calling MyController API(<code>mcApi.gateway().getAll(filters) </code>) with our filter<br />
&lt;4&gt; Printing result under <code>mycontroller/log/mycontroller.log</code> as <code>INFO</code> log.</p>
<p dir="auto">NOTE: When log level set at <code>ERROR</code>, <code>INFO</code> logs will not be printed!</p>
<h4><code>Python script</code></h4>
<p dir="auto">In this script we are getting gateways detail and printing in log file.</p>
<pre><code>from java.util import HashMap # &lt;1&gt;
from java.lang import Long # &lt;2&gt;
options = {'pageLimit': Long(20)} # &lt;3&gt;
gateways = mcApi.gateway().getAll(HashMap(options)) # &lt;4&gt;
mcApi.logger().info("Quesry Response:{}", gateways) # &lt;5&gt;
</code></pre>
<p dir="auto">&lt;1&gt; Import <code>HashMap</code> should be used to send filter queries<br />
&lt;2&gt; Import <code>Long</code> used to send java <code>Long</code> type<br />
&lt;3&gt; Create filter with <code>pageLimit</code> of <code>20</code><br />
&lt;4&gt; Query MyController with <code>McApi</code> and store result in <code>gateways</code><br />
&lt;5&gt; Print result in <code>mycontroller/log/mycontroller.log</code> file.</p>
]]></description><link>http://forum.mycontroller.org/topic/28/introduction</link><guid isPermaLink="true">http://forum.mycontroller.org/topic/28/introduction</guid><dc:creator><![CDATA[jkandasa]]></dc:creator><pubDate>Tue, 24 May 2016 16:24:19 GMT</pubDate></item></channel></rss>