Author Topic: Enable/Disable a Rule from another Rule?  (Read 2883 times)

mikedj

  • Jr. Member
  • **
  • Posts: 49
    • View Profile
Enable/Disable a Rule from another Rule?
« on: September 12, 2010, 02:43:49 pm »
Is there a way to set the Enabled/Disabled status of a rule from another rule?  I would like to be able to enable or disable a rule via a received X10 command.  I don't know how to write scripts, yet, but was wondering about something like this?

RuleIdentifier.Disabled(true);

However, I don't see a Scripting Identifier displayed for rules, only for scenes.  And it doesn't appear scenes can be enabled/disabled.

I do note that Actions can be manually disabled within a scene.  Could that be done via a script?  If so, how would you set enabled/disabled parameter of the action?  Something like this?

SceneName.Action#.Disabled(true);

I tried poking around in the scripting window to try this, but I didn't get very far.

Thanks,
Mike

John Hughes

  • Administrator
  • Hero Member
  • *****
  • Posts: 2852
    • View Profile
    • Codecore Technologies
Re: Enable/Disable a Rule from another Rule?
« Reply #1 on: September 12, 2010, 08:11:27 pm »
Disabling a device can not be done via script. What you will likely want to do is set a global variable and have your rule check the variable state using a condition. So for example you could set a variable called "disableRuleX" to true or 1 or whatever you like and then in the 1st action of your rule you would check the value and only execute the rest of the rule if the variable isn't set to true or 1, etc.
John Hughes
Codecore Technologies

mikedj

  • Jr. Member
  • **
  • Posts: 49
    • View Profile
Re: Enable/Disable a Rule from another Rule?
« Reply #2 on: September 13, 2010, 07:15:13 am »
This worked fine.  It takes a few more steps than if scripting allowed it directly, but it does work.  One other down side is that I assume it will lose its state if the system is restarted.  Here's what I did:

Create a variable using the Global Variables Device called disableWakeupLights, setting its initial value to false.

Create a new Rule to disable via X10 Received:  When an X10 OFF command is received, set the variable to true with this script: vars.disableWakupLights = true;
Create a new Rule to enable via X10 Received:  When an X10 ON command is received, set the variable to false with this script: vars.disableWakupLights = false;

Then, in the Action for the WakeupLights Rule, use a conditional statement that says if the Global Variable disableWakupLights is false, execute the actions to turn on the lights.

Thanks,
Mike

John Hughes

  • Administrator
  • Hero Member
  • *****
  • Posts: 2852
    • View Profile
    • Codecore Technologies
Re: Enable/Disable a Rule from another Rule?
« Reply #3 on: September 13, 2010, 09:22:44 am »
I assume it will lose its state if the system is restarted.


No, the global variables driver DOES support persisting values between reboots and it will do so unless you have changed the 'Persist Variables' setting on the device.  You should also specify the initial value to make sure the variable exists (which it should if you are persisting it).
John Hughes
Codecore Technologies

mikedj

  • Jr. Member
  • **
  • Posts: 49
    • View Profile
Re: Enable/Disable a Rule from another Rule?
« Reply #4 on: September 13, 2010, 09:44:25 am »
That's great.  It accomplishes exactly what I need.

Thanks,
Mike

John Hughes

  • Administrator
  • Hero Member
  • *****
  • Posts: 2852
    • View Profile
    • Codecore Technologies
John Hughes
Codecore Technologies