2019-04-11 22:25:05 +02:00
|
|
|
|
2019-06-04 21:21:18 +02:00
|
|
|
var Timer ChromeCastOffTimer = null
|
2019-07-18 20:07:57 +02:00
|
|
|
val peoplecountermax = 0 // if openhab is restarted, the max value is lost... do we need persistence, how does that work?
|
|
|
|
val SpaceStatus = ''
|
|
|
|
|
|
|
|
rule "Startup"
|
|
|
|
when
|
|
|
|
System started
|
|
|
|
then
|
|
|
|
if (entrance_door_status.state.toString == 'OFF') {
|
|
|
|
SpaceStatus = 'open'
|
|
|
|
} else {
|
|
|
|
SpaceStatus = 'closed'
|
|
|
|
}
|
|
|
|
end
|
2019-06-04 21:21:18 +02:00
|
|
|
|
2019-04-12 20:28:43 +02:00
|
|
|
rule "Door Status"
|
|
|
|
when
|
|
|
|
Item entrance_door_status changed
|
|
|
|
then
|
|
|
|
val state = entrance_door_status.state.toString
|
2019-07-18 20:07:57 +02:00
|
|
|
val peoplecountermax
|
2019-04-12 20:28:43 +02:00
|
|
|
// the sensor state is inverted:
|
|
|
|
// OFF means opened
|
|
|
|
// ON means opened
|
|
|
|
if (state == 'OFF') {
|
|
|
|
logInfo('door', 'opened')
|
2019-07-18 20:07:57 +02:00
|
|
|
SpaceStatus = 'open'
|
2019-04-12 20:28:43 +02:00
|
|
|
entrance_ceiling_lamps.sendCommand("ON")
|
2019-07-18 20:07:57 +02:00
|
|
|
entrance_marbleadder_lamps.sendCommand("ON")
|
2019-04-12 20:28:43 +02:00
|
|
|
chill_zone_lamps.sendCommand("ON")
|
2019-12-27 11:31:09 +01:00
|
|
|
chill_zone_ikea_led.sendCommand("ON")
|
2019-04-12 20:28:43 +02:00
|
|
|
engineering_table_lamps.sendCommand("ON")
|
|
|
|
engineering_ceiling_lamps.sendCommand("ON")
|
|
|
|
engineering_status_lamp.sendCommand("ON")
|
2019-06-04 21:21:18 +02:00
|
|
|
area42_status_lamp.sendCommand("ON")
|
2019-12-27 12:56:16 +01:00
|
|
|
area42_table_lamp1.sendCommand("ON")
|
|
|
|
area42_table_lamp2.sendCommand("ON")
|
2019-07-18 20:07:57 +02:00
|
|
|
executeCommandLine("/etc/openhab2/syn2cat/spaceapi-set-status.sh open")
|
|
|
|
// needs current time in OpenTime
|
|
|
|
// sendTweet("It's "+OpenTime+" and we are open \o/ \ncome in and create something awesome =) \nhttps://Level2.lu/openingTimes")
|
|
|
|
|
2019-04-12 20:28:43 +02:00
|
|
|
} else {
|
|
|
|
logInfo('door', 'closed')
|
2019-07-18 20:07:57 +02:00
|
|
|
SpaceStatus = 'closed'
|
2019-04-12 20:28:43 +02:00
|
|
|
// 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")
|
2019-07-18 20:07:57 +02:00
|
|
|
entrance_marbleadder_lamps.sendCommand("OFF")
|
2019-04-12 20:28:43 +02:00
|
|
|
chill_zone_lamps.sendCommand("OFF")
|
2019-12-27 11:31:09 +01:00
|
|
|
chill_zone_ikea_led.sendCommand("OFF")
|
2019-04-12 20:28:43 +02:00
|
|
|
engineering_table_lamps.sendCommand("OFF")
|
|
|
|
engineering_ceiling_lamps.sendCommand("OFF")
|
|
|
|
engineering_status_lamp.sendCommand("OFF")
|
2019-06-04 21:21:18 +02:00
|
|
|
area42_status_lamp.sendCommand("OFF")
|
2019-12-27 12:56:16 +01:00
|
|
|
area42_table_lamp1.sendCommand("OFF")
|
|
|
|
area42_table_lamp2.sendCommand("OFF")
|
2019-06-04 21:21:18 +02:00
|
|
|
lab_soldering_table.sendCommand("OFF")
|
2019-07-18 20:07:57 +02:00
|
|
|
IRCode.sendCommand(transform("MAP", "ir.map", "amp_off"))
|
|
|
|
executeCommandLine("/etc/openhab2/syn2cat/spaceapi-set-status.sh closed")
|
|
|
|
// needs current time in OpenTime
|
|
|
|
// and number of people in peopleMax="\nThere were up to $peopleMax hackers today.\n"
|
|
|
|
peoplecountermax=entrance_people_counter_max.state
|
|
|
|
if(peoplecountermax>8) {
|
|
|
|
peopleMax="\nThere were up to "+peoplecountermax+" hackers today.\n"
|
|
|
|
} else {
|
|
|
|
peopleMax=".".repeat(peoplecountermax)
|
|
|
|
}
|
|
|
|
logInfo("door", "twitter message: "+ OpenTime+peopleMax)
|
|
|
|
// sendTweet("We just closed our doors at "+OpenTime+peopleMax+" See you very soon... \nhttps://Level2.lu/openingTimes")
|
|
|
|
entrance_people_counter_max.postUpdate(0)
|
2019-04-12 20:28:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
logInfo("door", "Space state: {}", state)
|
|
|
|
end
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2019-06-04 21:21:18 +02:00
|
|
|
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()
|
|
|
|
)
|
2019-07-18 20:07:57 +02:00
|
|
|
if ( SpaceStatus == 'closed' ) {
|
|
|
|
count=0
|
|
|
|
}
|
2019-06-04 21:21:18 +02:00
|
|
|
if ( count != Integer.parseInt(entrance_people_counter.previousState().state.toString)) {
|
|
|
|
entrance_people_counter.postUpdate(count)
|
2019-07-18 20:07:57 +02:00
|
|
|
// fresh run needs a max init, later we use persistence to init
|
|
|
|
if (entrance_people_counter_max.state == NULL) {entrance_people_counter_max.postUpdate(count) }
|
|
|
|
// count is bigger, so we got a new maximum
|
|
|
|
if(entrance_people_counter_max.state < count) {
|
|
|
|
entrance_people_counter_max.postUpdate(count)
|
|
|
|
logInfo("door", "People counter maximum set to "+ count)
|
|
|
|
}
|
|
|
|
executeCommandLine("/etc/openhab2/syn2cat/spaceapi-update-peoplecount.sh "+count)
|
2019-06-04 21:21:18 +02:00
|
|
|
}
|
|
|
|
end
|
2019-07-18 20:07:57 +02:00
|
|
|
// moved this to some external scripts, way easier with debugging and quoting
|
|
|
|
// /usr/bin/curl --max-time 1 --silent --data key="$spaceapikey" --data-urlencode 'sensors={"sensors":{"people_now_present":[{"value":'"$presency"'}]}}' https://spaceapi.syn2cat.lu/sensor/set
|
|
|
|
// executeCommandLine("/usr/bin/curl -v --max-time 1 --data key=$(cat /etc/openhab2/spaceapikey.txt) --data-urlencode 'sensors={\"sensors\":{\"people_now_present\":[{\"value\":'+count+'}]}}' https://spaceapi.syn2cat.lu/sensor/set >/tmp/c.log 2>&1")
|
|
|
|
// needs import java.net.URLEncoder
|
|
|
|
// sendHttpGetRequest("https://spaceapi.syn2cat.lu/sensor/set?"+URLEncoder::encode('key='+spaceapikey+'&sensors={sensors":{"people_now_present":[{"value":'+count+'}]}}')
|
2019-06-04 21:21:18 +02:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
rule "Tweet People Count"
|
|
|
|
when
|
|
|
|
Item entrance_people_counter changed
|
|
|
|
then
|
2019-07-18 20:07:57 +02:00
|
|
|
// val people = entrance_people_counter.state.toString
|
|
|
|
// sendTweet('There are currently ' + people + ' hackers present. Just pass by!')
|
2019-06-04 21:21:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2019-04-17 22:19:01 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2019-04-11 22:25:05 +02:00
|
|
|
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
|
2019-07-18 20:07:57 +02:00
|
|
|
beamerResponse = sendHttpGetRequest("http://10.2.113.7/tgi/return.tgi?command=2a3101fe0660")
|
|
|
|
chill_zone_screen_button_down.sendCommand("ON")
|
2019-04-11 22:25:05 +02:00
|
|
|
} else {
|
|
|
|
// turn the beamer off
|
2019-07-18 20:07:57 +02:00
|
|
|
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 "Beamer input"
|
|
|
|
when
|
|
|
|
Item chill_zone_beamer_input received command
|
|
|
|
then
|
|
|
|
val state = chill_zone_beamer_input.state.toString
|
|
|
|
var beamerResponse
|
|
|
|
|
|
|
|
if (state == 'hdmi1') {
|
|
|
|
beamerResponse = sendHttpGetRequest("http://10.2.113.7/tgi/return.tgi?command=2a3109f6071475")
|
|
|
|
} else if (state == 'hdmi2') {
|
|
|
|
beamerResponse = sendHttpGetRequest("http://10.2.113.7/tgi/return.tgi?command=2a3109f6071576")
|
|
|
|
} else if (state == 'dvi') {
|
|
|
|
beamerResponse = sendHttpGetRequest("http://10.2.113.7/tgi/return.tgi?command=2a3109f6070566")
|
|
|
|
} else if (state == 'vga1') {
|
|
|
|
beamerResponse = sendHttpGetRequest("http://10.2.113.7/tgi/return.tgi?command=2a3109f6070162")
|
|
|
|
} else if (state == 'vga2') {
|
|
|
|
beamerResponse = sendHttpGetRequest("http://10.2.113.7/tgi/return.tgi?command=2a3109f6070263")
|
2019-04-11 22:25:05 +02:00
|
|
|
}
|
2019-07-18 20:07:57 +02:00
|
|
|
else { }
|
2019-04-11 22:25:05 +02:00
|
|
|
val beamerStatus = transform("XPATH", "/return/text()", beamerResponse).replace("\n", '')
|
|
|
|
logInfo("beamer", "Beamer state: {}", beamerStatus)
|
|
|
|
end
|
|
|
|
|
2019-04-12 00:23:40 +02:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2019-06-04 21:21:18 +02:00
|
|
|
|
2019-04-11 22:25:05 +02:00
|
|
|
rule "Chromecast changed"
|
|
|
|
when
|
|
|
|
Item chill_zone_chromecast_status changed
|
|
|
|
then
|
2019-06-04 21:21:18 +02:00
|
|
|
val l2state = entrance_door_status.state.toString
|
|
|
|
if (l2state == 'ON') {
|
|
|
|
// do nothing if Level2 is closed
|
|
|
|
|
2019-04-11 22:25:05 +02:00
|
|
|
} else {
|
2019-06-04 21:21:18 +02:00
|
|
|
|
|
|
|
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")
|
2019-04-11 22:25:05 +02:00
|
|
|
// set input to HDMI2 - chromecast
|
|
|
|
sendHttpGetRequest("http://10.2.113.7/tgi/return.tgi?command=2a3109f6071576")
|
2019-06-04 21:21:18 +02:00
|
|
|
val state = chill_zone_beamer.state.toString
|
|
|
|
logInfo('beamer', 'Switch from {} to input HDMI2',state)
|
|
|
|
}
|
2019-04-11 22:25:05 +02:00
|
|
|
}
|
|
|
|
end
|
2019-04-12 00:23:40 +02:00
|
|
|
|