X10 Community Forum

🖥️ActiveHome Pro => Plug-ins => Smart Macros => Topic started by: troll334 on January 31, 2011, 10:56:53 AM

Title: Need more than 16 flags?
Post by: troll334 on January 31, 2011, 10:56:53 AM
Hey Guys,
I've run out of flags. Needing more, I walked into the think-tank.
Remember that binary numbering system?  Someone back in '05 eluded
to using multiple flags for testing conditions. So I thought I'd
expand on that for anyone that needs more than 16 flags.
Admittedly, this will require you to document your macros lest ye
be caught in a whirlpool of numbers downing in your own creativity :)
Switch your mindset to binary and realize up to 65,536 flags (2^16)!
Though I don't think I've experienced this...for those of you
concerned about AHP using flags 15,16 for dawn/dusk, that would
still leave you with 14 flags (16,384) with which to apply to the
binary method.
So, here we go:
Flag 1 remains flag 1.
Flag 2 remains flag 2.
This is where it starts to change.
The third new flag (binary 0011) is now Flags 1 and 2 both set.
The fouth new flag (binary 0100) is now Flag 4 (only) set.
The fifth is now Flags 4 and 1 both set.
And so on...ad infinitum (well, almost)
Decimal to binary conversion is beyond the scope of this posting.
Suffice it to say, if you want to learn some binary, you'll get
all the flags you'll ever need and then some.
And yes, you could use some dummy modules along with the binary
thing and work more pseudo flags than your PC's addressing system
can likely handle; at least in our lifetimes :). Another story...
have fun!
Title: Re: Need more than 16 flags?
Post by: Noam on January 31, 2011, 11:10:54 AM
Hey Guys,
I've run out of flags. Needing more, I walked into the think-tank.
Remember that binary numbering system?  Someone back in '05 eluded
to using multiple flags for testing conditions. So I thought I'd
expand on that for anyone that needs more than 16 flags.
Admittedly, this will require you to document your macros lest ye
be caught in a whirlpool of numbers downing in your own creativity :)
Switch your mindset to binary and realize up to 65,536 flags (2^16)!
Though I don't think I've experienced this...for those of you
concerned about AHP using flags 15,16 for dawn/dusk, that would
still leave you with 14 flags (16,384) with which to apply to the
binary method.
So, here we go:
Flag 1 remains flag 1.
Flag 2 remains flag 2.
This is where it starts to change.
The third new flag (binary 0011) is now Flags 1 and 2 both set.
The fouth new flag (binary 0100) is now Flag 4 (only) set.
The fifth is now Flags 4 and 1 both set.
And so on...ad infinitum (well, almost)
Decimal to binary conversion is beyond the scope of this posting.
Suffice it to say, if you want to learn some binary, you'll get
all the flags you'll ever need and then some.
And yes, you could use some dummy modules along with the binary
thing and work more pseudo flags than your PC's addressing system
can likely handle; at least in our lifetimes :). Another story...
have fun!


That sounds like a great idea, but I've heard some people recommend avoiding flag #1, too (leaving you with only 13 usable flags - or 8192 possible binary numbers - which should still be plenty).

However, what happens if you need to use more than one flag at the same time?
How would you represent, for example, that flags #1 and 2 are on?

binary 01 is flag 1, and binary 10 is flag 2. If both are on, you get binary 11, which is the same as binary flag 3.

That could be a problem.

Have you thought of a way to overcome this?
Title: Re: Need more than 16 flags?
Post by: HA Dave on January 31, 2011, 11:39:31 AM
I've run out of flags. Needing more, I walked into the think-tank.
Remember that binary numbering system?  ..................
Flag 1 remains flag 1.
Flag 2 remains flag 2.
This is where it starts to change.
The third new flag (binary 0011) is now Flags 1 and 2 both set.
The fouth new flag (binary 0100) is now Flag 4 (only) set.
The fifth is now Flags 4 and 1 both set.
And so on...ad infinitum (well, almost)

troll334 that is brillant!!! Of course... a HELPFUL from me. It would be nice to see some tests and more details about setting this up... for those of us like myself that went to state run schools. And... is there anyway I could spend some time in your think-tank?  It sounds like the place to be. This reminds me of.... relays and punch cards?

I think this may be just the idea needed to get S.A.R.A. (http://davesdomainonline.com/sara/sara.htm) moving.
Title: Re: Need more than 16 flags?
Post by: Brandt on January 31, 2011, 12:15:05 PM
You would have to set multiple flags for each condition

Example to use "Flag" 25: ( 00011001 ):

IF ( Flag1 && Flag4 && Flag5 ) isSet; THEN turn on TV;

So you need to take care of un-setting the flags after you are done checking them.
Title: Re: Need more than 16 flags?
Post by: Noam on January 31, 2011, 12:37:15 PM
You would have to set multiple flags for each condition

Example to use "Flag" 25: ( 00011001 ):

IF ( Flag1 && Flag4 && Flag5 ) isSet; THEN turn on TV;

So you need to take care of un-setting the flags after you are done checking them.

How do you tell is 00011001 is flag "25" or if it it both flag "24" (00011000) and flag "1" (00000001) both being on at the same time?
Title: Re: Need more than 16 flags?
Post by: troll334 on January 31, 2011, 01:25:57 PM
Hey Noam, Dave.
Talk about brilliant...I need Noam in the think-tank as well :)
You are correct about that flaw. I just fired the guys in the think-tank (me).  B:(
It doesn't matter what you try, there always seems to be the possibility of a duplicate...e,g,. if you want to use
new flag 81 (binary 01010001) and test on new flag 17 (binary 00010001), it'll be true. Even if you tried using the
AND operator (xor) to test for "Flags Set AND Flags Cleared", you'll still end up with conflicts.
So, we're back to 16 flags but still able to use phantom modules (on the monitored HC) in conjunction. So, what does
that give us? 256 possibilities (assuming you've got no real devices on the monitored HC)? Nope, not even...
Back to the drawing board on this one.
Noam  #:)
sorry Dave. Take back that Helpful. I screwed the pooch on that one.
Title: Re: Need more than 16 flags?
Post by: Brandt on January 31, 2011, 01:59:03 PM
since when does AND = XOR? it doesn't. If you AND them all together properly, I don't see why it wouldn't work...


You would have to do something like this (not exact syntax):

FLAG25=((Flag1 && Flag4 && Flag5 ) && (!(Flag2 && Flag3 && Flag6 && Flag7 && Flag8)))

FLAG25 being some sort of environment variable in Windows.
Title: Re: Need more than 16 flags?
Post by: HA Dave on January 31, 2011, 02:56:55 PM
.......  sorry Dave. Take back that Helpful. I screwed the pooch on that one.

I only feel sorry for the pooch. And... I think Brandt has a point as well.

I use a pencil and paper as well as a calculator just to balance my checkbook.... and that requires far smaller and fewer numbers. So I am sure the math is over my head. But if only 4 of the 16 monitored addresses was used in combination with the 16 flags with the "and"... in my mind... that sounds like 16X4 new addresses right there. Not that they haven't ALWAYS been there. Just not thought of as a method to use them.
Title: Re: Need more than 16 flags?
Post by: Noam on January 31, 2011, 02:58:48 PM
since when does AND = XOR? it doesn't. If you AND them all together properly, I don't see why it wouldn't work...


You would have to do something like this (not exact syntax):

FLAG25=((Flag1 && Flag4 && Flag5 ) && (!(Flag2 && Flag3 && Flag6 && Flag7 && Flag8)))

FLAG25 being some sort of environment variable in Windows.

If you don't mind leaving your CM15A tethered to the PC, and leave AHP running all the time, then you CAN, theoretically, have an unlimited number of flags.
Instead of using flags, just create macros that set environment variables (easier to do now that we can pass command line parameters from a macro).
Then, write a scrip that uses those environment variables, and have it run whatever commands you want (either calling other AHP macros, or just send them one at a time using AHCMD).
Title: Re: Need more than 16 flags?
Post by: Brandt on January 31, 2011, 03:00:43 PM
+1 on that Noam. I'm all about scripts ;)
Title: Re: Need more than 16 flags?
Post by: HA Dave on January 31, 2011, 03:16:59 PM
..........  If you don't mind leaving your CM15A tethered to the PC, and leave AHP running all the time, then you CAN, theoretically, have an unlimited number of flags.
Instead of using flags, just create macros that set environment variables (easier to do now that we can pass command line parameters from a macro). Then, write a scrip that uses those environment variables,...

+1 on that Noam. I'm all about scripts ;)

Didn't someone... ihouse(?) already include an all X10 addresses monitoring in their software? Or... is this a new software opportunity? I know there was a time when many people bulked at running a PC 24/7... or hesitated at trusting HA functions to a computer. But I think... those days are behind us. Software products and Home Automation... are one and the same... IMHO.
Title: Re: Need more than 16 flags?
Post by: troll334 on January 31, 2011, 04:28:17 PM
Hey Gents,
Brandt, I'm sure AND = XOR on the other side of some worm-hole :) But, in our world, of course, AND != XOR.
Having said that, my use of XOR was a lame attempt at implying the use of a masking technique by including
"AND Flags x,y,z NOT SET" along with the ones of interest. But that still doesn't cut it, thanks to Noam's exploration
of the idea. Further, I was attempting to keep flag usage inside of AHP w/o shelling out the the OS. Should
have stated that. Further, the idea of using monitored HC's / phantom modules does not appear to work either.
It's logic too, fails almost immediately.
I'll shut up until I have something good and proven to work (inside AHP w/o shelling out).
have a great day!
Title: Re: Need more than 16 flags?
Post by: Fan of Zappa on May 14, 2011, 04:32:49 PM
Hey guys,
We all seem to be running out of flags. I've been working on a batch file, but I don't know how to implement it into AHP. To use it the command is FLAG SET/CHECK/CLEAR FLAGNUMBER . Make sure you set the drive and directory in the Flag.bat file before running from the command line. Flag.bat must reside in the parent directory of \flags. If you guys can figure out how to pass the flag info to AHP we can all have all the flags we want.

@echo off
Rem Flag.bat  by Bob Barr (Fan of Zappa)

set Flagdrv=C:
set flagdir=\House stuff\flags\

rem if %1 == NUL Goto usage - not working yet.... I'm stupid sometimes
if %1 == set Goto set
if %1 == clear Goto clear
if %1 == check goto check

:set
cd %flagdir%
copy flag0.txt flag%2.txt
goto end

:clear
cd %flagdir%
del flag%2.txt
goto end

:check
cd %flagdir%
rem if exist flag%2.txt (echo Flag%2 is set) else echo flag%2 is clear.
if exist flag%2.txt goto true else goto false

:false
echo flag%2 is clear
goto end

:true
echo flag%2 is set
goto end

:usage
echo flag set/clear/check num (1-256)

:end
cd..



Well that's it. It may be amateurish but it will set a flag, clear a flag, and check the state of a flag.

-Bob
Title: Re: Need more than 16 flags?
Post by: Fan of Zappa on May 14, 2011, 04:41:11 PM
Forgot one very important thing. Sorry! The file "flag0.txt which must be in the flags directory was created in notepad and contains only the word "set". But it could contain anything as long as there is a file there names flag0.txt
Title: Re: Need more than 16 flags?
Post by: ITguy on May 14, 2011, 05:26:55 PM
Very creative!

Another option is to just switch to iHouse!  An UNLIMITED number of flags, and allows flag "values" of anything you want, instead of just on or off!  It's open-source and available for download FREE at: http://www.ihousehomeautomation.com/phpBB/viewforum.php?f=33 (http://www.ihousehomeautomation.com/phpBB/viewforum.php?f=33)

And Dave_x10_L, you're right about the monitoring! 

ITguy
Title: Re: Need more than 16 flags?
Post by: Alish on May 16, 2011, 06:50:56 AM
Very creative!

Another option is to just switch to iHouse!  An UNLIMITED number of flags, and allows flag "values" of anything you want, instead of just on or off!  It's open-source and available for download FREE at: http://www.ihousehomeautomation.com/phpBB/viewforum.php?f=33 (http://www.ihousehomeautomation.com/phpBB/viewforum.php?f=33)

And Dave_x10_L, you're right about the monitoring! 

ITguy

ya iHouse solution is also the better option. They have unlimited number of flags, and there is also no restriction to catch values of anything. Nice link. Thanks for sharing it here.
Title: Re: Need more than 16 flags?
Post by: ErikP on May 16, 2011, 03:03:13 PM
Technically no matter what software you have, there is still only 16 flags physically in the CM15A.  I don't have anything to do with iHouse but I would bet their flags work more like Noam's environment variables suggestion than AHP's flags, and need the computer connected to the controller to function.

The binary count works if you need to track state instead of a series of flags.  you could use 4 flags to set up 2 binary values with 4 states each (00, 01, 10, 11).  You have to fully verify the state of each flag used as a bit when you check, and you can't reuse the same flags/bits across multiple states, but otherwise the idea is sound.  Not everyone's conditions can benefit from this type of compression but I'm sure at least a few can.  The tricky part is recognizing when you are really saving bits, and when you are just lumping conditions.