PiFace support added

User avatar
Keptenkurk
Posts: 440
Joined: Wednesday 21 August 2013 17:24
Target OS: -
Domoticz version:
Location: Waalre, The Netherlands
Contact:

Daily power consumption shows spike on restart Domoticz

Post by Keptenkurk » Tuesday 15 October 2013 17:12

I use RPi + PiFace to count pulses from my power meter. However on every restart of Domoticz (like after an update) the counter will start at 0 again.
This results in an hourly value of 49191318995907640000 Watt. Monthly graphs do no suffer from this. It's only that the other values get so small :-)
Power.jpg
Power.jpg (46.52 KiB) Viewed 3253 times
I suspect that this because usage is calculated from (current count - last count) which is negative. Does the RFXMeter device store the latest countvalue and/or should the PiFace driver do the same? (or at least get the latest value from the database instead of starting from 0).
Maybe RobinS can comment on this...
/paul

RobinS
Posts: 67
Joined: Friday 13 September 2013 0:24
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Daily power consumption shows spike on restart Domoticz

Post by RobinS » Friday 18 October 2013 21:38

Hi Paul,

At least your normal energy consumption is normal now :)
I think that you are correct, it seems that the current - last value gets negative when domoticz is restarted and the PiFace driver starts with 0.
Actually I was expecting such behaviour when testing, but then always got sane results... So I was under the impression that Domoticz had a good mechanism to deal with it.
The RFXmeter hardware will most likely store its energy counter in memory, and keep counting.

I will need to fix this, and think that there are 3 solutions to the problem:
1) Have the PiFace driver store the metervalues into a file on disk (do not like this option to much as it could add additional wear to the SD card)
With this method the counter value will be the most acurate because it will store all increments even between the updates to domoticz.
2) Get the last value from the Database as you suggested, and use it.
3) Fix the calculation error of the RFXmeter.
For now this has my preference, as is an RFXmeter is reset (replacement etc), then the same issue will occur.
As well as an RFXmeter overflow from large to 0...

One thing that I experienced with an older system that I used, which also had an opto to detect the 0 rotations on the gasmeter:
Was that in certain cases the mirror in the 0 was at an inconvenient edge, causing the signal to oscillate and also cause sky high readings.

However what you are describing imo looks like a domoticz issue.
Will try to look at it this weekend.

Best Regards,

Robin
BTW: I prefer to keep the issue reporting in the PiFace topic, as things remain central, and I am notified about it.
My domoticz setup:
PI [Doorbell on Audio out], DS1307 RTC, BMP085, PiFace [4* S0 meter, Doorbell In, PIR, GBS and Door sensors] and RFXCom 433 [5 HomeEasy, 2 Impluz]
2x P1 smartmeter on USB
Gammu-smsd with USB 3G modem
Andromoticz on control tablet

User avatar
Keptenkurk
Posts: 440
Joined: Wednesday 21 August 2013 17:24
Target OS: -
Domoticz version:
Location: Waalre, The Netherlands
Contact:

Re: Daily power consumption shows spike on restart Domoticz

Post by Keptenkurk » Friday 18 October 2013 22:44

Thanks Robin,

I agree the third solution would be the most general way to fix this and indeed would also prevent rollover errors.
The RFXCOM website states: "counters are stored in non-violate memory and values are preserved in cause of power failure"

Ok abt the place to report PiFace issues. WIll ask moderator to move.. and will maintain Wiki as well.
/paul

User avatar
gizmocuz
Posts: 8526
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi
Domoticz version: beta
Location: Top of the world
Contact:

Re: PiFace support added

Post by gizmocuz » Saturday 19 October 2013 9:30

What i do for the 'S0' meter hardware is for the first start retrieve the last value, and use this as an offset,
and/or when the actual value is lower then the last (the meter must have been reset, or the counter is looped), do it again...

Bdw, i seem to have a piface.conf file, but i do not own that hardware (yet), is this file automatically created, or was put into subversion?
If the later, i probably should add it to the beta/release archive file as well.
But would be better if this file was created on first user, or after use->exit

/Rob
Quality outlives Quantity!

RobinS
Posts: 67
Joined: Friday 13 September 2013 0:24
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: PiFace support added

Post by RobinS » Saturday 19 October 2013 20:41

Hi Rob,

I am currently working on a generic sqlhelper function that will retrieve the last device value from the database.
When I have this function working, then I will need to look for a place to put it to work.
Maybe your solution is best, and I should retrieve the prev. data when initializing the Piface, however I need to examine if I will have access to the sqlhelper functions.
When implemented this will forsure fix the current PiFace issues, however the same issue is also applicable to all other meter devices...

The piface.conf file was added to the svn.
Did not autocreate the file as I found that it would bloat the code way to much, and default settings are applied anyway.. So the PiFace will function out of the box.
Please add it to the beta and new release archive.

Best Regards,

Robin
My domoticz setup:
PI [Doorbell on Audio out], DS1307 RTC, BMP085, PiFace [4* S0 meter, Doorbell In, PIR, GBS and Door sensors] and RFXCom 433 [5 HomeEasy, 2 Impluz]
2x P1 smartmeter on USB
Gammu-smsd with USB 3G modem
Andromoticz on control tablet

RobinS
Posts: 67
Joined: Friday 13 September 2013 0:24
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: PiFace support added

Post by RobinS » Tuesday 22 October 2013 20:39

As of version 1.1106 the following updates have been made to the PiFace functionality:
- During startup the last counter values are retrieved from the database, and the counters will continue at there last known value.
(eliminating the large glitches that were reported earlier)
- piface.conf is now automatically created when its missing. And will contain default settings for board address 0.

Best regards,

Robin
My domoticz setup:
PI [Doorbell on Audio out], DS1307 RTC, BMP085, PiFace [4* S0 meter, Doorbell In, PIR, GBS and Door sensors] and RFXCom 433 [5 HomeEasy, 2 Impluz]
2x P1 smartmeter on USB
Gammu-smsd with USB 3G modem
Andromoticz on control tablet

User avatar
Titanothere
Posts: 32
Joined: Tuesday 16 July 2013 1:21
Target OS: -
Domoticz version:
Contact:

Re: PiFace support added

Post by Titanothere » Wednesday 30 October 2013 11:34

Hello,
I installed the piface with domoticz yesterday. Great job, thank you for the neat integration work!!

This opens up very interesting possibilities.

I have one issue though : I use one output to ring my home bell. Unfortunately, all tough domoticz gets the info somebody pressed the door button (I get the Prowl notification right away), the bell rings about 30 seconds to 1 minute later.
To be complete : the Piface output switch is activated by a blocky event ("if button=on then ring=on").

Any idea as to why I have this time lag ?

RobinS
Posts: 67
Joined: Friday 13 September 2013 0:24
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: PiFace support added

Post by RobinS » Wednesday 30 October 2013 19:30

Titanothere wrote:Hello,
I installed the piface with domoticz yesterday. Great job, thank you for the neat integration work!!

This opens up very interesting possibilities.

I have one issue though : I use one output to ring my home bell. Unfortunately, all tough domoticz gets the info somebody pressed the door button (I get the Prowl notification right away), the bell rings about 30 seconds to 1 minute later.
To be complete : the Piface output switch is activated by a blocky event ("if button=on then ring=on").

Any idea as to why I have this time lag ?
Hi,

Thanks, glad you like it and find it usefull...
I am now finally using the PiFace myself since this weekend, as I already did the development but was not able to use it due to some missing preparations... (am planning to post my project)

Regarding your doorbell, I have connected my doorbell to the PiFace as well, but use a different setup as I use the Pi audio circuit to play a mp3 file, using a lua script... (unfortunately the Pi Audio is to weak to hear and my first attempt to an amplifier as well :( Now am waiting for a 15W amplifier from ebay 8-) )

one thing that I observed is that the events are processed quite fast (PiFace event are notified almost immediately to Domoticz), however the script execution fi the mp3 file lua is blocking and will hold up the entire event processing chain.
During my doorbell tests, I noticed that when I played my doorbell mp3 file, I could press any button as much as I wanted, the events were lost and only when the lua script with the MP3 playback was finished the events were processed again.
I solved most of it with shell background processing, so the MP3 file was played in the background (although most shell mp3 players do not like it), there still is a timeframe of a few seconds that events seem to be blocked.

I also linked a webcam snapshot to the doorbell, and also found that it blocked the event chain for a few seconds.
However I never noticed such large delays as you mentioned (only when playing back the MP3 file in the foreground).

So I think that you are experiencing sort of the same event blocking problems, and suggest that you temporary disable all other scripts, blockly handling, webcam snapshots and event notification to determine if it remains or not. If not then enable the other things step by step.

Best Regards,

Robin
My domoticz setup:
PI [Doorbell on Audio out], DS1307 RTC, BMP085, PiFace [4* S0 meter, Doorbell In, PIR, GBS and Door sensors] and RFXCom 433 [5 HomeEasy, 2 Impluz]
2x P1 smartmeter on USB
Gammu-smsd with USB 3G modem
Andromoticz on control tablet

User avatar
Titanothere
Posts: 32
Joined: Tuesday 16 July 2013 1:21
Target OS: -
Domoticz version:
Contact:

Re: PiFace support added

Post by Titanothere » Thursday 31 October 2013 0:32

Thank you for this clear answer.
I think you found the problem : I have also linked two camera pictures (one straight away, one 20 seconds later)... And since I am working on my house configuration that part of the network is down.
So I guess your explanation is right : the system must be waiting for some time-out to consider the picture stuff has been done, and then rings my bell :-)
I will remove the camera notifications and confirm if that was the issue.
Thanks again !

User avatar
Keptenkurk
Posts: 440
Joined: Wednesday 21 August 2013 17:24
Target OS: -
Domoticz version:
Location: Waalre, The Netherlands
Contact:

Re: PiFace support added

Post by Keptenkurk » Thursday 31 October 2013 1:01

Thanks Titanothere for bringing it up and Robins for feedback. I have the same experience but never related it to the webcam being triggered. My cam is online but still delays ringing the bell for upto 5 seconds... Will also try tomorrow (don't want to wake up the family with my experiments at this time).
/paul

User avatar
Titanothere
Posts: 32
Joined: Tuesday 16 July 2013 1:21
Target OS: -
Domoticz version:
Contact:

Re: PiFace support added

Post by Titanothere » Thursday 31 October 2013 2:20

By the way, I fiddled around some months ago with pi sound (to make the bell :-) ) but let go in front of the same problems you described before.
Let us know how it goes with your amplifier ! (I am also looking at getting a very loud siren (?) to push "visitors" out, but this is another story.

User avatar
Keptenkurk
Posts: 440
Joined: Wednesday 21 August 2013 17:24
Target OS: -
Domoticz version:
Location: Waalre, The Netherlands
Contact:

Re: PiFace support added

Post by Keptenkurk » Thursday 31 October 2013 9:34

The camera indeed spoils the fun!
I now have the following setup:
Doorbell button --> PiFace input-level (rising would only work every other push)
Blockly: If doorbell_button=on set doorbell_ringer=on
Doorbell ringer --> PiFace output off delay 1 (this make it sound like "ding"-1sec-"dong").
Camera triggers at Doorbell ringer (and not the button!) with delay 2 sec.

This will have the camera take the picture after the time critical things have been done.
EDIT: one strange thing: i now get 2 pictures taken with 2 seconds between them. :?

Maybe this camera communication could be done in background ?

btw The doorbell ringer is at the PiFace relay. The ringer coil induces huge sparks of which i'm not sure a PiFace output can stand :-)
/paul

RobinS
Posts: 67
Joined: Friday 13 September 2013 0:24
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: PiFace support added

Post by RobinS » Saturday 02 November 2013 19:12

Titanothere wrote:By the way, I fiddled around some months ago with pi sound (to make the bell :-) ) but let go in front of the same problems you described before.
Let us know how it goes with your amplifier ! (I am also looking at getting a very loud siren (?) to push "visitors" out, but this is another story.
Sure will post my results, but we both need to be patient as it can take upto 4 weeks from now for the stuff to arrive from hong kong :(
My domoticz setup:
PI [Doorbell on Audio out], DS1307 RTC, BMP085, PiFace [4* S0 meter, Doorbell In, PIR, GBS and Door sensors] and RFXCom 433 [5 HomeEasy, 2 Impluz]
2x P1 smartmeter on USB
Gammu-smsd with USB 3G modem
Andromoticz on control tablet

RobinS
Posts: 67
Joined: Friday 13 September 2013 0:24
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: PiFace support added

Post by RobinS » Saturday 02 November 2013 19:20

Hi Paul,

thanks for your work-a-round.
Keptenkurk wrote: Maybe this camera communication could be done in background ?
Agree on that.
I think that also the LUA and blockly processing should be done in the background, to make sure that the events are not delayed nor forgotton.
This is especially important if one wants to use domoticz as a security system.
I already have been looking into the event system to try to understand its workings and find my way around in its code.
Hopefully I can find the cause and fix it.

Best Regards,

Robin
My domoticz setup:
PI [Doorbell on Audio out], DS1307 RTC, BMP085, PiFace [4* S0 meter, Doorbell In, PIR, GBS and Door sensors] and RFXCom 433 [5 HomeEasy, 2 Impluz]
2x P1 smartmeter on USB
Gammu-smsd with USB 3G modem
Andromoticz on control tablet

bistoury
Posts: 158
Joined: Friday 12 July 2013 14:14
Target OS: -
Domoticz version:
Contact:

Re: PiFace support added

Post by bistoury » Saturday 02 November 2013 20:27

Hello,

firstly I would like to give a big thank you for piface support. It worth every penny :)

I'am using it to monitor my gas counter remotly (so with 2 pi's).

I have 2 questions for you :
1) I understand that for a 'gas type' counter, 'Status' should give a overall counter value.
As I plug Piface today, the 'status' value is equal to the 'today' value (quite logical, hey !) but I was wondering how to change the 'status' value to match my counter.
I can go in the DB or use sqlite, but I'd like to know if there's an official way to edit this parameter...

2) I can see that on both my master Pi and on my slave Pi, the 'status' value are identical. Good.
But it is not the case for 'today' value. As I linked the Master to the Slave several minutes after setuping the slave, there is a gap between the 2.
So here the master seems to live on its own... and does not reflect the slave values.
Is there a way to synchronize them for the 'today' value ?


Best regards,

bistoury.

RobinS
Posts: 67
Joined: Friday 13 September 2013 0:24
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: PiFace support added

Post by RobinS » Saturday 02 November 2013 23:07

bistoury wrote:Hello,

firstly I would like to give a big thank you for piface support. It worth every penny :)

I'am using it to monitor my gas counter remotly (so with 2 pi's).

I have 2 questions for you :
1) I understand that for a 'gas type' counter, 'Status' should give a overall counter value.
As I plug Piface today, the 'status' value is equal to the 'today' value (quite logical, hey !) but I was wondering how to change the 'status' value to match my counter.
I can go in the DB or use sqlite, but I'd like to know if there's an official way to edit this parameter...

2) I can see that on both my master Pi and on my slave Pi, the 'status' value are identical. Good.
But it is not the case for 'today' value. As I linked the Master to the Slave several minutes after setuping the slave, there is a gap between the 2.
So here the master seems to live on its own... and does not reflect the slave values.
Is there a way to synchronize them for the 'today' value ?


Best regards,

bistoury.
Hi Bistoury,

Good to hear that you have succeed with your cable and got your PiFace up and running with Domoticz and find the addon usefull.
Regarding your questions:

1) Actually I have been thinking about this same issue this afternoon.
As I have my PiFace running since almost a week now, I found the same annoyance.
Currently there is no way to 'official' way get a startup value for your meter other than 0...
You can use sqlite3, however you will need to make sure that you change the first value that is written to the DB, and thus will need to start domoticz, activate your meter, and
immediately stop domoticz and then manually change your value in the DB.
And make sure that there is only one value in the DB. If there are more, then you will get a spike in your registration like keptenkurk described some posts earlier.

As mentioned I have been thinking about adding a additional parameter in the piface.conf so the startup value can be set.
Such a value will then only be applied once there is no previous value for the meter in the DB.
Your request has pulled me across the line, so I will add it in the next couple of days/weeks or so.

2) Unfortunately I do not know how the master / slave functions.
The way the PiFace 'devices' function, exactly the same as RFXcom or related devices.
So I estimate that there is something wrong with the master / slave functionality. for which I hope that one of the other thread readers might be able to help you.

Best Regards,

Robin
My domoticz setup:
PI [Doorbell on Audio out], DS1307 RTC, BMP085, PiFace [4* S0 meter, Doorbell In, PIR, GBS and Door sensors] and RFXCom 433 [5 HomeEasy, 2 Impluz]
2x P1 smartmeter on USB
Gammu-smsd with USB 3G modem
Andromoticz on control tablet

User avatar
Titanothere
Posts: 32
Joined: Tuesday 16 July 2013 1:21
Target OS: -
Domoticz version:
Contact:

Re: PiFace support added

Post by Titanothere » Sunday 03 November 2013 1:03

Just a quick feedback on camera delaying ringing for a doorbell... The d on my side : I am afraid a deleted the camera rather than removing the picture sent. Hence the delay is still here, as well as the icon in front of the doorbell button. But this is no Piface issue, rather a domoticz/camera issue, I will post that in the issue topic.
I like your workaround Robin, thank you !
Talking about scripts running in background, I slightly remember an old thread saying that it was rather complicated and prone to lead to locked situations (what I readily believe : how would you handle two scripts running in background and dealing with the same objects ?). But I might be wrong, this would need some digging and more brain power : in other words, I am happy with Robin's workaround :-).

RobinS
Posts: 67
Joined: Friday 13 September 2013 0:24
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: PiFace support added

Post by RobinS » Sunday 03 November 2013 17:45

Titanothere wrote: Talking about scripts running in background, I slightly remember an old thread saying that it was rather complicated and prone to lead to locked situations (what I readily believe : how would you handle two scripts running in background and dealing with the same objects ?)
Hi Titanothere,

Having two processes accessing / controlling one object is indeed a tricky issue. However its also a common thing of multi threaded applications.
To control it one will need a MuTex (MuTual Exclusion).
A Mutex is a sort of programmatic traffic light that controls access to the resource / object and avoids problems with simultaneous use, as it requires all processes to wait for each other.
Formally the mutex code should be compact and non interrupt-able, so no so called race conditions can occur.
The mutex-ed object should be locked only as short as possible.

How to create and use a lock, depends on what you are using.
fi for Perl, Python, C, C++ or LUA mutex functionality is available.
For bash the default way is to use lock file, a bit like the pid files that linux creates for processes.

To control access to limited resources, semaphores are used.
They are basically a down /up count mechanism, that keep count of the usage, and when it reaches 0, all resources are depleted until some are released again.

Hope this info is a bit useful for you.

Best Regards,

Robin
My domoticz setup:
PI [Doorbell on Audio out], DS1307 RTC, BMP085, PiFace [4* S0 meter, Doorbell In, PIR, GBS and Door sensors] and RFXCom 433 [5 HomeEasy, 2 Impluz]
2x P1 smartmeter on USB
Gammu-smsd with USB 3G modem
Andromoticz on control tablet

bistoury
Posts: 158
Joined: Friday 12 July 2013 14:14
Target OS: -
Domoticz version:
Contact:

Re: PiFace support added

Post by bistoury » Monday 11 November 2013 23:47

Hello,

Just a Quick question on Piface.

Domoticz has just implemented french teleinfo interface which is basicly a serial data transmission coming from the electricity main counter. It consist of 2 wires, free of potential, to plug to a decoder that would read that serial interface.

Do you thing that piface can handle the job ?

Regards,

Bistoury
PS : there are some posts on the forum that délais with french teleinfo.

RobinS
Posts: 67
Joined: Friday 13 September 2013 0:24
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: PiFace support added

Post by RobinS » Thursday 14 November 2013 0:21

Hi Bistoury,

You are providing me with a bit of a riddle, as the information on the teleinfo is in french and so are some parts of the discussion on the forum regarding this subject..
And I do not understand french that much...

What I could make out of the information that you provided and the french info is the following: (please tell if I got it right)
- S0 type related meter with high and low tarif detection (and I guess separate outputs).
- Potentlal free contacts
- Pulse frequency 1 pulse per kwh ?
(judging from some calculations on the http://julien.manche.free.fr/maison/ele ... onique.php website the pulse frequency does not seem to be
that high) (please verify...)

The potential free contacts can be directly connected to the piface, one wire to the gnd, and one to an input pin, as the pullups on the piface IOs are switched on.
Depending on the number of pulses that the teleinfo gives, the piface will be able to count them (note that maximum usefull frequency is 5 Hz, higher is possible but less accurate .less is better and more accurate.)
If I interpreted the french stuff OK, then the pulse rate seems to be low, so the piface should be keeping up.

Note that normal S0 meters generally give an 1 pulse per watt, a 5Hz pulse freq would exceed the maximum powerbudget of a normal domestic power connection by a factor 2-3.
And as the Teleinfo seems to be a factor 1000 slower then no problems should be expected.

I am planning to start some additional developments (as indicated) to extend the PiFace functionality within the next 2 weeks or so, as soon as I finished automating the startup / shutdown of my servers to reduce there idle time (as hooking up the S0 meters to my PiFace scared the H*ll out of me in respect to my power consumption).

Best Regards,

Robin
My domoticz setup:
PI [Doorbell on Audio out], DS1307 RTC, BMP085, PiFace [4* S0 meter, Doorbell In, PIR, GBS and Door sensors] and RFXCom 433 [5 HomeEasy, 2 Impluz]
2x P1 smartmeter on USB
Gammu-smsd with USB 3G modem
Andromoticz on control tablet

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests