This page last changed on Nov 23, 2013 by aktur.

I'm testing now a power sensor and display wattage in a label. I wonder how hard would it be to change the label color according to number of watts the sensor is indicating? Of course doing it from drools, but due to references etc. probably this would mean heavy hacking, wouldn't it?

This is something we've been thinking about for some time and how to fit a generic implementation of this in the roadmap (basically allowing all/most of the attributes of widgets to be linked to a sensor or somehow modified from the controller (or from local scripting in the console). But it'll take time and we're not there yet.

The "hack" I can think about now (but have not tested) is that if you e.g. only want 2 colors, add 2 labels on top of each other, each with their own color. From the rules, send the text to the label with the desired color and an empty string to the other.

If you do try that, please let me know how it works out.

Posted by ebariaux at Nov 24, 2013 09:00

Unfortunately this hack does not work. When I send an empty string to the label then the old string is kept. If you can point me to the java source which does that then I can try to modify it and test if it works.

Posted by aktur at Nov 24, 2013 16:22

Correction to my previous test. It does not work on iOS (iOS 7, OR 2.1.3) but it works on Android. Therefore, IMHO it has to do with the console app and not the controller.

Posted by aktur at Nov 25, 2013 22:04

Thanks for the investigation, I'll take a look at the iOS code

Posted by ebariaux at Nov 26, 2013 08:55

Michal, would you mind posting the Code-snippet to Set a label from inside a rule.

Would be interesting for unexperienced Users (like me)

Thank you

Posted by orjo at Nov 26, 2013 18:45

Sure, here it is:

// Power Measurement Label color
rule "Socket Switching Power"
when
  Event(source=="SocketSwitching1.POWER", $v: value)
then
  String s = $v.toString();
  int v=Integer.parseInt($v.toString());
  if(v<80){
    execute.command("SocketSwitching1.POWER.Green", s);
    execute.command("SocketSwitching1.POWER.Yellow", " ");
    execute.command("SocketSwitching1.POWER.Red", " ");
  }else if(v<150){
    execute.command("SocketSwitching1.POWER.Green", " ");
    execute.command("SocketSwitching1.POWER.Yellow", s);
    execute.command("SocketSwitching1.POWER.Red", " ");
  }else{
    execute.command("SocketSwitching1.POWER.Green", " ");
    execute.command("SocketSwitching1.POWER.Yellow", " ");
    execute.command("SocketSwitching1.POWER.Red", s);
  }
end
Posted by aktur at Nov 26, 2013 19:39

I've seen that indeed the current iOS code does check for empty string (and I suppose it gets trimmed somewhere in the path, so a space would not help) and do not update the label in that case.

I'm doing a lot of rework on the iOS console and will drop that check to see if it causes any issue.

Posted by ebariaux at Nov 27, 2013 20:14
Document generated by Confluence on Jun 05, 2016 09:34