Old Düwi wall plug polling

Discussions about existing Z-Wave device and their usage with Z-Way/Z-Cloud/Z-Box
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Old Düwi wall plug polling

Post 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?
Since 29-12-2016 I am no longer a moderator for this forum
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Old Düwi wall plug polling

Post by pofs »

Sure setInterval() is preferred one, because it doesn't involve network interaction overhead (request parsing, native->js->native data transfer etc.)
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Old Düwi wall plug polling

Post by pz1 »

Thanks, that's what I thought. I'll add this bit of information to the UPD Recipe
Since 29-12-2016 I am no longer a moderator for this forum
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Old Düwi wall plug polling

Post 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.
Since 29-12-2016 I am no longer a moderator for this forum
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Old Düwi wall plug polling

Post 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 :)
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Old Düwi wall plug polling

Post 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 ) ;
} );
Since 29-12-2016 I am no longer a moderator for this forum
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Old Düwi wall plug polling

Post 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
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Old Düwi wall plug polling

Post 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
Since 29-12-2016 I am no longer a moderator for this forum
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Old Düwi wall plug polling

Post 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
Since 29-12-2016 I am no longer a moderator for this forum
skiv71
Posts: 124
Joined: 01 May 2014 13:46
Location: United Kingdom
Contact:

Re: Old Düwi wall plug polling

Post 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?
Post Reply