Files
OpenHab_Steamware/Seriate/rules/steamware.rules
T
Samuele E. Locatelli 776f3832e3 Update seriate
2019-12-14 08:40:25 +01:00

286 lines
8.3 KiB
Plaintext

import java.util.Random
var Timer timer = null
val Random random = new Random()
// val resList = newArrayList("640/480", "320/240", "480/360")
// val urlList = newArrayList("https://www.fillmurray.com", "https://www.fillmurray.com/g",
// "https://www.placecage.com", "https://www.placecage.com/c", "https://www.placecage.com/g")
/**********************************************************************
* Rules x automazione CLIMA ALWAYS
**********************************************************************/
rule "Spegnimento Clima sabato-domenica pomeriggio 14:00"
when
Time cron "0 0 14 * * SAT,SUN"
then
Heating_GU120_CL_C1_Switch.sendCommand(OFF)
Heating_GU120_CL_C2_Switch.sendCommand(OFF)
Heating_GU120_CL_C3_Switch.sendCommand(OFF)
Heating_GU120_CL_C4_Switch.sendCommand(OFF)
Heating_GU120_CL_C5_Switch.sendCommand(OFF)
end
rule "Spegnimento Clima OGNI sera 20:00"
when
Time cron "0 0 20 * * ?"
then
Heating_GU120_CL_C1_Switch.sendCommand(OFF)
Heating_GU120_CL_C2_Switch.sendCommand(OFF)
Heating_GU120_CL_C3_Switch.sendCommand(OFF)
Heating_GU120_CL_C4_Switch.sendCommand(OFF)
Heating_GU120_CL_C5_Switch.sendCommand(OFF)
end
/**********************************************************************/
/**********************************************************************
* Rules x automazione CLIMA INVERNO
**********************************************************************/
rule "Accensione Riscaldamento mattino 8:00 SE < 19°"
when
Time cron "0 0 8 * JAN,FEB,NOV,DEC ?"
then
if (GU120_CL_Temp.state < 19)
{
Heating_GU120_CL_C1_Switch.sendCommand(ON)
Heating_GU120_CL_C2_Switch.sendCommand(ON)
Heating_GU120_CL_C3_Switch.sendCommand(ON)
// Heating_GU120_CL_C4_Switch.sendCommand(ON)
// Heating_GU120_CL_C5_Switch.sendCommand(ON)
}
end
rule "Accensione Riscaldamento mattino ingresso SAM in inverno"
when
Item gNet_Mobile_Sam changed to ON
//and
//Time cron "* * * * JAN,FEB,NOV,DEC ?"
then
// if (GU120_CL_Temp.state < 19)
// {
Heating_GU120_CL_C1_Switch.sendCommand(ON)
Heating_GU120_CL_C2_Switch.sendCommand(ON)
Heating_GU120_CL_C3_Switch.sendCommand(ON)
Heating_GU120_CL_C4_Switch.sendCommand(ON)
// Heating_GU120_CL_C5_Switch.sendCommand(ON)
// }
end
// rule "Accendo tutti se accendo 1 con meno di 21°"
// when
// Item Heating_GU120_CL_C1_Switch received command ON
// then
// // if (GU120_CL_Temp.state < 21)
// // {
// // if (GU120_CL_Switch.state == ON)
// // {
// Heating_GU120_CL_C1_Switch.sendCommand(OFF)
// Heating_GU120_CL_C2_Switch.sendCommand(OFF)
// Heating_GU120_CL_C3_Switch.sendCommand(OFF)
// Heating_GU120_CL_C4_Switch.sendCommand(OFF)
// Heating_GU120_CL_C5_Switch.sendCommand(OFF)
// // }
// // }
// end
/**********************************************************************/
/**********************************************************************
* Rules x automazione CLIMA ESTATE
**********************************************************************/
// rule "Accensione Riscaldamento mattino 8:00 SE > 22°"
// when
// Time cron "0 0 8 * MAY,JUN,JUL,AUG ?"
// then
// if (GU120_CL_Temp.state > 22)
// {
// Heating_GU120_CL_C1_Switch.sendCommand(ON)
// Heating_GU120_CL_C2_Switch.sendCommand(ON)
// Heating_GU120_CL_C3_Switch.sendCommand(ON)
// Heating_GU120_CL_C4_Switch.sendCommand(ON)
// Heating_GU120_CL_C5_Switch.sendCommand(ON)
// }
// end
// rule "Accendo tutti se accendo 1 con oltre 23°"
// when
// Item GU120_CL_Switch received command ON
// then
// if (GU120_CL_Temp.state > 23)
// {
// Heating_GU120_CL_C1_Switch.sendCommand(ON)
// Heating_GU120_CL_C2_Switch.sendCommand(ON)
// Heating_GU120_CL_C3_Switch.sendCommand(ON)
// Heating_GU120_CL_C4_Switch.sendCommand(ON)
// Heating_GU120_CL_C5_Switch.sendCommand(ON)
// }
// end
/**********************************************************************/
// rule "Test cron Riscaldamento ufficio"
// when
// Time cron "0 * 15 * JAN,FEB,NOV,DEC THU"
// then
// Heating_GU120_CL_C4_Switch.sendCommand(ON)
// end
/**
* This is a demo rule which simulates a real dimmer by reacting to increase/decrease commands
* and posting an updated state on the bus
*/
rule "Dimmed Light"
when
Item DimmedLight received command
then
if ((receivedCommand == INCREASE) || (receivedCommand == DECREASE)) {
var Number percent = 0
if (DimmedLight.state instanceof DecimalType) percent = DimmedLight.state as DecimalType
if (receivedCommand == INCREASE) percent = percent + 5
if (receivedCommand == DECREASE) percent = percent - 5
if (percent < 0) percent = 0
if (percent > 100) percent = 100
postUpdate(DimmedLight, percent);
}
end
rule "Timer Demo"
when
Item Light_GF_Corridor_Ceiling received command
then
if (receivedCommand == ON) {
if (timer === null) {
// first ON command, so create a timer to turn the light off again
timer = createTimer(now.plusSeconds(10)) [|
sendCommand(Light_GF_Corridor_Ceiling, OFF)
]
} else {
// subsequent ON command, so reschedule the existing timer
timer.reschedule(now.plusSeconds(10))
}
} else if (receivedCommand == OFF) {
// remove any previously scheduled timer
if (timer !== null) {
timer.cancel
timer = null
}
}
end
/**
* The following rules help initializing the demo items with some helpful states.
*/
// rule "Initialize light states"
// when
// System started
// then
// Lights?.members.forEach(light|
// postUpdate(light, if (Math::random > 0.7) ON else OFF)
// )
// end
// rule "Initialize heating states"
// when
// System started
// then
// Heating?.members.forEach(heating|
// postUpdate(heating, if (Math::random > 0.8) ON else OFF)
// )
// postUpdate(Temperature_Setpoint, 22)
// end
// rule "Initialize contact states"
// when
// System started
// then
// Windows?.members.forEach(window|
// postUpdate(window, if (Math::random > 0.5) OPEN else CLOSED)
// )
// end
// rule "Initialize Location"
// when
// System started
// then
// DemoLocation.postUpdate(new PointType("52.5200066,13.4049540"))
// end
rule "Set random room temperatures"
when
System started or
Time cron "0 0/5 * * * ?"
then
Temperature?.members.forEach(temperature|
postUpdate(temperature, 20.0 + (25.0 - (Math::random * 50.0).intValue) / 10.0)
)
end
rule "Set daily max and min temperature"
when
Item Weather_Temperature changed or
Time cron "0 0 0 * * ?" or
System started
then
val max = Weather_Temperature.maximumSince(now.withTimeAtStartOfDay)
val min = Weather_Temperature.minimumSince(now.withTimeAtStartOfDay)
if (max !== null && min !== null) {
postUpdate(Weather_Temp_Max, max.state)
postUpdate(Weather_Temp_Min, min.state)
}
end
// Creates an item that stores the last update time of this item
rule "Records last weather update time"
when
Item Weather_Temperature received update
then
postUpdate(Weather_LastUpdate, new DateTimeType())
end
// rule "Set random wifi variations"
// when
// System started or
// Time cron "/20 * * * * ?"
// then
// postUpdate(Wifi_Level, (Math::random * 4.0).intValue)
// end
// rule "Set random image URLs"
// when
// Time cron "/10 * * * * ?"
// then
// val url = urlList.get(random.nextInt(urlList.length))
// val res = resList.get(random.nextInt(resList.length))
// postUpdate(ImageURL, url + "/" + res)
// end
// rule "Volume"
// when
// Item Volume received command
// then
// if (receivedCommand instanceof PercentType) {
// setMasterVolume(receivedCommand)
// } else {
// if (receivedCommand == INCREASE) increaseMasterVolume(20)
// if (receivedCommand == DECREASE) decreaseMasterVolume(20)
// }
// end
// rule "Select Radio Station"
// when
// Item Radio_Station received command
// then
// switch(receivedCommand) {
// case 0 : playStream(null)
// case 1 : playStream("http://metafiles.gl-systemhaus.de/hr/hr3_2.m3u")
// case 2 : playStream("http://mp3-live.swr3.de/swr3_m.m3u")
// }
// end
// vim: syntax=Xtend