RaZberry OpenRemote interface (RAZOR)

Discussions about RaZberry - Z-Wave board for Raspberry computer
Post Reply
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

RaZberry OpenRemote interface (RAZOR)

Post by pz1 »

Since version 1.5 a new version of the RaZ-OR is bundled with the z-way-server distribution. A short guide is given here: viewtopic.php?f=3422&t=20271#p49887.

In the assessment I came to a problem with the MeterLevel function.

Code: Select all

            case "MeterLevel":
                var S = params.shift();
                zway.devices[N].instances[I].Meter.Get();
                return zway.devices[N].instances[I].Meter.data[S].val.value;
The source of the problem is that OpenRemote sensors only accept integer or string values. I do use this MeterLevel for reading consumption/power levels of a Fibaro plugin switch. The returned values are reals.
I therefor had added some math to do away with the decimals in the original RaZ-OR. I tried to reinstate that in the new code:

Code: Select all

    case "MeterLevel":
         var S = params.shift();
         zway.devices[N].instances[I].Meter.Get();
         switch (S)
           {
           case 0:
             return Math.round((zway.devices[N].instances[I].Meter.data[S].val.value)*1000);
             break;
           case 2:
             return Math.round((zway.devices[N].instances[I].Meter.data[S].val.value)*10)/10;
             break;  
           }
For some reason the function now only returns 0 values in both cases. In the original openremote.js this worked fine. What am I doing wrong?

EDIT: As a matter of fact, after I called the function from Firefox, I noticed that the accumulated kWh was reset to zero :?:
Since 29-12-2016 I am no longer a moderator for this forum
User avatar
PoltoS
Posts: 7649
Joined: 26 Jan 2011 19:36

Re: RaZberry OpenRemote interface (RAZOR)

Post by PoltoS »

May be it is a better idea to convert it to a string using zway.devices[N].instances.Meter.data.val.value.toStrong()? And even add correspinding scale title to it?

I don't like the idea to make a switch on scales, since there might be a lot of them...

Or even add postfix /string to any value to convert it automatically to string?

Just would like to keep things clear and simple
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: RaZberry OpenRemote interface (RAZOR)

Post by pz1 »

Just would like to keep things clear and simple
I fully agree. But that being said, if you have to interface dissimilar systems you can not always avoid it to be a bit messy.

Making a string with added scale is not an option, because the value is needed in further operations. The http command at the OpenRemote side can do some regex, json, xpath, but is badly missing some scripting functions to prepare/polish data. As said integer is the only numerical value it can deal with.

So at the moment for me it is the only option to do these conversions within RaZberry. I'll see if I can partially resurrect the old openremote.js and do the 'dirty' things there.
Since 29-12-2016 I am no longer a moderator for this forum
User avatar
PoltoS
Posts: 7649
Joined: 26 Jan 2011 19:36

Re: RaZberry OpenRemote interface (RAZOR)

Post by PoltoS »

In that case I propose to add postifxes to OpenRemote URLs with dividors to allow control wished dividors from the caller, not messing this in the module.
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: RaZberry OpenRemote interface (RAZOR)

Post by pz1 »

I do not intend to mess with your OpenRemote Helper!
For the time being I use a my_openremote.js which is executed from main.js. It follows the calls with the case switch that work for me.
This is meant to be a temporary solution until I can do the smartness presently configured using OpenRemote Drools.

Your automation configurator is promising, but unfortunately I have not yet have the skills to design a kind of IF <clauses> THEN <action> template.
Since 29-12-2016 I am no longer a moderator for this forum
User avatar
PoltoS
Posts: 7649
Joined: 26 Jan 2011 19:36

Re: RaZberry OpenRemote interface (RAZOR)

Post by PoltoS »

Such a clause is not possible yet, but can be done in future. The question is, what do you want in <clauses> and <actions>. Please provide real examples
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: RaZberry OpenRemote interface (RAZOR)

Post by pz1 »

I'll just give you a rule to control a sunshade as I use in OpenRemote. It is the second examples Poor Mans Sunshade Control that you refer to under Projects on the RaZberry home page

Code: Select all

rule "Sunshades Up" when
  CustomState( source == "SunScreenDocked", value=="false")
  (CustomState( source == "isItRaining", value=="true") or 
   CustomState( source=="isNight_sensor", value=="true") or 
   Event( source == "WindGust", value > 38 )
  )
then
  execute.command( "SunScreenUP" );
end
The first two clauses come from the respective BinarySensors of a Fibaro Universal Sensor (FGBS001)
The isNight comes from the Openremote Time Protocol, for which I must find/construct an equivalent via some custom code.
The WindGust is read from XML coming from a public wheather source (Wunderground.com presently).

The action part is presenly done via a a shell script called GPIO.sh that controls some of the pins of the gpio-connector just next to the RaZberry.

This is in short the scenario. Within OpenRemote windgust and isNight are modelled in some kind of virtual device.

EDIT: I forgot to mention the logical constructors in this Drools example. By default Drools interprets the clauses as AND statements. The OR must be explicitly specified.
So in normal language the rule read as:
"When Sunscreen is not in dock position, and it is at least raining, night or stormy" then "raise the sunscreen"
Since 29-12-2016 I am no longer a moderator for this forum
User avatar
PoltoS
Posts: 7649
Joined: 26 Jan 2011 19:36

Re: RaZberry OpenRemote interface (RAZOR)

Post by PoltoS »

Check in git develop LogicalRules module. Hope it will solve your problem.
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: RaZberry OpenRemote interface (RAZOR)

Post by pz1 »

PoltoS wrote:Check in git develop LogicalRules module. Hope it will solve your problem.
I'll have a look at it later today or tomorrow
Since 29-12-2016 I am no longer a moderator for this forum
Post Reply