I searched the forum but didn’t find it.Can I execute a rule by another rule?
-
Execute a rule by another rule
-
Create a rule and a dummy button. Let the rule kick in when the button is pressed. Press the button with a API call
OR
Create a rule and a variable. Let the rule kick in when the variable has a specific value. Set the variable with the second rule so the first rule is executed (don’t forget to reset the variable).Like my projects and help? Consider donating electroneum etnjwAKGPqF6omQWRmpp9u2BPyVDG9VuyRQjNJ1S8yfBdfR9qeUQ46kRy8KS2CNqbpNLRrsgmNW6F2TMzxmZgPrh6KctrkrYbm
-
@temp said in Execute a rule by another rule:
I searched the forum but didn’t find it.Can I execute a rule by another rule?
It is not possible as you might expect but there are some work-arounds:
- You can execute a rule using the pimatic API implicitly by activating it, e.g. using pimatic shell execute. - https://forum.pimatic.org/topic/310/execute-rule-through-api
- You can use some guard variable as part of the of the rule condition to fire the rule. I think the easiest way of achieving that is to use a DummySwitch. See example below:
# Setup a a DummySwitch with id "guard-1" # The guarded rule WHEN state of guard-1 changes THEN ... # The trigger rule WHEN .... THEN toggle guard-1
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
@developer can you please help with the syntax
execute "curl -X PATCH --silent --header "Content-Type:application/json" --data '{"rule": {"active" :"true"}}' --user "user:password" http://url:5001/api/rules/rule_id"
-
That call is only for enabling a rule, not executing.
Like my projects and help? Consider donating electroneum etnjwAKGPqF6omQWRmpp9u2BPyVDG9VuyRQjNJ1S8yfBdfR9qeUQ46kRy8KS2CNqbpNLRrsgmNW6F2TMzxmZgPrh6KctrkrYbm
-
@koffienl said in Execute a rule by another rule:
That call is only for enabling a rule, not executing.
You can execute a rule using the pimatic API implicitly by activating it, e.g. using pimatic shell execute. - https://forum.pimatic.org/topic/310/execute-rule-through-api
@koffienl please read two posts above
-
@temp You need to escape
"
and{
characters with backslashexecute "curl -X PATCH --silent --header 'Content-Type:application/json' --data '\{\"rule\": \{\"active\" :\"true\"}}' --user 'user:password' http://url:5001/api/rules/rule_id"
I have tested this and rule actication works as expected, however, different to what Oliver stated in https://forum.pimatic.org/topic/310/execute-rule-through-api the rule is not executed. I am sorry about this. I’ll make a note on the ticket.
EDIT: The button press via API may another thing to try. See https://forum.pimatic.org/topic/327/press-button-via-api
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
@developer can I also use the API for simulate pressing a amazon dash button?
-
With pimatic-amazing-dash-button it is currently not possible.
With pimatic-dash-button I don’t think it is currently possible either, but I haven’t tried this out. Even though it is a ButtonsDevice the action declaration is missing on the most derived class.
I’ll provide a solution for pimatic-amazing-dash-button asap
https://github.com/mwittig/pimatic-amazing-dash-button/issues/10
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
@mwittig I am using your plugin so I wait. Thanks
-
@temp Released pimatic-amazing-dash-button@0.9.13.
See also README for details on trigger action.
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
but there is a possibility to execute the THEN part of a rule via api.
i know that @slix made that possible in his kodi addon. there, you are able to trigger the then part of rules (from within kodi!)
https://github.com/SLiX69/plugin.program.pimatic/blob/master/addon.py#L98-L109pimatic v0.9 has been released!
Support Pimatic and get some free stickers
Like us on Facebookmake it so !
-
@leader21 said in Execute a rule by another rule:
but there is a possibility to execute the THEN part of a rule via api.
Well, not exactly. The code you’re referring to is using the
execute-action
a service. This allows for executing an action string, but it is not referring to the action part of a specific rule. For example, theactionString
property may look like as follows:{"actionString": "switch mySwitch off"}
It should also be noted that
execute-action
can only handle a single action. It does not allow for an action statement with a complex action expression contain multiple actions."It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
ok, maybe the wrong part in the code ^^
just have a look here
the pimatic addon in kodi scans all rules and provides a trigger option.
pimatic v0.9 has been released!
Support Pimatic and get some free stickers
Like us on Facebookmake it so !
-
Any feedback here @mwittig
Big thanks to your update
-
I have no idea, guys. Maybe the author of the kodi plugin can shed some light on this
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
@slix, Jannis can you help us with that?
pimatic v0.9 has been released!
Support Pimatic and get some free stickers
Like us on Facebookmake it so !