Xpl-Perl ZenAH setup (Dutch)

Forum regarding Linux Software and Home Automation Domotica.
User avatar
RDNZL
Forum Moderator
Forum Moderator
Posts: 1008
Joined: Sun Sep 24, 2006 1:45 pm
Location: Dordrecht, The Netherlands
Contact:

Xpl-Perl ZenAH setup (Dutch)

Post by RDNZL »

<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by snelvuur</i>
<br />Well join the club then :) i dont know if you use http://www.advsofteng.com/ chart director. But there are some simple lines to get some graphs with it (the sensors button from www.binkey.nl) if you want i can put those online to, perhaps to play around.

// Erik (binkey.nl)
<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">

Hi Erik,

I'm using the default rrd graphs to test my setup, and I'm looking for a more atractive graph...

Would be nice to look your chart director examples.

Thanks,
Ron.
User avatar
Snelvuur
Forum Moderator
Forum Moderator
Posts: 3156
Joined: Fri Apr 06, 2007 11:01 pm
Location: Netherlands
Contact:

Xpl-Perl ZenAH setup (Dutch)

Post by Snelvuur »

check http://www.binkey.nl/perl/sensors.txt , i use the same perl script depending on how it was called (see the examples on my site for url) i also use the xpl client so it grabs the database (mysql) values aswell. You can use chart director without a key, you only get a small text line commercial which is still do-able. xPL::SQL::Msg is a few examples beanz created. Although there not fast, they do make some nice graphs easy.

Some notes from beanz:

xPL::SQL::Msg->last_sensor_readings("rtgr328n.4d","temp"); (default is average)
or xPL::SQL::Msg->last_sensor_readings("rtgr328n.4d","temp","maximum"); # or
xPL::SQL::Msg->last_sensor_readings("rtgr328n.4d","humidity","minimum");
you can even do things like: xPL::SQL::Msg->last_sensor_readings("%","humidity","minimum"); # to get the minimum of all devices reporting humidity
note for temperature you might want to do '%.%' to match only 1-wire or oregon sensors and not hddtemp or you might find it reports it as rather warm ;-)

You can also grab a mysql line, which i got from beanz too. As an example you can see what it does more or less in one of those querys:

select HOUR(FROM_UNIXTIME(msg.time)) as hr, avg(substring(body.body from (8+position('current=' in body.body)))) as value from msg,body where msg.body = body.id and msg.time > UNIX_TIMESTAMP(DATE_SUB(CURDATE(),INTERVAL 1 DAY)) and body.body like '%device=rfxsensor00f0\ntype=temp\n%' group by hr;

// Erik (binkey.nl)
beanz
Starting Member
Starting Member
Posts: 20
Joined: Wed Jun 13, 2007 11:22 am
Location: United Kingdom
Contact:

Xpl-Perl ZenAH setup (Dutch)

Post by beanz »

<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by snelvuur</i>
<br />check http://www.binkey.nl/perl/sensors.txt , i use the same perl script depending on how it was called (see the examples on my site for url) i also use the xpl client so it grabs the database (mysql) values aswell. You can use chart director without a key, you only get a small text line commercial which is still do-able. xPL::SQL::Msg is a few examples beanz created. Although there not fast, they do make some nice graphs easy.

Some notes from beanz:

xPL::SQL::Msg->last_sensor_readings("rtgr328n.4d","temp"); (default is average)
or xPL::SQL::Msg->last_sensor_readings("rtgr328n.4d","temp","maximum"); # or
xPL::SQL::Msg->last_sensor_readings("rtgr328n.4d","humidity","minimum");
you can even do things like: xPL::SQL::Msg->last_sensor_readings("%","humidity","minimum"); # to get the minimum of all devices reporting humidity
note for temperature you might want to do '%.%' to match only 1-wire or oregon sensors and not hddtemp or you might find it reports it as rather warm ;-)

You can also grab a mysql line, which i got from beanz too. As an example you can see what it does more or less in one of those querys:

select HOUR(FROM_UNIXTIME(msg.time)) as hr, avg(substring(body.body from (8+position('current=' in body.body)))) as value from msg,body where msg.body = body.id and msg.time > UNIX_TIMESTAMP(DATE_SUB(CURDATE(),INTERVAL 1 DAY)) and body.body like '%device=rfxsensor00f0\ntype=temp\n%' group by hr;

// Erik (binkey.nl)
<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">

I should point out that even though I did provide this information it is *not* the way I actually do it nor the way I really recommend. I personally run my ZenAH code and define specific rules to log only the values I require to a History table which then supports somewhat simpler/faster SQL queries. I'll try to get around to adding some examples to the ZenAH wiki. (The xPL SQL tables are very generic because they support xPL messages which are also very generic. This results in awful and complicated queries for specific things such as graphs.)

Regards,
Mark.
beanz
Starting Member
Starting Member
Posts: 20
Joined: Wed Jun 13, 2007 11:22 am
Location: United Kingdom
Contact:

Xpl-Perl ZenAH setup (Dutch)

Post by beanz »

<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by RDNZL</i>
<br />Mark,

I finally had some time to look into my RFXPower module probs I had with xpl-rfxcom.

I solved 2 bugs, dunno if these break other modules.

Code: Select all

server:/usr/local/bin# diff  /home/domo/install/xpl-perl/lib/xPL/RF/RFXMeter.pm /usr/local/share/perl/5.8.8/xPL/RF/RFXMeter.pm 
58c58,59
<   my $device = sprintf "%02x%02x", $bytes->[1], $bytes->[2];
---
>   my $device = sprintf "%02x%02x", $bytes->[0], $bytes->[1];
> 
102c103
<   my $kwh = ( ($bytes->[4]<<16) + ($bytes->[2]<<8) + ($bytes->[3]) ) / 100;
---
>   my $kwh = ( ($bytes->[4]<<16) + ($bytes->[2]<<8) + ($bytes->[3]) ) / 1000;

This fixes the problem I described earlier, about the wrong device id. I found out xpl-perl reads the wrong bytes ( 1 off)...

And for an RFXPower module inserted in RFXMeter you need to divide by 1000 instead of 100 to get the kWh.

Problem which is still there is rrd not accepting the readout:
2007-09-25_17:51:39.96879 ERROR updating /var/lib/rrd/rfxmeter.00f0/kwh.rrd: not a simple integer: '224.271'
2007-09-25_17:53:39.97997 ERROR updating /var/lib/rrd/rfxmeter.00f0/kwh.rrd: not a simple integer: '224.299'
2007-09-25_17:57:39.99785 ERROR updating /var/lib/rrd/rfxmeter.00f0/kwh.rrd: not a simple integer: '224.354'
2007-09-25_17:59:40.00677 ERROR updating /var/lib/rrd/rfxmeter.00f0/kwh.rrd: not a simple integer: '224.385'

I can round it, but i loose important data then.
Anyone knows why rrd is complaining?

I have also created 2 very simple scripts, to stop and start xpl-perl the right way, make live so much easier!

stop-xpl:

Code: Select all

#!/bin/sh

cd /etc/xplperl/service
for i in `ls`
do
sv down $i
done
start-xpl:

Code: Select all

#!/bin/sh

cd /etc/xplperl/service
for i in `ls`
do
sv up $i
done
I'm starting to like xpl-perl! [8)]

Regards,
Ron.
<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">

Thanks for the address bug fix. I've incorporated that in to svn r363.

The other fix is not so simple. Since I have one of the original rfxpower transmitters and that transmits kwh*100 not kwh*1000. I'll try to find out if there is a programmatic way to tell the two apart.

As for the RRD problem, counters in rrd must be integers - I didn't realize that earlier versions just truncated them silently. I think the best thing to do is just to multiply them back up (*1000) for storage and divide again for display. However, I'm not really sure that I can think of a good way to do this in the code. I'll have a think about it. I've raised a ticket in the xPL-Perl bug tracker at http://www.xpl-perl.org.uk/ticket/7. Send me a private message if you want a login so you can raise other tickets.

Thanks very much for the helpful feedback. It is much appreciated.

Regards,
Mark.
Post Reply

Return to “Linux Forum”