{"id":24221605,"url":"https://github.com/michdo93/openhab-rulemanager","last_synced_at":"2026-02-02T08:43:27.852Z","repository":{"id":135031606,"uuid":"529997216","full_name":"Michdo93/openHAB-RuleManager","owner":"Michdo93","description":"Will manage rules in openHAB.","archived":false,"fork":false,"pushed_at":"2022-08-29T08:22:40.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T00:45:32.403Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Michdo93.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-28T22:44:04.000Z","updated_at":"2022-08-28T22:44:04.000Z","dependencies_parsed_at":"2023-05-10T20:15:31.323Z","dependency_job_id":null,"html_url":"https://github.com/Michdo93/openHAB-RuleManager","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Michdo93/openHAB-RuleManager","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Michdo93%2FopenHAB-RuleManager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Michdo93%2FopenHAB-RuleManager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Michdo93%2FopenHAB-RuleManager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Michdo93%2FopenHAB-RuleManager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Michdo93","download_url":"https://codeload.github.com/Michdo93/openHAB-RuleManager/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Michdo93%2FopenHAB-RuleManager/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263687158,"owners_count":23496089,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-14T06:19:43.532Z","updated_at":"2026-02-02T08:43:22.797Z","avatar_url":"https://github.com/Michdo93.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# openHAB-RuleManager\nWill manage rules in openHAB.\n\n## Items\n\nAt first you have to create an `Switch` item for each Rule you will `enable` or `disable`. And you have to create an `Switch` item for each Rule you want to run:\n\n```\nGroup RuleManager \"Rule Manager\"\n\nSwitch exampleRule \"Enable/Disable example rule\" (RuleManager)\nSwitch isRunningExampleRule \"Is example rule running?\" (RuleManager) \n```\n\n## Sitemaps\n\nYou can then add following to your sitemap:\n\n```\nText label=\"Rule Manager\" icon=\"control\" {\n    Switch item=exampleRule label=\"Enable/Disable example rule\"\n    Switch item=isRunningExampleRule label=\"Is example rule running?\"\n}\n```\n\n## Rules\n\nFor enabling and disabling a rule you can add following rules:\n\n```\nrule \"Rule Manager example rule enable\"\nwhen\n    Item exampleRule changed from OFF to ON\nthen\n    executeCommandLine(\"/usr/bin/sshpass\",\"-p\",\"habopen\",\"/usr/bin/ssh\",\"-p\",\"8101\",\"openhab@localhost\",\"openhab:automation\",\"enableRule\",\"\u003cuid\u003e\",\"true\")\nend\n\nrule \"Rule Manager example rule disable\"\nwhen\n    Item exampleRule changed from OFF to ON\nthen\n    executeCommandLine(\"/usr/bin/sshpass\",\"-p\",\"habopen\",\"/usr/bin/ssh\",\"-p\",\"8101\",\"openhab@localhost\",\"openhab:automation\",\"enableRule\",\"\u003cuid\u003e\",\"false\")\nend\n```\n\nTo check if an rule is running you can do following:\n\n```\nrule \"example rule\"\nwhen\n    \u003ctrigger_example_rule\u003e\nthen\n    isRunningExampleRule.sendCommand(ON) // execution of example rule is started\n    \n    \u003cexample_rule\u003e\n    ... // the actual rule\n    \u003c/example_rule\u003e\n    \n    isRunningExampleRule.sendCommand(OFF) // execution of example rule is finished\nend\n```\n\nIs it possible to stop/abort a rule execution? Yes. You can extend the previous rule as follows:\n\n```\nrule \"example rule\"\nwhen\n    \u003ctrigger_example_rule\u003e\nthen\n    isRunningExampleRule.sendCommand(ON) // execution of example rule is started\n    \n    \u003cexample_rule\u003e\n    \n    if (isRunningExampleRule.state == ON) {\n        \u003cpart_of_example_rule\u003e\n        ... // a part of the example rule\n        \u003c/part_of_example_rule\u003e\n    } else {\n        \u003cundo_previously_changes\u003e // maybe you have to undo previously changes. If you changed an switch item to ON you can as example change it to OFF.\n    }\n    \n    if (isRunningExampleRule.state == ON) {\n        \u003canother_part_of_example_rule\u003e\n        ... // a another part of the example rule\n        \u003c/another_part_of_example_rule\u003e\n    } else {\n        \u003cundo_previously_changes\u003e // maybe you have to undo previously changes. If you changed an switch item to ON you can as example change it to OFF.\n    }\n    \n    \u003c/example_rule\u003e\n    \n    isRunningExampleRule.sendCommand(OFF) // execution of example rule is finished\nend\n```\n\nIf you structured your rule execution into multiple rules which are executed one after the other you can change this rules to as example:\n\n```\nrule \"part of example rule\"\nwhen\n    \u003ctrigger_by_example_rule\u003e\nthen\n    if (isRunningExampleRule.state == ON) {\n        \u003cpart_of_example_rule\u003e\n        ... // a part of the example rule\n        \u003c/part_of_example_rule\u003e\n    } else {\n        \u003cundo_previously_changes\u003e // maybe you have to undo previously changes. If you changed an switch item to ON you can as example change it to OFF.\n    }\nend\n```\n\nSo and how can I stop this rule (`example rule`) from execution? You have to set the state of the switch `isRunningExampleRule` to `OFF`. During execution, this switch should always be `ON`. However, this switch is only set to `ON` at the very beginning when the rule is started. If you set this switch to `OFF`, the rule will not be executed further by the `if`-statements. This happens because during the execution of the rule this switch is not set to `ON` again. The rule runs through and does not execute anything more. At the end, this switch would theoretically be set to `OFF` again. However, this then remains without effect.\n\nThere is another borderline case to consider: What if one rule is running and this is supposed to cause another rule not to be executed because in this one perhaps a trigger is used which is triggered by the other rule and these would interfere? This can also be queried and prevented. It is only fair to say that you would then not have set the triggers well and would have had to add further conditions:\n\n```\nrule \"second example rule\"\nwhen\n    \u003ctrigger_second_example_rule\u003e\nthen\n    if (isRunningExampleRule.state == OFF) {\n        \u003csecond_example_rule\u003e\n        ... // the actual second example rule\n        \u003c/second_example_rule\u003e\n    }\nend\n```\n\nAnd who has understood the concept presented here correctly, also introduces to this and each further rule a switch that can enable or disable the execution of the second rule and also a switch that enables or disables the rule. If a rule is disabled completely, then it does not interfere with the execution of the other rule right from the start.\n\nSo do I have to check if this other rule is enabled or disabled?\n\n```\nrule \"second example rule\"\nwhen\n    \u003ctrigger_second_example_rule\u003e\nthen\n    if (exampleRule.state == OFF) {\n        if (isRunningExampleRule.state == OFF) {\n            \u003csecond_example_rule\u003e\n            ... // the actual second example rule\n            \u003c/second_example_rule\u003e\n        }\n    }\nend\n```\n\nOf course not! The state of the switch that this rule is running should never reach `ON` by execution this rule. In this case `isRunningExampleRule` is still `OFF`.\n\nBut how can I be sure? I can switch the item to `ON` via REST API, MQTT, Karaf Console or by using my Sitemap. Well, that would not be so wise and could have fatal consequences.\n\nOne thing should be clear, I can't do the following either:\n\n```\nrule \"example rule\"\nwhen\n    \u003ctrigger_example_rule\u003e\nthen\n    if (exampleRule.state == ON) {\n        isRunningExampleRule.sendCommand(ON) // execution of example rule is started\n    }\n    \n    \u003cexample_rule\u003e\n    \n    if (isRunningExampleRule.state == ON) {\n        \u003cpart_of_example_rule\u003e\n        ... // a part of the example rule\n        \u003c/part_of_example_rule\u003e\n    } else {\n        \u003cundo_previously_changes\u003e // maybe you have to undo previously changes. If you changed an switch item to ON you can as example change it to OFF.\n    }\n    \n    if (isRunningExampleRule.state == ON) {\n        \u003canother_part_of_example_rule\u003e\n        ... // a another part of the example rule\n        \u003c/another_part_of_example_rule\u003e\n    } else {\n        \u003cundo_previously_changes\u003e // maybe you have to undo previously changes. If you changed an switch item to ON you can as example change it to OFF.\n    }\n    \n    \u003c/example_rule\u003e\n    \n    isRunningExampleRule.sendCommand(OFF) // execution of example rule is finished\nend\n```\n\nTo be clearer...\n\n```\n    if (exampleRule.state == ON) {\n        isRunningExampleRule.sendCommand(ON) // execution of example rule is started\n    }\n```\n\nwill not work because the rule will never be triggered of the state of `exampleRule` is `OFF`.\n\nBut you can create another rule:\n\n```\nrule \"check if isRunningExampleRule is actual running\"\nwhen\n    Item isRunningExampleRule changed to ON\nthen\n    if (exampleRule.state == OFF) {\n        isRunningExampleRule.postUpdate(OFF)\n    }\nend\n```\n\nYou can't outsmart the system with this anymore. Or can you? Yes you can if you make following mistake: `isRunningExampleRule.postUpdate(ON)` swap with `isRunningExampleRule.sendCommand(ON)`. \n\nNevertheless, the second rule should look like this:\n\n```\nrule \"second example rule\"\nwhen\n    \u003ctrigger_second_example_rule\u003e\nthen\n    if (isRunningExampleRule.state == OFF) {\n        isRunningSecondExampleRule.sendCommand(ON)\n    \n        \u003csecond_example_rule\u003e\n    \n        if (isRunningSecondExampleRule.state == ON) {\n            \u003cpart_of_second_example_rule\u003e\n            ... // a part of the second example rule\n            \u003c/part_of_second_example_rule\u003e\n        } else {\n            \u003cundo_previously_changes\u003e // maybe you have to undo previously changes. If you changed an switch item to ON you can as example change it to OFF.\n        }\n    \n        if (isRunningSecondExampleRule.state == ON) {\n            \u003canother_part_of_second_example_rule\u003e\n            ... // a another part of the second example rule\n            \u003c/another_part_of_second_example_rule\u003e\n        } else {\n            \u003cundo_previously_changes\u003e // maybe you have to undo previously changes. If you changed an switch item to ON you can as example change it to OFF.\n        }\n    \n        \u003c/second_example_rule\u003e\n    }\n    \n    isRunningSecondExampleRule.sendCommand(OFF)\nend\n```\n\n## New Items\n\nThe items changed then to:\n\n```\nGroup RuleManager \"Rule Manager\"\n\nSwitch exampleRule \"Enable/Disable example rule\" (RuleManager)\nSwitch isRunningExampleRule \"Is example rule running?\" (RuleManager)\nSwitch secondExampleRule \"Enable/Disable second example rule\" (RuleManager)\nSwitch isRunningSecondExampleRule \"Is second example rule running?\" (RuleManager) \n```\n\n## New Sitemaps\n\nThe sitemap changed then to:\n\n```\nText label=\"Rule Manager\" icon=\"control\" {\n    Switch item=exampleRule label=\"Enable/Disable example rule\"\n    Switch item=isRunningExampleRule label=\"Is example rule running?\"\n    Switch item=secondExampleRule label=\"Enable/Disable second example rule\"\n    Switch item=isRunningSecondExampleRule label=\"Is second example rule running?\"\n}\n```\n\n## New Rules\n\nYour rules at least look like this:\n\n```\nrule \"Rule Manager example rule enable\"\nwhen\n    Item exampleRule changed from OFF to ON\nthen\n    executeCommandLine(\"/usr/bin/sshpass\",\"-p\",\"habopen\",\"/usr/bin/ssh\",\"-p\",\"8101\",\"openhab@localhost\",\"openhab:automation\",\"enableRule\",\"\u003cuid\u003e\",\"true\")\nend\n\nrule \"Rule Manager example rule disable\"\nwhen\n    Item exampleRule changed from OFF to ON\nthen\n    executeCommandLine(\"/usr/bin/sshpass\",\"-p\",\"habopen\",\"/usr/bin/ssh\",\"-p\",\"8101\",\"openhab@localhost\",\"openhab:automation\",\"enableRule\",\"\u003cuid\u003e\",\"false\")\nend\n\nrule \"Rule Manager second example rule enable\"\nwhen\n    Item secondExampleRule changed from OFF to ON\nthen\n    executeCommandLine(\"/usr/bin/sshpass\",\"-p\",\"habopen\",\"/usr/bin/ssh\",\"-p\",\"8101\",\"openhab@localhost\",\"openhab:automation\",\"enableRule\",\"\u003cuid\u003e\",\"true\")\nend\n\nrule \"Rule Manager second example rule disable\"\nwhen\n    Item secondExampleRule changed from OFF to ON\nthen\n    executeCommandLine(\"/usr/bin/sshpass\",\"-p\",\"habopen\",\"/usr/bin/ssh\",\"-p\",\"8101\",\"openhab@localhost\",\"openhab:automation\",\"enableRule\",\"\u003cuid\u003e\",\"false\")\nend\n\nrule \"check if isRunningExampleRule is actual running\"\nwhen\n    Item isRunningExampleRule changed to ON\nthen\n    if (exampleRule.state == OFF) {\n        isRunningExampleRule.postUpdate(OFF)\n    }\nend\n\nrule \"check if isRunningSecondExampleRule is actual running\"\nwhen\n    Item isRunningSecondExampleRule changed to ON\nthen\n    if (secondExampleRule.state == OFF) {\n        isRunningSecondExampleRule.postUpdate(OFF)\n    }\nend\n\nrule \"example rule\"\nwhen\n    \u003ctrigger_example_rule\u003e\nthen\n    isRunningExampleRule.sendCommand(ON) // execution of example rule is started\n    \n    \u003cexample_rule\u003e\n    \n    if (isRunningExampleRule.state == ON) {\n        \u003cpart_of_example_rule\u003e\n        ... // a part of the example rule\n        \u003c/part_of_example_rule\u003e\n    } else {\n        \u003cundo_previously_changes\u003e // maybe you have to undo previously changes. If you changed an switch item to ON you can as example change it to OFF.\n    }\n    \n    if (isRunningExampleRule.state == ON) {\n        \u003canother_part_of_example_rule\u003e\n        ... // a another part of the example rule\n        \u003c/another_part_of_example_rule\u003e\n    } else {\n        \u003cundo_previously_changes\u003e // maybe you have to undo previously changes. If you changed an switch item to ON you can as example change it to OFF.\n    }\n    \n    \u003c/example_rule\u003e\n    \n    isRunningExampleRule.sendCommand(OFF) // execution of example rule is finished\nend\n\nrule \"second example rule\"\nwhen\n    \u003ctrigger_second_example_rule\u003e\nthen\n    if (isRunningExampleRule.state == OFF) {\n        isRunningSecondExampleRule.sendCommand(ON)\n    \n        \u003csecond_example_rule\u003e\n    \n        if (isRunningSecondExampleRule.state == ON) {\n            \u003cpart_of_second_example_rule\u003e\n            ... // a part of the second example rule\n            \u003c/part_of_second_example_rule\u003e\n        } else {\n            \u003cundo_previously_changes\u003e // maybe you have to undo previously changes. If you changed an switch item to ON you can as example change it to OFF.\n        }\n    \n        if (isRunningSecondExampleRule.state == ON) {\n            \u003canother_part_of_second_example_rule\u003e\n            ... // a another part of the second example rule\n            \u003c/another_part_of_second_example_rule\u003e\n        } else {\n            \u003cundo_previously_changes\u003e // maybe you have to undo previously changes. If you changed an switch item to ON you can as example change it to OFF.\n        }\n    \n        \u003c/second_example_rule\u003e\n    }\n    \n    isRunningSecondExampleRule.sendCommand(OFF)\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichdo93%2Fopenhab-rulemanager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichdo93%2Fopenhab-rulemanager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichdo93%2Fopenhab-rulemanager/lists"}