On startup I’ve like all my switch items to turn off (ie also go Red on GUI in Basic). I created a script, but it doesnt actually work. Anyone know what I’ve missed?
rule “Default Status”
when
System started
then
{
TimeStateOvernight.sendCommand(OFF)
TimeStateEarlyMorning.sendCommand(OFF)
TimeStateMorning.sendCommand(OFF)
TimeStateMidday.sendCommand(OFF)
TimeStateAfternoon.sendCommand(OFF)
TimeStateEarlyEvening.sendCommand(OFF)
TimeStateEvening.sendCommand(OFF)
TimeStateLateEvening.sendCommand(OFF)
TimeStateBoilerOveride.sendCommand(OFF)
PresenceKIT.sendCommand(OFF)
PresenceLVR.sendCommand(OFF)
PresenceHAL.sendCommand(OFF)
PresenceSSB.sendCommand(OFF)
PresenceGB2.sendCommand(OFF)
PresenceGB3.sendCommand(OFF)
PresenceBR1.sendCommand(OFF)
PresenceBR2.sendCommand(OFF)
PresencePOR.sendCommand(OFF)
PresenceFGD.sendCommand(OFF)
PresenceRGD.sendCommand(OFF)
PresenceDSB.sendCommand(OFF)
PresenceDST.sendCommand(OFF)
PresenceDSH.sendCommand(OFF)
PresenceDSK.sendCommand(OFF)
PresenceDSL.sendCommand(OFF)
PresenceDSG.sendCommand(OFF)
PresenceMHG.sendCommand(OFF)
PresenceGEN.sendCommand(OFF)
}
end
hmerk
(Hans-Jörg Merk)
September 30, 2017, 9:42pm
#2
Remove { } cause they are not needed.
rossko57
(Rossko57)
September 30, 2017, 10:14pm
#3
You could use a group based approach, writing a rule that operates on members of a group ‘gOffAtStart’ or similar, iterating through group members.
Problem Statement
Often one finds a number of rules that are very similar and that all work on similar Items. One way to solve this problem is through the use of lambdas but an even more flexible approach is to use Groups.
This Design Pattern presents a step-by-step tutorial for how to use Groups to consolidate and simplify the these several similar rules into one single rule.
The example used will be based on Contact Items that represent door and window sensors. Whenever any of these Contac…
That would also easily allow you to add a small delay between items, rather than flooding OH event bus
I haven’t really added any groups to anything in items. What would you say are the real benefits are I couldn’t really see one - it’s only really useful for short cutting turning things off together isn’t it?
Please compare this code with your code:
rule "OFF @ startup"
when
System started
then
gAllOff.forEach[i|
i.sendCommand(OFF)
]
end
To be honest, you would have to add one line in an .items file
Group:Switch gAllOff
plus a (gAllOff)
to all Items which should be set to OFF on startup.
But I guess you got the point
rlkoshak
(Rich Koshak)
October 1, 2017, 11:51pm
#6
You can do even better if all the members accept OFF then you just need
gAllOff.sendCommand(OFF)
Clearly you haven’t read the link rossko provided nor any of the other design patterns. Groups are vital to the writing of generic, concise, and maintainable rules.