Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Motion Sensor - double trip Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
theowl
Groupie
Groupie
Avatar

Joined: February 24 2006
Location: United States
Online Status: Offline
Posts: 59
Posted: February 24 2006 at 09:47 | IP Logged Quote theowl

Hello!

Mission

I have a motion sensor by the front door(D7) and one outside the front door(D1). What I'm trying to do is write a macro that allows D7 to play different greetings/goodbyes depending on the status of D1. However, I also want the goodbye to only play if D7 is tripped twice.

Here's what I have, which seems to have a bug I can't find...

10 JUMP if(ph_getglobal_n("MOTIONFRONTDOOR") = 2,999,1)
20 JUMP if(ph_getglobal_n("MOTIONFRONTDOOR") = 1,60,1)
30 SET GLOBAL MOTIONFRONTDOOR 1
40 TTS "Debug Test 1 2 3"
50 JUMP 999
60 TTS "Debug Test 2"
70 SET GLOBAL MOTIONFRONTDOOR 2
80 SET SYSTEM [LOCAL1] if(ph_ismacrowaiting("MOTION-FRONTDECK") > 0,"013","014")
90 LAUNCH APP "C:\program files\hal\CompanionPrograms\RandomSpeak\randomspeak.exe [LOCAL1]"
100 TTS ph_readfile("C:\program files\hal\CompanionPrograms\RandomSpeak\Speak[LOCAL1].txt")
110 Wait 60
120 SET GLOBAL MOTIONFRONTDOOR 0

I know the issue is something simple, and there may even be an easier way to do all this. I have yet to figure out why I can get the macro to execute up to 50, but never go over that even with the jumps that I have.

Any ideas?
Back to Top View theowl's Profile Search for other posts by theowl
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: February 24 2006 at 13:13 | IP Logged Quote dhoward

The error you have where you cant get past line 60 is in the Jump statement on line 20. You want to change the 60 to a 4. The jump statement is relative to the current location and is the number of line forward or back you wish to jump. You can use the Label and Goto Label commands if you wish to just to specific locations.

You can also replace your first two statements with this line:

Code:
10 JUMP case(ph_getglobal_n("MOTIONFRONTDOOR") when 0 then 1 when 1 then 4 when 2 then 999)


I don't see D1 or D7 referenced anywhere in your macro so don't know what your triggers may look like or not. Basicaly, I would have triggers for both D1 and D7 and then use the ph_getx10dt and the ph_minutesafter functions to determine how long ago one motion sensor was triggered in reference to the other.

HTH,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
theowl
Groupie
Groupie
Avatar

Joined: February 24 2006
Location: United States
Online Status: Offline
Posts: 59
Posted: February 25 2006 at 02:30 | IP Logged Quote theowl

Well, don't I feel stupid. I bet I would have found out the problem if I RTFM, huh?

I tried doing something with ph_getx10dt(D,1), but could not get any type of response from it at all. After the last 30 minutes or so, I just decided to go with the case statement you suggested and everything started working fine.

Thanks

Once I get some stuff done around here, I'll post some fun codes that I think people might like. My current favorite is a little vbscript that fetchs different types of jokes from a site and reads them back. Basically, I'm attempting to set-up PH so it takes over all the stuff I currently ask Hal to do...so far so good!

BTW: Aprox how many lines of code do you figure PH is made of before all the macros and formulas are added by others?
Back to Top View theowl's Profile Search for other posts by theowl
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: February 27 2006 at 00:56 | IP Logged Quote dhoward

Lines of code....Hmmmm...Thats not easy to come up with in the PowerBuilder environment. However, the source modules of PowerBuilder code are just over 10 meg. That's not including the modules that are written in C, C++, etc.

If I had to make a rough guess though, I would say on the order of 200,000 lines .

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
theowl
Groupie
Groupie
Avatar

Joined: February 24 2006
Location: United States
Online Status: Offline
Posts: 59
Posted: February 27 2006 at 17:56 | IP Logged Quote theowl

That's a lot of code...and it shows with the quality of this program. Awesome Job!

Any idea why I couldn't get any responce from ph_getx10dt(D,1)? I tested it in several ways, but the debug version went something like...

ph_tts(ph_getx10dt(D,1))

Then, I used a remote to switch D1 on and then on again. Nothing happened, so I tried D1 on, D1 off, D1 on...pausing about a second between each send. I was guessing that the dt would not be reset until the motion stopped (off) and started again (on). No matter what configuration I tried it in, just couldn't get anything to work with that.

Thanks
Back to Top View theowl's Profile Search for other posts by theowl
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: February 27 2006 at 18:01 | IP Logged Quote TonyNo

Syntax:

ph_getx10dt( house, unit )

Argument Description:
house A string equating to the housecode from which you wish to retrieve the datetime of the last status change.

unit An integer equating to the unitcode from which you wish to retrieve the datetime of the last status change.


So, for D1, you need to use ph_getx10dt( "D", 1 ).
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: February 27 2006 at 18:39 | IP Logged Quote dhoward

Heh,

This also depends on the version of PowerHome you're running. If you're running version 1.03.4.4 or earlier, then Tony gave you the correct syntax. If you're running later than 1.03.4.4 then the syntax is:

ph_getx10dt(id) where id is the ID you've entered for your X10 device in the X10 Units screen. So if your ID for housecode D, unitcode 1 were KITCHENLIGHT, then you would use ph_getx10dt("KITCHENLIGHT")

HTH,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: February 27 2006 at 19:55 | IP Logged Quote TonyNo

Ah ha! I need to update my help file at the office!
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
theowl
Groupie
Groupie
Avatar

Joined: February 24 2006
Location: United States
Online Status: Offline
Posts: 59
Posted: March 02 2006 at 17:05 | IP Logged Quote theowl

I'm stilling trying to get my head around this ph_minutesafter thing. I'm trying a line like this...

ph_minutesafter(ph_getglobal_dt("MOTIONFRONTDOOR"),ph_getx10 dt("D",7))

Within MOTIONFRONTDOOR, I'm storing the last time D7 had been switch on.

In theory, I should be getting back the minutes between the last time D7 came on and this time. Instead, I'm getting 55838390.43083333 when I test this line. Perhaps I just need to read more on it, but is this returning minutes or ticks?

I do recall something in the manual about the previous dt already being stored somewhere...so I'm off to check that out.
Back to Top View theowl's Profile Search for other posts by theowl
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: March 03 2006 at 11:42 | IP Logged Quote dhoward

A couple of things.

ph_getx10dt takes a single parameter, the ID of your X10 device. If your X-10 device at HC "D", UC "7" has an ID of D7 then the command would be ph_getx10dt("D7"). This was probably just a typo because you would ohave gotten a "!" if it was typed this way and I just want to clarify for others following the thread.

Where the problem most likely lies is in the "MOTIONFRONTDOOR" global variable. In order for the ph_getglobal_dt function to interpret the data correctly as a datetime, the data must appear in the following format:

Code:
yyyy-mm-dd hh:mm:ss


You can optionally have a .fff following the ss portion for fractional seconds. Most functions should automatically save to a global in this format and the ones that don't can be forced to by using the string function with the above code as a format mask.

If the global is not in the proper format, then the datetime returned will be 01/01/1900 00:00:00. This value would correspond with the grossly huge number you received above.

Let me know,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum