Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Just a suggestion: for Operation #235

Open
jkandasa opened this issue Aug 5, 2016 · 10 comments
Open

Just a suggestion: for Operation #235

jkandasa opened this issue Aug 5, 2016 · 10 comments

Comments

@jkandasa
Copy link
Member

jkandasa commented Aug 5, 2016

Reported by @cimba007 at https://forum.mysensors.org/topic/4431/mycontroller-0-0-3-alpha2-released/15
image

Send notification would include all further kinds of notifications you might include but grouping this is not that important. The current way it is is already very easy to understand so a change might not be necessary.

Send payload might be better split into three different points as it would be very clear from the beginning what you are dealing with.

  • Dealing with Resources (manipulating stuff that is only known to the controller )
  • Manipulating Devices (reboot etc. .. this is more like a "command")
  • Update Sensor variables is an 1:1 mapping of the request/set concept of mysensors
@cimba007
Copy link

Hello, on my current configuration the rules system does not show any meaningfull values on "autocomplete".

image

Althrough I have one node with 2 sensors which I would like to check against some threshold.

image

Am I doing something wrong?! I can't select operations based on these 2 sensor values neither.

@cimba007
Copy link

I noticed the option to enable/disable operations via operations is not possible. With this I would very conveniently enable/disable my notification mechanism.

image

Rule and Timer is possible, Operations is missing.

@cimba007
Copy link

cimba007 commented Aug 28, 2016

I tried a workaround with scripts but I have no idea how to list all operations with their correspondig ID so I could use a script to disable the specific operation via scripting.

Could you provide a very small example on how to list all operations with ID and how to disable/enable an operation? Thank you in advance!

I think I have an working example for displaying all operations:

Script:

var HashMap = Java.type('java.util.HashMap');
var map = new HashMap();

var myoperations2 = mcApi.operation().getAllRaw(map);

Template:

${( myoperations2.toString() )}

Result:

image

@jkandasa
Copy link
Member Author

@cimba007

Rule and Timer is possible, Operations is missing.

Operations inside operation might create recursive loop, hence I disable that option.

Could you provide a very small example on how to list all operations with ID and how to disable/enable an operation?

To list operations on Dashboard.

Script: JavaScript
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);
}
Template:
<table class="table table-hover table-bordered table-striped mc-table">
  <thead>
    <th>{{ 'STATUS' | translate }}</th>
    <th>{{ 'ID' | translate }}</th>
    <th>{{ 'NAME' | translate }}</th>
    <th>{{ 'OPERATION' | translate }}</th>
    <th>{{ 'LAST_EXECUTION' | translate }}</th>
  </thead>
  <tbody>
    <#list operations.data as item>
      <tr ui-sref="operationsAddEdit({id: ${item.id} })">
        <td class="text-center">
          <#if item.enabled>
            <i class="text-success fa fa-circle fa-lg" uib-tooltip="{{ 'ENABLED' | translate }}"></i>
          <#else>
            <i class="text-danger fa fa-circle-o fa-lg" uib-tooltip="{{ 'DISABLED' | translate }}"></i>
          </#if>
        </td>
        <td>${item.id}</td>
        <td>${(item.name)!}</td>
        <td ng-bind-html="'${(item.operationString)!}' | mcResourceRepresentation"></td>
        <td><span uib-tooltip="{{ ${(item.lastExecution?c)!"Never"} | date:mchelper.cfg.dateFormat:mchelper.cfg.timezone}}" tooltip-placement="left" am-time-ago="${(item.lastExecution?c)!"Never"}"></span></td>
      </tr>
    </#list>
  </tbody>
</table>

To enable/disable list of operations:

JavaScript

Script bindings: {options:{name:"operation-name", enable:false}}
Important: It is important to pass Script bindings when executing this script. In the binding you can include your operation name 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.

For example I want to enable or disable following operations,

  • my send email notification operation
  • notification: pushbullet

In the above names I have notification word in common. So I can use this name in filter to get these operations exactly.

To disable:

{options:{name:"notification", enable:false}}

To enable:

{options:{name:"notification", enable:true}}

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<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);
  }
}

@cimba007
Copy link

cimba007 commented Aug 29, 2016

Thank you very much. This looks much more refined as my little "hack" 💃

I think this will do exactly what I want.

Maybe I should take my time to sum up what I intent to do with the possibility to enable/disable operations.

My Plan:

I plan to send pushbullet notifications depending on my sensor threshold. This should be pretty straightforward and is currently working as expected.

To disable these notifications at night it would be possible to disable every rulde which leads to a notification. I thought it would be much easyier to disable the notification, leaving all rules intact.

To disable the operation I would then use a simple rule and an V_ARMED switch which would execute my custom script to disable the notification operation.

I am not totally sure if it is flawless but having the possibility to disable operations from script is very nice and I think will help me a lot.

@jkandasa: I think your example is very elaborated and very good. If you/I close this issue the information would be "Lost" for other users. Maybe you could add this and the statistics example from earlyer to the documentation?! It would help a lot to get a quickstart for custom widgets for other users!

@cimba007
Copy link

I now successfully implemented enabling/disabling operation via switch thanks to your excellent example code:

image

image

@jkandasa
Copy link
Member Author

jkandasa commented Aug 29, 2016

@cimba007 great! This is awesome!

@jkandasa: I think your example is very elaborated and very good. If you/I close this issue the information would be "Lost" for other users. Maybe you could add this and the statistics example from earlyer to the documentation?! It would help a lot to get a quickstart for custom widgets for other users!

Yes, you are right I will create entry on http://forum.mycontroller.org and close this one.

To disable these notifications at night it would be possible to disable every rulde which leads to a notification. I thought it would be much easyier to disable the notification, leaving all rules intact.

Yes, for that reason I gave an option for operations also. We may use operations on timer, rule(multiple places). When disabling operation directly never get executed by any rules, timers.

If you have only requirement that to disable operations on night time, simply schedule a cron, other other timer to execute enable/disable operations script. Which is easier than manual switch. but it is up to you.

@cimba007
Copy link

If you create the entry on the forum please add a link to the forum post to the documentation too!
http://www.mycontroller.org/#/documents/user/0.0.3.Alpha2.html => Script examples

People will most likely have a look at the documentation first so this would ensure this valuable information can be easylie found.

@jkandasa
Copy link
Member Author

updated in forum, http://forum.mycontroller.org/topic/46/control-display-operations-via-script

If you create the entry on the forum please add a link to the forum post to the documentation too!
http://www.mycontroller.org/#/documents/user/0.0.3.Alpha2.html => Script examples

Sure, I will add this on 0.0.3.Final release document.

@cimba007
Copy link

I even thought if it would be usefull to include the example in the actual mycontroller version as EXAMPLE_SCRIPT with the disabled flag set. It would be even easier to find a quickstart to scripting ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants