Page 1 of 2

Old Düwi wall plug polling

Posted: 26 Nov 2014 19:04
by pz1
I have this old Düwi wall plug that does not send unsolicited status updates. For usage with OpenRemote there are two things I can do:
  1. Place every second a status request call via OpenRemoteHelpers module
  2. Use setInterval as Custom Java script

    Code: Select all

             /JS/Run/setInterval(function(){
               zway.devices[2].Basic.Get();
             } ,1000);
    
Which of the two is the preferred (most efficient) method?

Re: Old Düwi wall plug polling

Posted: 26 Nov 2014 19:24
by pofs
Sure setInterval() is preferred one, because it doesn't involve network interaction overhead (request parsing, native->js->native data transfer etc.)

Re: Old Düwi wall plug polling

Posted: 26 Nov 2014 19:54
by pz1
Thanks, that's what I thought. I'll add this bit of information to the UPD Recipe

Re: Old Düwi wall plug polling

Posted: 26 Nov 2014 23:35
by pz1
Hmmmmm, I am biting myself in the tail with this one :oops: Every time I do a "Get()" it results in an event. This event does trigger a status update to be send with my UDP module. As a result CPU raising from a modest 5% to 25-40%. For this one I'll revert to good old polling. For its intended use, a low refresh rate is not a real problem.

Re: Old Düwi wall plug polling

Posted: 27 Nov 2014 07:11
by pofs
There's a type arg in callback. If it has PhantomUpdate bit set, you shouldn't really send status update, because value has not changed :)

Re: Old Düwi wall plug polling

Posted: 27 Nov 2014 11:52
by pz1
pofs wrote:There's a type arg in callback. If it has PhantomUpdate bit set, you shouldn't really send status update, because value has not changed :)
Took me a while to find information about PhantomUpdate as it is not in the Developers Document, and the search function of this forum apparantly does not search inside code blocks. Anyhow I found this post about TKB switches.
That describes a different situation I think. I don't know how/where to use that type in my function
Here?

Code: Select all

                 /JS/Run/setInterval(function(){
                   zway.devices[2].Basic.Get();
                 } ,1000);
or here?

Code: Select all

zway.devices[4].instances[0].SwitchBinary.data.level.bind(function()
{
   var status = (this.value) ? "on" : "off";
   system("/opt/z-way-server/automation/storage/status.sh", "ZWay_4," + status ) ;
} );

Re: Old Düwi wall plug polling

Posted: 27 Nov 2014 22:23
by pofs
The latter one, as type arg is only available in bind callback.

But unlike the linked post, where only phantom updates were used, you should use only real ones:

Code: Select all

zway.devices[4].instances[0].SwitchBinary.data.level.bind(function(type)
{
   if (type !== 1) return; // handle only real updates
   var status = (this.value) ? "on" : "off";
   system("/opt/z-way-server/automation/storage/status.sh", "ZWay_4," + status ) ;
});
Of course, it will create some overhead, but not that big as calling shell script

Re: Old Düwi wall plug polling

Posted: 28 Nov 2014 11:47
by pz1
pofs wrote:Of course, it will create some overhead, but not that big as calling shell script
Thanks, I'll give it a try.
Result will go to Recipe on UPD status push

Re: Old Düwi wall plug polling

Posted: 28 Nov 2014 22:25
by pz1
pofs wrote:The latter one, as type arg is only available in bind callback.

But unlike the linked post, where only phantom updates were used, you should use only real ones:

Code: Select all

zway.devices[4].instances[0].SwitchBinary.data.level.bind(function(type)
{
   if (type !== 1) return; // handle only real updates
   var status = (this.value) ? "on" : "off";
   system("/opt/z-way-server/automation/storage/status.sh", "ZWay_4," + status ) ;
});
I had to make a block code after the if:

Code: Select all

zway.devices[4].instances[0].SwitchBinary.data.level.bind(function(type)
{
   if (type !==1){
     return;
   }
   var status = (this.value) ? "on" : "off";
   system("/opt/z-way-server/automation/storage/status.sh", "ZWay_4," + status )                                                                               ;
} );
It does work this way, but CPU load went from ~5% to ~10% (mostly for the setInterval I guess). I'll see what plain polling does. I guess the same, and it is simpler

Re: Old Düwi wall plug polling

Posted: 04 Jan 2015 17:58
by skiv71
My system is aware of all the nodes (and their classes) and periodically (once a minute) does automated *.Get() for all classes on a white-list, for all mains devices.

Battery device's have their *.Get() done on wake instead.

Maybe you could do something similar with just javascript?