145 lines
5.0 KiB
Plaintext
145 lines
5.0 KiB
Plaintext
|
|
var Timer ChromeCastOffTimer = null
|
|
|
|
rule "Door Status"
|
|
when
|
|
Item entrance_door_status changed
|
|
then
|
|
val state = entrance_door_status.state.toString
|
|
|
|
// the sensor state is inverted:
|
|
// OFF means opened
|
|
// ON means opened
|
|
if (state == 'OFF') {
|
|
logInfo('door', 'opened')
|
|
entrance_ceiling_lamps.sendCommand("ON")
|
|
chill_zone_lamps.sendCommand("ON")
|
|
engineering_table_lamps.sendCommand("ON")
|
|
engineering_ceiling_lamps.sendCommand("ON")
|
|
engineering_status_lamp.sendCommand("ON")
|
|
area42_status_lamp.sendCommand("ON")
|
|
} else {
|
|
logInfo('door', 'closed')
|
|
// turn the beamer off
|
|
sendHttpGetRequest("http://10.2.113.7/tgi/return.tgi?command=2a3102fd0660")
|
|
chill_zone_screen_button_up.sendCommand("ON")
|
|
entrance_ceiling_lamps.sendCommand("OFF")
|
|
chill_zone_lamps.sendCommand("OFF")
|
|
engineering_table_lamps.sendCommand("OFF")
|
|
engineering_ceiling_lamps.sendCommand("OFF")
|
|
engineering_status_lamp.sendCommand("OFF")
|
|
area42_status_lamp.sendCommand("OFF")
|
|
lab_soldering_table.sendCommand("OFF")
|
|
}
|
|
|
|
|
|
logInfo("door", "Space state: {}", state)
|
|
end
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
rule "Poll People Counter"
|
|
when
|
|
// sec min hour day month weekday year(opt)
|
|
Time cron "*/2 * * ? * *"
|
|
then
|
|
val response = sendHttpGetRequest("http://10.2.113.8/output.cgi")
|
|
val count = java.lang.Integer.parseInt(
|
|
transform("XPATH", "/table/tr[4]/td[2]/text()", response).trim()
|
|
)
|
|
if ( count != Integer.parseInt(entrance_people_counter.previousState().state.toString)) {
|
|
entrance_people_counter.postUpdate(count)
|
|
}
|
|
end
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
rule "Tweet People Count"
|
|
when
|
|
Item entrance_people_counter changed
|
|
then
|
|
// sendTweet('There are currently ' + entrance_people_counter.state.toString + ' hackers present. Just pass by!')
|
|
end
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
rule "Phone Ringing"
|
|
when
|
|
Time cron "*/2 * * ? * *"
|
|
then
|
|
// we could also fetch the XML but fetching the HTML seems to be faster
|
|
// http://10.2.113.137/admin/spacfg.xml
|
|
val phoneResponse = sendHttpGetRequest("http://10.2.113.137")
|
|
val isRinging = "Ringing" == (transform("REGEX", ".*(Ringing).*", phoneResponse))
|
|
if (isRinging) {
|
|
engineering_ceiling_phone_flash.sendCommand("ON")
|
|
}
|
|
end
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
rule "Beamer Power"
|
|
when
|
|
Item chill_zone_beamer received command
|
|
then
|
|
val state = chill_zone_beamer.state.toString
|
|
var beamerResponse
|
|
|
|
if (state == 'ON') {
|
|
// turn the beamer on
|
|
beamerResponse = sendHttpGetRequest("http://10.2.113.7/tgi/return.tgi?command=2a3101fe0660")
|
|
} else {
|
|
// turn the beamer off
|
|
beamerResponse = sendHttpGetRequest("http://10.2.113.7/tgi/return.tgi?command=2a3102fd0660")
|
|
}
|
|
val beamerStatus = transform("XPATH", "/return/text()", beamerResponse).replace("\n", '')
|
|
logInfo("beamer", "Beamer state: {}", beamerStatus)
|
|
end
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
rule "Chromecast changed"
|
|
when
|
|
Item chill_zone_chromecast_status changed
|
|
then
|
|
val l2state = entrance_door_status.state.toString
|
|
if (l2state == 'ON') {
|
|
// do nothing if Level2 is closed
|
|
|
|
} else {
|
|
|
|
val app = chill_zone_chromecast_status.state.toString
|
|
if (app === null || app == UNDEF || app == 'UNDEF' || app == '' || app == 'BackDrop' ) {
|
|
// set input to DVI - hackerspace video
|
|
logInfo('beamer', 'start 2min delay before switch input to DVI')
|
|
// ChromeCastOffTimer.cancel() // stop any timer running
|
|
ChromeCastOffTimer=createTimer(now.plusSeconds(30)) [
|
|
app = chill_zone_chromecast_status.state.toString
|
|
if (app === null || app == UNDEF || app == 'UNDEF' || app == '' || app == 'BackDrop' ) {
|
|
sendHttpGetRequest("http://10.2.113.7/tgi/return.tgi?command=2a3109f6070566")
|
|
logInfo('beamer', 'Switch to input DVI (after 2min)')
|
|
} else {
|
|
logInfo('beamer', 'after 2min, chromecast again streaming. Not switching off.')
|
|
}
|
|
]
|
|
} else {
|
|
if (ChromeCastOffTimer !== null) {
|
|
logInfo('chromecast', 'disabling off timer')
|
|
ChromeCastOffTimer.cancel() // stop any timer running
|
|
} else {
|
|
logInfo('chromecast', 'no off time running')
|
|
}
|
|
// only switch beamer on if chromecast is actually showing something
|
|
logInfo('chromecast', 'is streaming from '+app)
|
|
chill_zone_beamer.sendCommand("ON")
|
|
chill_zone_screen_button_down.sendCommand("ON")
|
|
// set input to HDMI2 - chromecast
|
|
sendHttpGetRequest("http://10.2.113.7/tgi/return.tgi?command=2a3109f6071576")
|
|
val state = chill_zone_beamer.state.toString
|
|
logInfo('beamer', 'Switch from {} to input HDMI2',state)
|
|
}
|
|
}
|
|
end
|
|
|