In my previous post Forget_me_not : My Smart Home Post#5 Week-4 Smart Mailbox with email and tweet support I have shared my basic build of smart mailbox with email and tweet support,
In this week I have received parts I have requested for "My Smarthome" initial phase build...
As now I have raspberry-pi camera, I have added one more feature to my smart doorbell application , That is with visitor image capturing when doorbell event is there , or take photograph of your door step to look around doorstep any time from openhab application with of course email and tweet support....
My demo.rules file..
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.binding.*
import org.openhab.action.*
import org.apache.commons.mail.*
import java.util.Date
var Number mail_count = 0
var Number visitor_count = 0
/** When system starts update all items with its default value */
rule "Initialization at system startup"
when
System started
then
postUpdate(No_new_mail, mail_count)
postUpdate(No_visitor, visitor_count)
end
/**
* This rule sends email to home owner when doorbell switch pressed with photo as attachment
* here execute command line is just for demo it actually takes photo from PI Camera and save this image in specified folder
* So far I am waiting for PI camera so its not implemented
*/
rule "send mail doorbell"
when
Item EnOcean_switch received update ON
then
executeCommandLine("/opt/openhab/cam.sh")
visitor_count=visitor_count+1
postUpdate(Doorbell_tstamp, new DateTimeType())
postUpdate(No_visitor, visitor_count)
playSound("doorbell.mp3")
var String tweet_doorbell="Doorbell:You have visitor at home (" + new Date + ")\nTotal visitor so far = " + visitor_count
sendTweet(tweet_doorbell)
sendMail("ravi.butani03@gmail.com", "My Smart Home (Doorbell)",tweet_doorbell +".\nOpen attachment to see latest visitor's image" ,"http://localhost:8080/doorcam/visitor.jpg")
end
rule "send mail manual image"
when
Item Send_pic_email received update ON
then
sendMail("ravi.butani03@gmail.com", "My Smart Home (Door image latest)"," Open attachment to see latest manually captured image at ("+ new Date +")" ,"http://localhost:8080/doorcam/man_pic.jpg")
postUpdate(Send_pic_email, OFF)
end
rule "take manual image of door step"
when
Item Take_doorstep_pic received update ON
then
executeCommandLine("/opt/openhab/cam_manual.sh")
postUpdate(Manual_tstamp, new DateTimeType())
postUpdate(Take_doorstep_pic, OFF)
end
rule "reset visitor count"
when
Item Reset_visitor_count received update ON
then
visitor_count=0
postUpdate(No_visitor, visitor_count)
var String tweet_reset_visitor_count="Doorbell:You have Reset visitor count at (" + new Date + ")"
sendTweet(tweet_reset_visitor_count)
sendMail("ravi.butani03@gmail.com", "My Smart Home (Doorbell)", tweet_reset_visitor_count)
postUpdate(Reset_visitor_count, OFF)
end
/**
* This rule sends email to home owner when new mail dropped in mail box
*/
rule "send mail update Mailbox "
when
Item EnOcean_contact changed from CLOSED to OPEN
then
mail_count=mail_count+1
postUpdate(No_new_mail, mail_count)
postUpdate(Mail_tstamp, new DateTimeType())
var String tweet_mailbox="Mailbox : You have " + mail_count+" new mail. latest at (" +new Date + ")"
sendTweet(tweet_mailbox)
sendMail("ravi.butani03@gmail.com", "My Smart Home (Mailbox)" , tweet_mailbox)
end
rule "send mail collect Mailbox "
when
Item EnOcean_contact_collect changed from CLOSED to OPEN
then
mail_count=0
postUpdate(No_new_mail, mail_count)
postUpdate(Mail_tstamp, new DateTimeType())
var String tweet_mailbox_collect="Mailbox : You have collected all mails at (" +new Date + ")"
sendTweet(tweet_mailbox_collect)
sendMail("ravi.butani03@gmail.com", "My Smart Home (Mailbox)" , tweet_mailbox_collect)
end
My demo.items file...
/* My Smart Home items */
Switch EnOcean_switch "Doorbell" <doorbell1> (enocean) {enocean="{id=00:17:D3:AD, eep=F6:02:01, channel=A, parameter=I}"}
Switch EnOcean_switch_B "DoorbellB" <doorbell1> (enocean) {enocean="{id=00:17:D3:AD, eep=F6:02:01, channel=B, parameter=I}"}
Number EnOcean_sensor_temp "Temperature [%.1f °C]" <temperature> (enocean) {enocean="{id=00:83:02:70, eep=A5:04:01, parameter=TEMPERATURE}"}
Number EnOcean_sensor_humd "Humidity [%.1f %%]" <humidity> (enocean) {enocean="{id=00:83:02:70, eep=A5:04:01, parameter=HUMIDITY}"}
Contact EnOcean_contact "MailBox [MAP(en.map):%s]" <mailbox> (enocean) {enocean="{id=00:83:4A:99, eep=D5:00:01, parameter=CONTACT_STATE"}
Contact EnOcean_contact_collect "MailBox collect [MAP(en.map):%s]" <mailbox> (enocean) {enocean="{id=00:82:B9:65, eep=D5:00:01, parameter=CONTACT_STATE"}
Switch Take_doorstep_pic "Capture image" <click>
Switch Send_pic_email "Send me image as email" <email>
Switch Reset_visitor_count "Reset Visitor count" <reset>
Number No_new_mail "Mailbox [%d New mails]" <mailbox>
Number No_visitor "Latest Visitors [%d Latest visitors]" <doorbell>
//String Arduino "Arduino [%s]" (arduino) {serial="/dev/ttyUSB0"}
/* Time stamp items */
DateTime Date "Date [%1$tA, %1$td.%1$tm.%1$tY]" <calendar>
DateTime Mail_tstamp "Mailbox last updated [%1$tA, %1$td.%1$tm.%1$tY, %1$tI:%1$tM %1$tp]" <clock1>
DateTime Doorbell_tstamp "Doorbell last updated [%1$tA, %1$td.%1$tm.%1$tY, %1$tI:%1$tM %1$tp]" <clock1>
DateTime Manual_tstamp "Latest image [%1$tA, %1$td.%1$tm.%1$tY, %1$tI:%1$tM %1$tp]" <clock1>
/* This portion will be used in application soon */
String UnknownDevices "Unknown Devices in Range: [%s]" { bluetooth="?" }
Number NoOfPairedDevices "Paired Devices in Range: [%d]" { bluetooth="!" }
my demo.sitemap file...
sitemap demo label="My Smart Home"
{
Frame label="Latest events and parameters" {
Text item=EnOcean_sensor_temp valuecolor=[>25="orange",>15="green",>5="orange",<=5="blue"]
Text item=EnOcean_sensor_humd valuecolor=[>25="orange",>15="green",>5="orange",<=5="blue"]
//Text item=Date
Text item=No_new_mail valuecolor=[==0="blue",>=1="green",>5="orange"]
Text item=Mail_tstamp
Text item=No_visitor valuecolor=[==0="blue",>=1="green",>5="orange"]
Text item=Doorbell_tstamp
//Text item=Arduino
}
Frame label="Visitor and manual image captures" {
Text label="Latest Doorbell image and setting" icon="doorbell1"{
Switch item=Reset_visitor_count
Text label="See latest Visitor image..." icon="video"{
Frame label="Latest visitor image.." {
Text item=Doorbell_tstamp
Image url="http://localhost:8080/doorcam/visitor.jpg"
}
}
}
Text label="Manual image capture and settings" icon="video"{
Frame label="Capture and send via email" {
Switch item=Take_doorstep_pic
Switch item=Send_pic_email
}
Frame label="See Latest captured Image" {
Text label="Latest Image and time" icon="video"{
Frame label="Latest Image.." {
Text item=Manual_tstamp
Image url="http://localhost:8080/doorcam/man_pic.jpg"
}
}
}
}
}
}
This short video shows scripts for handle pi-camera and directories structure for image database with time stamp...
Here are some pics of my openhab url...
