Diet Tracker Desk Lamp

by ef12 in Circuits > Arduino

24 Views, 2 Favorites, 0 Comments

Diet Tracker Desk Lamp

Diet Tracking Desk Lamp
final_product.jpg
IMG_976FC24DFC0F-1.jpeg
Screen Shot 2024-08-25 at 11.33.52 AM.png

Eating healthy is hard and tracking what to eat - even harder!

We wanted to find a way to

  1. Generate recipes based on general nutritional value.
  2. Express eating trends in a general and intuitive way, with a color and a single number.

To achieve this:

  1. We built a Telegram chatbot that triggers a
  2. Make.com scenario,
  3. Generating the recipe via ChatGPT
  4. and updating a Google Sheet,
  5. which tracks the recipes that were consumed
  6. from where we extrapolate an overall health grade,
  7. and update the Desk Lamp ESP32.
  8. The ESP32 sends the update to a Sonos speaker via NodeRed, which reads it out whenever a meal is marked as prepared.

Supplies

Physical:

  1. 1X ESP32 microcontroller,
  2. 1X LED strip with 12 bulbs,
  3. 1X Square cardboard box (in our case - ariel capsules for washing clothes, 24cm * 9cm * 6.5cm),
  4. 2X A4 papers for light dispersion and to cover the insides and outside of the box.
  5. Gorilla glue to stick it all together.
  6. 1 Sonos Speaker (you may choose another smart speaker).

Services:

  1. Telegram account,
  2. Make.com account,
  3. Google Sheet,
  4. Node.red,
  5. Ngrok for hosting,
  6. HiveHQ for as a MQTT queue.

Telegram Bot

IMG_D62A437FB6C9-1.jpeg
IMG_D7BFC495C7A7-1.jpeg
IMG_E42C7120516C-1.jpeg
  1. Create a Telegram Account if you didn't have one.
  2. Search for "Bot Father" and choose /start
  3. Follow the instructions of the bot:
  4. Add the following commands:
  5. start - Get a new set of recipes for the day
  6. breakfast - breakfast recipe
  7. lunch - lunch recipe
  8. dinner - dinner recipe
  9. prepare_meal - when you’re ready to start making the meal, choose option and update the sheet
  10. cancel - start over
  11. Save the API token

Google Sheets

Screen Shot 2024-08-25 at 11.33.52 AM.png
  1. Create a new Google Sheets called: my_diet_tracking
  2. Rename the sheet to Meals
  3. Add the following columns: "Meal, Meal Of The Day, Ingredients, Health Grade, Nutritional Info, Health Prompt, Eaten?"

Set Up Ngrok

  1. Create an ngrok account and install locally. (only for dev purposes, should be https in production)
  2. Open terminal and do (check how to do it on a Windows machine)
ngrok http 192.168.1.184:80
  1. Leave it open for testing purposes.

Make.com Scenario

Screen Shot 2024-08-25 at 14.34.29 PM.png
Screen Shot 2024-08-25 at 14.38.02 PM.png
Screen Shot 2024-08-25 at 14.37.24 PM.png
Screen Shot 2024-08-25 at 14.39.47 PM.png
Screen Shot 2024-08-25 at 14.40.30 PM.png

Attached photos are the flows within the scenario in order!

In this step, you'll configure a comprehensive Make.com scenario that interacts with a Telegram bot to help users select a meal, generate a recipe, and store relevant data. The scenario branches based on user input and includes actions such as sending messages, saving data to a datastore, generating content with GPT-3, and logging information in Google Sheets.

1. Telegram Bot Interaction Setup

  1. Trigger Module: Start by adding the Telegram: Watch Updates module. This module will trigger the scenario every time your bot receives a message.
  2. Webhook Configuration: Use the provided Webhook ID to connect the bot to your scenario. This ensures the bot is always listening for updates.

2. Routing User Commands

  1. Router Module: After the Telegram trigger, add a Router module to handle different user commands.
  2. Path 1 - /start Command:
  3. Action: Sends a message prompting the user to choose a meal type (e.g., "/breakfast", "/lunch", "/dinner").
  4. Path 2 - Meal Type Commands (/breakfast, /lunch, /dinner):
  5. Action: Sends a follow-up message asking the user what kind of recipe they want (e.g., "/healthy", "/corrupt").

3. Handling Meal Selection

  1. Healthy or Corrupt Recipe Selection:

The beauty of this is that you may choose your own objectives in this step by shaping the prompt; I used a very simple one:

"Generate a new recipe for a {{7.message.text}} meal. Provide instructions and a list of ingerdients. Use the metric system.
1.Include nutritional values for the meal for:
CaloriesCarbs (g), Protein (g), Fat (g), Vitamin A (%DV),Vitamin C (%DV),Calcium (%DV),Iron (%DV)
2. Give a 1-10 grade for its content.


  1. Path 1 - /healthy Command:
  2. Datastore Action: Use the Datastore: AddRecord module to save the user's meal choice and the type of recipe they want.
  3. Generate Recipe: Utilize the OpenAI GPT-3: Message Assistant Advanced module to generate a healthy recipe based on the user's meal choice.
  4. Path 2 - /corrupt Command:
  5. Datastore Action: Similarly, use the Datastore: AddRecord module to save the choice of a less healthy or indulgent recipe.
  6. Generate Recipe: Use GPT-3 to create a recipe that matches the user’s preference for something "corrupt."

4. Storing and Retrieving Recipe Data

  1. Recipe Data Storage:
  2. Structured Data Extraction: After generating the recipe, use OpenAI GPT-3: Transform Text to Structured Data to extract key elements such as ingredients, nutritional information, and the recipe name.
  3. Datastore Update: Add a Datastore: UpdateRecord module to update the stored information with the extracted data.
  4. Data Retrieval and Processing:
  5. Meal Preparation: If the user selects /prepare_meal, retrieve the stored recipe data using the Datastore: GetRecord module.
  6. Google Sheets Logging: Use the Google Sheets: Add Row module to log the details of the prepared meal in a Google Sheets document, allowing for easy tracking and analysis.

5. User Feedback and Final Actions

  1. Replying with Recipe:
  2. Send Recipe Details: Use the Telegram: Send Reply Message module to send the generated recipe back to the user. Include options to confirm preparation (/prepare_meal) or cancel (/cancel).
  3. Final Data Storage:
  4. Meal Confirmation: If the user confirms the meal preparation, log this action in both the Datastore and Google Sheets. Ensure that the meal status is updated accordingly.

6. Test the Scenario

  1. Testing: Run the scenario in Make.com to ensure all branches operate as expected. Make sure each user input leads to the correct outcome, whether it's generating a recipe, logging data, or sending a confirmation message.

Configure NodeRED

Screen Shot 2024-08-25 at 14.47.33 PM.png
  1. Install NodeRed locally.
  2. cd ~/.node_red (check NodeRed module installation instructions if in of on a Windows machine)
  3. Do npm install node-red-contrib-tts-ultimate.
  4. Add mqtt in node and configure it to your notification topic (ex sonos/notification).
  5. Add a TTS-Ultimate Player and choose your smart speaker in the TTS-Ultimate Player options.

Configure HiveMQ

  1. Create a HiveMQ account,
  2. Create new cluster. Save the
  3. Go to the "Access Management" tab and create a new pub/sub access credentials pair and save them securely.

ESP32 - HW and Sketch

  1. Ensure you have the necessary drives to connect to the port for uploading the sketch(differs on Windows/Mac OS)
  2. Download Arduino Sketch.
  3. Download the attached sketch.
  4. Change the WiFi credentials, HiveMQ server, topic user and password
  5. Based on the availability of your network (check your router admin page) add: local_IP, gateway, subnet, primaryDNS, secondaryDNS.
  6. Attach the LED strip to PIN 5.
  7. Add the certificate for HiveMQ (if in production).

Downloads

Run the Telegram Bot for Testing

  1. Choose /start,
  2. Choose meal of the day,
  3. Once the recipe is generated, choose \prepare_meal if your satisfied or \cancel if you want to start over,
  4. The lamp should start blinking when you receive the update in the health grade as was shown in the video and a voice notification.

Create the Lamp Casing

IMG_8403.jpg
IMG_8402.jpg
  1. Cut on of the A4 papers so they fit the sides of the box. Make sure you cover all colored parts of the cardboard
  2. Glue the pieces to the cardboard
  3. Cut the other A4 paper to fit over the box and folded in the middle and again on each side such that it will create a nice effect. No need to glue them so you can interact with the insides more easily.
  4. punch a hole into the back of the box so you can fit a power supply through
  5. Place the esp32 and the LED strip inside and place the paper you folded over the hole so it will fit nicely and cover all insides.
  6. Et Voila, you have your desk lamp!