Wow ! PLEG is really complete (I had not yet read the documentation).
When I started writing scripts for managing my HA, the things that have seemed to me the most important were :
to succeed to have an overview of the implemented rules/scenarios.
to simply make a backup of these rules, even to export them to another system.
(if you change your system, the only thing that you really need is “but how it worked ?”).
I have tried PLEG (free version), but I’ve not found how I will fill these two conditions.
So… what is your initial need concerning sequence expressions ?
You want to create sub-conditions and make a main condition depending from the temporal sequence of these ?
It could be :
a new block of list of conditions (like “one is true”, “all are true”) defining the time to respect between each conditions.
a new block of conditions, visually resembling the block “do”, where you can order conditions and add a block “after x seconds” between two conditions.
It departs somewhat of the standard to define an “If” block.
After playing with things a few days, the rules engine seems great for stateless scenarios, and PLEG is well suited to situations with a lot of state. Sequences is maybe a simple state scenario, but I’m finding for a lot of lighting control scenarios its a bit hard to do without some sort of state information.
For example, I have patio lights that are turned on/off when the door opens at night after some time has elapsed. Works great. The issue is those lights can be turned/off from a number of sources like an Echo or a switch. In those cases, you don’t want the timer to turn off the lights automatically if you manually turned them on. You could explicitly check the state of the lights, but if you don’t have instant status on the switches its problematic, and if you use a scene its even more painful as you’d potentially have to check many lights. Not sure there is a easily solution to this other than to add all possible control sources into the rule.
I’ve not yet thought of a good way to capture these scenarios efficiently. In the past I have used multi-variable string blocks to store state for air conditioners so multiple things can update them, and then update those changes to the thermostat from there (ensuring you track the state), but thats a nasty way to solve this problem.
You can have a kind of state with “level”.
If you set a level on a condition (in condition params), you will be able to define actions that are executed when the level changes.
For your need of managing your patio lights, you should look at the plugin Smartswitch, which does exactly what you want (I use it).
You can create a rule to change the auto timeout on day and set it on zero, if you want just auto switching during night.
One of the best examples I can give you is that of utilising the Sequence expression to determine direction of travel along a path, for example I have several lights along a corridor, staircase and upstairs corridor.
The Sequence to turn on the lights as you progress from Downstairs to Upstairs is controlled by motion sensors (M).
Entering at Night by the Front door D1;M2 Turns on the Stair Light,
D1;M2;M1 turns on the downstairs, whilst D1;M2;M3 turns on the upstairs.
The opposite M2;D1 Turns on the outside light only when the entry door is open.
To test if see if the CFL is Off and if it is and the 2 conditions occur in order turn on the CFL are
cUpstairsPassageCFLOff and (cUpstairsPassageCFLOff;tStudyCFL)
To turn off the Upstairs LED the following is used.
tPassageLEDisOn and (tPassageLEDisOn;Now>2:00)
[size=1em]
[font=verdana]It first tests to see if the LED is On and if it is then the sequence commences a 2 min. timer to turn off the led.[/font][/size]
[size=1em][font=verdana]I’m not sure how adaptable Blocky is hence the question?
[/font]
[/size]
Here is a try with Blockly to implement sequence of conditions.
In this example, the rule is active when :
(time is between 08:00 and 20:00)
AND
( condition sequence :
item 1 : (
(Device “VirtualSwitch 1” in Room 1 is on since 5 seconds)
OR
(One device in Room 2 is on since 5 seconds)
),
item 2 : (One security sensor is tripped in room 2);
is true when “item 2” is true, 30 seconds after that “item 1” became true.
)
[quote=“RichardTSchaefer, post:87, topic:189418”]Both are supported:
The Status/Report command
The PLEG Backup/Restore command.
You can’t import to a new system because Inputs and Output bindings would not be valid. But the logic would be.
I would luv to put in a Visual editor if I could find one that can express what PLEG is capable of.[/quote]
I’ve tried PLEG some years ago (ouch time flies…) and great progress has certainly been made since.
When I’ve begun the RulesEngine plugin, I wanted to do a simple UI, allowing to create easily some rules.
It was not designed at the beginning to cover all the needs. Looks like it is starting to become a bit more complicated.
I don’t want to replace PLEG plugin, which is more powerfull, and needs some developer skills.
the plugin RulesEngine is becoming more stable (even if there are still some bugs)… but it remains lot of work on scalability and robustness.
Even if I have spent some time on it, it’s a good thing to look around sometimes… and I’ve just seen Nore-Red + MQTT…
Ouch :o
I will try that this week-end and report next week.
[quote=“vosmont, post:90, topic:189418”]Hello all,
the plugin RulesEngine is becoming more stable (even if there are still some bugs)… but it remains lot of work on scalability and robustness.
Even if I have spent some time on it, it’s a good thing to look around sometimes… and I’ve just seen Nore-Red + MQTT…
Ouch :o
I will try that this week-end and report next week.
a quick and brute force jointjs integration with altui… we could build a workflow data structure and manage this , as a state machine, in the lua backend…
[quote=“amg0, post:91, topic:189418”][quote=“vosmont, post:90, topic:189418”]Hello all,
the plugin RulesEngine is becoming more stable (even if there are still some bugs)… but it remains lot of work on scalability and robustness.
Even if I have spent some time on it, it’s a good thing to look around sometimes… and I’ve just seen Nore-Red + MQTT…
Ouch :o
I will try that this week-end and report next week.
a quick and brute force jointjs integration with altui… we could build a workflow data structure and manage this , as a state machine, in the lua backend…[/quote]
Yes. Sexy.
I’d think you need three entry methods, the state machine flow thru what you’ve shown above. Some sort of combinatorial/logic flow (like blocky) for the arrows (transitioning states), and something simple to allow actions for a given state/input.
I’ve played a little with Node-RED and here are my feelings :
easy to install (even on Windows)
really powerfull, it seems that you can do what you want… but you have to have developer skills if you want to go further.
the tabs for event workflows look great but if you want to know what a node does, you have to click on it.
It’s ok for simple workflow, but for a complex with a lots of device, it’s not easy (e.g. the name of the box will by the MQTT event)
My conclusion (for the moment, it changes all the hours) :
Put all your rules on Vera’s devices in Node-RED will be a nightmare. You have to put the id of the devices in the MQTT boxes.
Creating a helper for Node-RED for exposing the ids is not a good idea (there’s no need to recreate the Vera outside).
Node-RED seems to be excellent to process high-level messages (e.g. “alarm is ON”, “someone is in living-room”, …)
If you want to include the Vera in a system managed by Node-RED, the Vera should be able to generate and handle MQTT functional messages (without reference to the id of the devices).
So it seems to me that Node-RED is not the solution to handle rules directly linked to devices.
OK, for an easy solution, RulesEngine is still an option.
Rules are simple state machines, storing a status and a level (changed by the level of the active conditions).
It should cover main of the simple needs. I don’t think I will go further with workflows (and graphes).
So comming next on RulesEngine :
Sequences of condition (if the POC works)
MQTT messages in conditions and actions, so it will be easy to define local rules on the Vera dealing with devices, and manage complex scenario outside.
Just a word on Vera’s community : it seems that there are a lots of new things currently
Great !
Im currently running Rules engine on openLuup on a Raspberry Pi 3. I can create rules but they don’t appear to run. I enclose screen shot of the device which shows the state. I can slide the on /off switch to right but it will not stay there and the colours do not change, any ideas? I’m using the latest AltUi and the latest RulesEngine files,
Hi Vosmont, tried hotfix, there appears to be an error in J_ALTUI_RulesEngine1.js. get this as first line in Chrome
“_loadStyle(‘ALTUI_RulesEngine.getStyle’); // // -->”
Have reverted back to previous versions for moment.
[quote=“dsroberts1945, post:98, topic:189418”]Hi Vosmont, tried hotfix, there appears to be an error in J_ALTUI_RulesEngine1.js. get this as first line in Chrome
“_loadStyle(‘ALTUI_RulesEngine.getStyle’); // // -->”
Have reverted back to previous versions for moment.
David[/quote]
Hello,
I’ve tested this version on Chrome and Firefox, without this error.
Can you try with a F5 in your browser ?
Cleared browser cache and tried again with no success, however downloaded all files from github again and reloaded ALL the luupfiles onto my pi. tried again and success this time must have been file corruption. many thanks vosmont, now getting into the hang of creating rules!