mas
(Markus)
December 19, 2019, 9:15am
1
I have several of these very simple rules:
rule "Switch Start"
when
Item Switch_Start received command
then
Command_Item.sendCommand("start")
end
rule "Switch Stop"
when
Item Switch_Stop received command
then
Command_Item.sendCommand("stop")
end
Is there a possibility that I can do without these simple rules and realize this directly in the item file, e.g. with the help of profiles?
pacive
(Anders Alfredsson)
December 19, 2019, 9:46am
2
I’m not sure if it’s possible by using profiles, but if you have a lot of short rules that is basically the same you can merge them into one rule. See for example:
Please see Design Pattern: What is a Design Pattern and How Do I Use Them for how to read and use DPs.
Problem Statement
Often one will have a number of separate Items which are all related to each other in some way. For example, one might have a Contact on a door and a DateTime to represent when the last time the door was opened. This is easy enough to keep track of if there are only one or two such Items, but if one has a lot of similar Items or is using a lot of generically coded rules where…
Please see Design Pattern: What is a Design Pattern and How Do I Use Them for how to read and use DPs.
Problem Statement
Often one finds a number of Rules that are very similar and that all work on similar Items resulting in a lot of duplicated code. One way to solve this problem is through the use of Groups.
Concept
[image]
This DP is not a standard DP in that it provides a single concrete template to follow to solve a specific problem. Instead this DP is more of a grand exploration of some …
opus
(Jürgen Baginski)
December 19, 2019, 10:39am
3
A bit more information would help!
Are all rules doing a sendCommand to the same item(Command_Item)?
Shall the switch all act like a toggle ( i.e. no difference between ON and OFF)?
…
mas
(Markus)
December 19, 2019, 11:06am
4
Yes, exactly. I use the Xiaomi Mi IO Binding . I want to send different commands (strings) to the item that is linked to the command channel .
The switches are only used to generate a command that executes the rule. It could look like this in the sitemap:
Switch item=Switch_Start mappings=[ON="Start"]
Switch item=Switch_Stop mappings=[ON="Stop"]
opus
(Jürgen Baginski)
December 19, 2019, 11:32am
5
In this case I would use a single String item like:
String ActionItem "Action"
and present it as a switch on a sitemap with mappings like.
Switch item=ActionItem mappings=[start="Start", stop="Stop", whatever="MyAction"]
Additional mappings are possible!
Now use a single rule:
rule "Action"
when
Item ActionItem received command
then
switch (receivedCommand) {
case "start" :
Command_Item.sendCommand("start")
case "stop" :
Command_Item.sendCommand("stop")
case "whatever" :
//Whatever needed!
}
ActionItem.postUpdate(NULL) //resets the selected switch position!
end