element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Forget Me Not Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Forget Me Not Design Challenge
  • More
  • Cancel
Forget Me Not Design Challenge
Blog Episode 4: Forget Me Not: Medication System
  • Blog
  • Forum
  • Documents
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: michaelwylie
  • Date Created: 17 Aug 2014 5:46 AM Date Created
  • Views 2120 views
  • Likes 1 like
  • Comments 11 comments
  • forget_me_not
  • forget-me-not
  • iot_monitor_auto
  • forget-me-not-challenge-2014
Related
Recommended

Episode 4: Forget Me Not: Medication System

michaelwylie
michaelwylie
17 Aug 2014

Previous Posts:

Epidode 1: Forget Me Not: Application

Episode 2: Forget Me Not: The Best Laid Plans ...

Episode 3: Forget Me Not: Setup EnOcean with openHAB

 

I was notified of a possible delay in shipment from Newark, so I have worked on the Medication Reminder System in the mean time. It took a while to work through the examples on https://github.com/openhab/openhab/wiki/Samples-Rules to learn about setting up rules. My rules system can be summarized as follows:

 

1. Initialize System - Set The rocker switch states

 

This part is extremely important. Even though I can load the openHab interface and see the state of the switches are not ON it doesn't mean the states of the switches are OFF. There must be a tri-state option? In demo.rules I have this rule for the system startup.

 

rule "System Start"          //demo.rules
when
    System started
then
    Rocker1B.setState(OFF)
    Rocker1A.setState(OFF)
    medicationTakenFlag = 0          //Flag set when medication taken
end

 

Note: In demo.items, my rocker switches are defined as:

Switch Rocker1A {enocean="{id=00:29:E4:66, eep=F6:02:01, channel=A}"}
Switch Rocker1B {enocean="{id=00:29:E4:66, eep=F6:02:01, channel=B}"}

 

2. Set the medicationTakenFlag when I take the medication

 

If the Rocker Switch is pressed, the medicationTakenFlag gets set.

 

//Set the medication flag when I take my medication
rule "Medication Taken"
when
    Item Rocker1A changed from OFF to ON
then
    medicationTakenFlag = 1
end

 

3. Attempt to leave the home without taking medication

 

I have mounted a magnetic contact switch on my front door and named it EnOcean_sensor_CONTACT2. If I attempt to leave the home without having set the medicationTakenFlag (pressing the rocker switch) my Raspberry Pi will notify me with a voice command "Take Medication". This should only occur after 4 AM, because before that would just be annoying.

 

//Haven't taken medication and leave the apartment
rule "Remind Me While I am Leaving"
when
    Item EnOcean_sensor_CONTACT2 changed from CLOSED to OPEN
then
    var Number hour = now.getHourOfDay
    if ( (Rocker1A.state == OFF) && (hour > 4) )
    {
        //Rocker1B.setState(ON)
        say("Take Medication")
    }   
end

 

4. Reset the rocker switch everyday at 3:59 AM.


This should be one of the easiest settings, but I had to learn how cron works in Linux to setup the check.Have a look here for the details Quartz Scheduler | Documentation | Tutorial Lesson 06. It's still a bit confusing. The code below should turn off the rocker switch and reset the medicationTakenFlag at 3:59:00 AM everyday.

 

//Reset medication flag every night at 03:59
rule "Reset me"
when
    Time cron "0 59 03 * * * "        //03:59:00 AM everyday
then
    sendCommand(Rocker1A, OFF)
    medicationTakenFlag = 0;
end

 

5. The last rule is a little trickier. What if it's the weekend or I have the day off? I still need to be reminded if I didn't take the medication.

 

This last rule reminds me every 15 minutes between 8AM and 11AM if medicationTakenFlag is not set that I should take the medication. I will come up with a better way to do this one eventually because this could get really annoying.

 

rule "Remind Me and I Haven't Left"

when
    Time cron "* */15 * * * ?"
then
    var Number hour = now.getHourOfDay
    if ((hour > 8) && (hour < 11) && (medicationTakenFlag == 0))
        say("Take Medication")
end

 

That's the medication system so far. Next I might try to get Notify My Android to notify our smart devices at home as well as the voice command to take medication.

 

Things I learned this week:

  • Initialize switch states, holy moly this can cause you a lot of grief!
  • The smart phone apps respond a lot quicker than the web interface. I was watching the web interface waiting for a rocker switch state to change but it didn't change until I reloaded the interface. The app responds immediately.
  • If you are working in openHab designer and you want to see the autofill options, ie you type Rocker1A. and you want to see the parameter options, hit ctrl-space.
  • Sign in to reply
  • mcb1
    mcb1 over 11 years ago

    Nice work

     

    I've been looking at the openhab stuff today and scratching my head to find a simple list of what you can do, use and the syntax.

    The demo is fine but doesn't include or explain anything.

     

    Mark


    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
<
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube