Reactor Ex Machina II (2023-July Update)
-
Here is an updated Reactor Ex Machina that works with new features of Reactor that have been added since the earlier post. It now can be done a single rule, thanks to the Repeat...While action in reactions.
The easiest way to get this new version is to grab the rule data (bottom of this post) and save it with the name
rule-reactorexmachina.json
(exactly this; no changes) in yourstorage/rules/
subdirectory. Then restart Reactor. After restart, you will find the Reactor Ex Machina II rule in a Recovered Rules rule set. You can move it to whatever other rule set you like. You may see an error for theREM_lights
variable (global) missing; don't worry about that right now, we'll handle that in a moment.To configure it, you need to do two things (and maybe a third optional thing):
- Create a global variable/expression called
REM_lights
that defines an array containing the canonical IDs of the lights you want it to manipulate. This is as it was for the previous version of REM, so you may already have that, and what you have is probably fine. If you don't have it, your expression should look like this to define the array of lights:
-
You need to configure the conditions in the Triggers of the new rule to be true when you want lights to randomly cycle. This is called the active period, and the default configuration is from 30 minutes before sunset to 23:30 (just as a placeholder).
-
(OPTIONAL) Change the timing by modifying the two Delay actions. The Delay action in the Set Reaction is for when lights are being toggled while in the active period. In the Reset Reaction, the delay controls the timing of lights shutting off at the end of the active period (i.e. to simulate going to bed, which may be more rapid). The formula for computing the delay is
random()*range + minimum
(seconds). As an example,random()*840 + 60
would give a random delay of 60 to 900 (840+60=900) seconds (which is 1 to 15 minutes) between actions.
Operation is pretty straightforward and greatly simplified by the new Reactor features. When the rule is SET (i.e. triggers true, in the active period), the Set Reaction starts an infinite loop that picks a random light from
REM_lights
and toggles it, then delays a random amount of time. That continues until the triggers are no longer true and the rule RESETs. The Reset Reaction then runs (automatically cancelling the Set Reaction task), turning off a light that is currently on (from among those inREM_lights
again) and then delaying, repeating until all lights are off.Here's the rule JSON data:
{ "id": "rule-reactorexmachina", "container": "rules", "value": { "id": "rule-reactorexmachina", "serial": 44, "triggers": { "type": "group", "id": "trig", "op": "or", "conditions": [ { "type": "group", "id": "grp13uaq1lz", "op": "and", "conditions": [ { "id": "cond13uaq1m0", "type": "comment", "data": { "comment": "Here, put in the rules for when random lights should cycle... time of day, house mode, virtual switch/input boolean state, etc." } }, { "id": "cond13uaq1m2", "type": "sun", "data": { "tzo": 240, "op": "after", "start": "sunset", "start_offset": -30 } }, { "id": "cond13uaq1m3", "type": "trange", "data": { "op": "before", "start": { "hr": 18, "min": 45 }, "tzo": 240, "end": {} } } ], "editor_version": 23130, "name": "Active Period" } ], "editor_version": 23130, "disabled": true }, "constraints": { "type": "group", "id": "cons", "op": "and", "conditions": [] }, "expressions": { "dummy": { "name": "dummy", "expr": "", "index": 0 }, "lights_on": { "name": "lights_on", "expr": "each light in REM_lights: do e=getEntity( light ), e.attributes.power_switch.state ? e.canonical_id : null done", "index": 1 } }, "name": "Reactor Ex Machina II", "react_set": { "id": "rule-reactorexmachina:S", "actions": [ { "id": "rule-reactorexmachina:S-13ua1p95", "type": "while", "actions": [ { "id": "13u9qo3b", "type": "comment", "data": { "comment": "Toggle a random light in the list of lights" } }, { "id": "8wul3as", "type": "setvar", "data": { "var": "dummy", "rule": "rule-reactorexmachina", "value": "${{ performAction( REM_lights[ floor( random() * len( REM_lights ) ) ], 'toggle.toggle', {} ) }}", "reeval": false } }, { "id": "13u9py8u", "type": "comment", "data": { "comment": "Delay random to next light toggle" } }, { "id": "8wul3ew", "type": "delay", "data": { "delay": "${{ random()*840 + 60 }}" } } ], "constraints": { "id": "13ua1p95-cons", "name": "Active", "type": "group", "op": "and", "conditions": [ { "id": "cond13uaycbu", "type": "comment", "data": { "comment": "The below is a dummy condition that's always true if your REM is configured (i.e. it has lights to operate on)" } }, { "id": "cond13ua1smv", "type": "var", "data": { "var": "REM_lights", "op": "notempty" } } ], "editor_version": 23130 } } ], "rule": "rule-reactorexmachina", "editor_version": 23130 }, "react_reset": { "id": "rule-reactorexmachina:R", "actions": [ { "id": "rule-reactorexmachina:R-13uagam7", "type": "while", "actions": [ { "id": "13uagcg8", "type": "comment", "data": { "comment": "Turn off a light that's on. Then delay random to next light off. This continues until all lights are off (condition above)." } }, { "id": "13uagut5", "type": "setvar", "data": { "var": "dummy", "rule": "rule-reactorexmachina", "value": "${{ performAction( lights_on[0], \"power_switch.off\" ) }}", "reeval": false } }, { "id": "13uah4lh", "type": "delay", "data": { "delay": "${{ random()*270 + 30 }}" } } ], "constraints": { "id": "13uagam7-cons", "name": "Shutdown", "type": "group", "op": "and", "conditions": [ { "id": "cond13uagex0", "type": "var", "data": { "rule": "rule-reactorexmachina", "var": "lights_on", "op": "notempty" } } ], "editor_version": 23130 } } ], "rule": "rule-reactorexmachina", "editor_version": 23130 }, "ruleset": "rs-remII" }, "tss": 1689548165797, "tsc": 1689548165797 }
- Create a global variable/expression called
-
@toggledbits Being the impetus for recreating this from the old days of Vera I love this "REM: TNG".
-
T toggledbits locked this topic on