You downloaded ESH Designer, right?
I’m thinking you checked it when it was just a list of a bunch of things that are different between the two. Now it is a full blown step by step tutorial.
The link above is to a very simple example with lots of notes. It is basically a function, i.e. a chunk of code you can call with a set of passed in parameters.
I don’t think so. The problem you have is you have different numbers that you send based on the time of day. The map file for this would get pretty complicated if not completely unworkable.
One thing that would help things a little though is to move the time testing out of the rules here and use a state machine instead, as documented here.
Another would be to use a lambda.
import org.eclipse.xtext.xbase.lib.*
val Functions$Function5<String, String, String, String, String, Boolean> tvLightAuto = [ adjuster, adjusterTimer, ceilingLevel, autoTimer, autoTimer_or |
TVRoom_Ceiling_Light_Adjuster.sendCommand(adjuster)
TVRoom_Ceiling_Light_Adjuster_Timer.sendCommand(adjusterTimer)
Light_FF_TVRoom_Ceiling_level.sendCommand(ceilingLevel)
TVRoom_Ceiling_LightingAutomationTimer.sendCommand(autoTimer)
TVRoom_Ceiling_LightingAutomationTimer_OR.sendCommand(autoTimer_or)
logInfo("Lighting", "TVRoom Ceiling Level Udated to " + ceilingLevel)
logInfo("Lighting", "TVRoom Ceiling Level Updated to " + autoTimer)
true
]
rule "TVRoom Ceiling Light Modes"
when
System started or
Item TVRoom_Ceiling_LightingAutomation received command
then
val TimeOfDay = "DAY"
if(now.getHourOfDay < 05) TimeOfDay = "BED"
else if(now.getHourOfDay >= 23) "NIGHT"
switch receivedCommand {
case 1: {
switch TimeOfDay:
case "BED": tvLightAuto.apply("5", "1000", "1", "5", "20")
case "DAY": tvLightAuto.apply("5", "1000", "45", "5", "60")
case "NIGHT": tvLightAuto.apply("5", "1000", "2", "5", "20")
}
case 2: {
switch TimeOfDay:
case "BED": tvLightAuto.apply("1", "1000", "0", "5", "20")
...
}
...
}
end
Apply the same principles to the second rule. Do common calculations first (e.g. like I calculated the TimeOfDay). If the only difference between the clauses are the new states, move the calling of sendCommand and logging to a lambda and pass in the new states. At a minimum move the while loops to a lambda.
However, you might be able to make something work using Groups. For example, I have a much simpler use case but it could be expanded.
roup:Switch:OR(ON,OFF) gLights_ALL "All Lights"
Group:Switch:OR(ON, OFF) gLights_ON
Group:Switch:OR(ON, OFF) gLights_OFF
Group:Switch:OR(ON, OFF) gLights_ON_MORNING (gLights_ON)
Group:Switch:OR(ON, OFF) gLights_OFF_MORNING (gLights_OFF)
Group:Switch:OR(ON, OFF) gLights_ON_DAY (gLights_ON)
Group:Switch:OR(ON, OFF) gLights_OFF_DAY (gLights_OFF)
Group:Switch:OR(ON, OFF) gLights_ON_AFTERNOON (gLights_ON)
Group:Switch:OR(ON, OFF) gLights_OFF_AFTERNOON (gLights_OFF)
Group:Switch:OR(ON, OFF) gLights_ON_EVENING (gLights_ON)
Group:Switch:OR(ON, OFF) gLights_OFF_EVENING (gLights_OFF)
Group:Switch:OR(ON, OFF) gLights_ON_NIGHT (gLights_ON)
Group:Switch:OR(ON, OFF) gLights_OFF_NIGHT (gLights_OFF)
Group:Switch:OR(ON, OFF) gLights_ON_BED (gLights_ON)
Group:Switch:OR(ON, OFF) gLights_OFF_BED (gLights_OFF)
Switch aFrontLamp "Front Room Lamp"
(gLights_ALL, gLights_ON_MORNING, gLights_OFF_DAY, gLights_OFF_AFTERNOON, gLights_ON_EVENING, gLights_OFF_NIGHT, gLights_OFF_BED)
{ channel="zwave:device:dongle:node3:switch_binary" }
Switch aFamilyLamp "Family Room Lamp"
(gLights_ALL, gLights_OFF_MORNING, gLights_OFF_DAY, gLights_ON_AFTERNOON, gLights_ON_EVENING, gLights_OFF_NIGHT, gLights_OFF_BED)
{ channel="zwave:device:dongle:node10:switch_binary" }
Switch aPorchLight "Front Porch"
(gLights_ALL, gLights_OFF_MORNING, gLights_OFF_DAY, gLights_OFF_AFTERNOON, gLights_ON_EVENING, gLights_OFF_NIGHT, gLights_OFF_BED)
{ channel="zwave:device:dongle:node6:switch_binary" }
Each light belongs to a set of Groups which correspond with my TimeOfDay state. I have an ON and OFF group. So, for example, a member of gLights_ON_MORNING should turn on when MORNING starts and a member of gLights_OFF_AFTERNOON should turn off when AFTERNOON starts.
And because I’ve done this the rule is as simple as:
val logName = "lights"
rule "Set lights based on Time of Day"
when
Item vTimeOfDay received update
then
val offGroupName = "gLights_OFF_"+vTimeOfDay.state.toString
val onGroupName = "gLights_ON_"+vTimeOfDay.state.toString
logInfo(logName, "Turning off lights in " + offGroupName)
val GroupItem offItems = gLights_OFF.members.filter[g|g.name == offGroupName].head as GroupItem
offItems.members.filter[l|l.state != OFF].forEach[l | l.sendCommand(OFF)
]
logInfo(logName, "Turning on lights for " + onGroupName)
val GroupItem onItems = gLights_ON.members.filter[g|g.name == onGroupName].head as GroupItem
onItems.members.filter[l|l.state != ON].forEach[l | l.sendCommand(ON)]
end
I don’t know if this sparks any ideas or not.