-
Notifications
You must be signed in to change notification settings - Fork 15
Openhab 2.1 Rules
Chibald edited this page Feb 2, 2020
·
4 revisions
val Maestro_Temperature_Setpoint_Manual = 0
var Timer Temperature_Setpoint_Send = null
var Timer Temperature_Setpoint_Expire = null
val Maestro_Boiler_Setpoint_Manual = 0
var Timer Boiler_Setpoint_Send = null
var Timer Boiler_Setpoint_Expire = null
// ---------------------------------------------------------------------------------------
rule "Send MQTT message to maestro deameon"
when
Item Maestro_Temperature_Setpoint changed
then
Maestro_Temperature_Setpoint_Manual = Maestro_Temperature_Setpoint.state
if (Temperature_Setpoint_Send != null) {
Temperature_Setpoint_Send.cancel()
Temperature_Setpoint_Send = null;
}
if (Temperature_Setpoint_Expire != null) {
Temperature_Setpoint_Expire.cancel()
Temperature_Setpoint_Expire = null;
}
Temperature_Setpoint_Expire = createTimer(now.plusSeconds(5), [|
Maestro_Temperature_Setpoint_Manual = 0;
Temperature_Setpoint_Expire = null
])
Temperature_Setpoint_Send = createTimer(now.plusSeconds(1), [|
var myString = '{\"Command\": "Temperature_Setpoint", \"Value\": \"' + Maestro_Temperature_Setpoint.state.toString + '\"}'
publish("mosquitto", "SUBmcz", myString)
Temperature_Setpoint_Send = null
])
end
rule "Update control item"
when
Item Maestro_Temperature_Setpoint_Proxy changed
then
if (Maestro_Temperature_Setpoint_Manual == 0) {
logInfo("Maestro","Set to " + Maestro_Temperature_Setpoint_Proxy.state)
Maestro_Temperature_Setpoint.sendCommand(Maestro_Temperature_Setpoint_Proxy.state)
} else {
logInfo("Maestro","Busy setting manual.")
}
end
// ---------------------------------------------------------------------------------------
rule "Send MQTT message to maestro deameon boiler"
when
Item Maestro_Boiler_Setpoint changed
then
Maestro_Boiler_Setpoint_Manual = Maestro_Boiler_Setpoint.state
if (Boiler_Setpoint_Send != null) {
Boiler_Setpoint_Send.cancel()
Boiler_Setpoint_Send = null;
}
if (Boiler_Setpoint_Expire != null) {
Boiler_Setpoint_Expire.cancel()
Boiler_Setpoint_Expire = null;
}
Boiler_Setpoint_Expire = createTimer(now.plusSeconds(5), [|
Maestro_Boiler_Setpoint_Manual = 0;
Boiler_Setpoint_Expire = null
])
Boiler_Setpoint_Send = createTimer(now.plusSeconds(1), [|
var myString = '{\"Command\": "Boiler_Setpoint", \"Value\": \"' + Maestro_Boiler_Setpoint.state.toString + '\"}'
publish("mosquitto", "SUBmcz", myString)
Boiler_Setpoint_Send = null
])
end
rule "Update control item boiler"
when
Item Maestro_Boiler_Setpoint_Proxy changed
then
if (Maestro_Boiler_Setpoint_Manual == 0) {
logInfo("Maestro","Set to " + Maestro_Boiler_Setpoint_Proxy.state)
Maestro_Boiler_Setpoint.sendCommand(Maestro_Boiler_Setpoint_Proxy.state)
} else {
logInfo("Maestro","Busy setting manual.")
}
end
// ---------------------------------------------------------------------------------------
rule "Maestro_ECO_Mode"
when
Item Maestro_ECO_Mode changed
then
publish("mosquitto", "SUBmcz", '{\"Command\": "Eco_Mode", \"Value\": \"' + Maestro_ECO_Mode.state.toString + '\"}')
end
// ---------------------------------------------------------------------------------------
rule "Maestro_Chrono_Mode"
when
Item Maestro_Chrono_Mode changed
then
publish("mosquitto", "SUBmcz", '{\"Command\": "Chronostat", \"Value\": \"' + Maestro_Chrono_Mode.state.toString + '\"}')
end
// ---------------------------------------------------------------------------------------
rule "Maestro_Silent_Mode"
when
Item Maestro_Silent_Mode changed
then
publish("mosquitto", "SUBmcz", '{\"Command\": "Silent_Mode", \"Value\": \"' + Maestro_Silent_Mode.state.toString + '\"}')
end
// ---------------------------------------------------------------------------------------
rule "Maestro_Control_Mode"
when
Item Maestro_Control_Mode changed
then
publish("mosquitto", "SUBmcz", '{\"Command\": "Control_Mode", \"Value\": \"' + Maestro_Control_Mode.state.toString + '\"}')
end
// ---------------------------------------------------------------------------------------
rule "Maestro_Power_Level"
when
Item Maestro_Power_Level changed
then
publish("mosquitto", "SUBmcz", '{\"Command\": "Power_Level", \"Value\": \"' + ((Maestro_Power_Level.state as DecimalType) -10).toString + '\"}')
end
// ---------------------------------------------------------------------------------------
rule "Maestro_Fan_State"
when
Item Maestro_Fan_State changed
then
publish("mosquitto", "SUBmcz", '{\"Command\": "Fan_State", \"Value\": \"' + Maestro_Fan_State.state.toString + '\"}')
end
// ---------------------------------------------------------------------------------------
rule "Maestro_Maestro_Power_State"
when
Item Maestro_Power_State received update
then
Thread::sleep(450)
if (Maestro_Power_State_ONOFF.state != Maestro_Power_State.state && Maestro_Power_State_ONOFF.state != 2) { // Debounce
logError("Maestro","Turning On / Off Stove " + Maestro_Power_State.state)
logInfo("Maestro",'{\"Command\": "Power", \"Value\": \"' + Maestro_Power_State.state.toString + '\"}')
publish("mosquitto", "SUBmcz", '{\"Command\": "Power", \"Value\": \"' + Maestro_Power_State.state.toString + '\"}')
}
end
rule "Maestro_Power_State_Proxy"
when
Item Maestro_Power_State_Proxy changed
then
Maestro_Power_State_ONOFF.sendCommand(transform("MAP", "maestro_stovestate_onoff.map", Maestro_Power_State_Proxy.state.toString))
end
// Maestro_Lastmessage
// ---------------------------------------------------------------------------------------
rule "Initialize Items"
when
System started or
Item SystemStartedSimulate changed
then
logInfo("MZC.rules","System Started");
publish("mosquitto", "SUBmcz", '{\"Command\": "Refresh" }')
end
// ---------------------------------------------------------------------------------------
rule "Maestro Message Recieved"
when
Item Maestro_Status_Message changed
then
postUpdate(Maestro_Status, 1)
end
// ---------------------------------------------------------------------------------------