Diet Tracker Desk Lamp
Eating healthy is hard and tracking what to eat - even harder!
We wanted to find a way to
- Generate recipes based on general nutritional value.
- Express eating trends in a general and intuitive way, with a color and a single number.
To achieve this:
- We built a Telegram chatbot that triggers a
- Make.com scenario,
- Generating the recipe via ChatGPT
- and updating a Google Sheet,
- which tracks the recipes that were consumed
- from where we extrapolate an overall health grade,
- and update the Desk Lamp ESP32.
- The ESP32 sends the update to a Sonos speaker via NodeRed, which reads it out whenever a meal is marked as prepared.
Supplies
Physical:
- 1X ESP32 microcontroller,
- 1X LED strip with 12 bulbs,
- 1X Square cardboard box (in our case - ariel capsules for washing clothes, 24cm * 9cm * 6.5cm),
- 2X A4 papers for light dispersion and to cover the insides and outside of the box.
- Gorilla glue to stick it all together.
- 1 Sonos Speaker (you may choose another smart speaker).
Services:
- Telegram account,
- Make.com account,
- Google Sheet,
- Node.red,
- Ngrok for hosting,
- HiveHQ for as a MQTT queue.
Telegram Bot
- Create a Telegram Account if you didn't have one.
- Search for "Bot Father" and choose /start
- Follow the instructions of the bot:
- Add the following commands:
- start - Get a new set of recipes for the day
- breakfast - breakfast recipe
- lunch - lunch recipe
- dinner - dinner recipe
- prepare_meal - when you’re ready to start making the meal, choose option and update the sheet
- cancel - start over
- Save the API token
Google Sheets
- Create a new Google Sheets called: my_diet_tracking
- Rename the sheet to Meals
- Add the following columns: "Meal, Meal Of The Day, Ingredients, Health Grade, Nutritional Info, Health Prompt, Eaten?"
Set Up Ngrok
- Create an ngrok account and install locally. (only for dev purposes, should be https in production)
- Open terminal and do (check how to do it on a Windows machine)
ngrok http 192.168.1.184:80
- Leave it open for testing purposes.
Make.com Scenario
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
- Trigger Module: Start by adding the Telegram: Watch Updates module. This module will trigger the scenario every time your bot receives a message.
- 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
- Router Module: After the Telegram trigger, add a Router module to handle different user commands.
- Path 1 - /start Command:
- Action: Sends a message prompting the user to choose a meal type (e.g., "/breakfast", "/lunch", "/dinner").
- Path 2 - Meal Type Commands (/breakfast, /lunch, /dinner):
- Action: Sends a follow-up message asking the user what kind of recipe they want (e.g., "/healthy", "/corrupt").
3. Handling Meal Selection
- 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.
- Path 1 - /healthy Command:
- Datastore Action: Use the Datastore: AddRecord module to save the user's meal choice and the type of recipe they want.
- Generate Recipe: Utilize the OpenAI GPT-3: Message Assistant Advanced module to generate a healthy recipe based on the user's meal choice.
- Path 2 - /corrupt Command:
- Datastore Action: Similarly, use the Datastore: AddRecord module to save the choice of a less healthy or indulgent recipe.
- Generate Recipe: Use GPT-3 to create a recipe that matches the user’s preference for something "corrupt."
4. Storing and Retrieving Recipe Data
- Recipe Data Storage:
- 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.
- Datastore Update: Add a Datastore: UpdateRecord module to update the stored information with the extracted data.
- Data Retrieval and Processing:
- Meal Preparation: If the user selects /prepare_meal, retrieve the stored recipe data using the Datastore: GetRecord module.
- 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
- Replying with Recipe:
- 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).
- Final Data Storage:
- 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
- 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
- Install NodeRed locally.
- cd ~/.node_red (check NodeRed module installation instructions if in of on a Windows machine)
- Do npm install node-red-contrib-tts-ultimate.
- Add mqtt in node and configure it to your notification topic (ex sonos/notification).
- Add a TTS-Ultimate Player and choose your smart speaker in the TTS-Ultimate Player options.
Configure HiveMQ
- Create a HiveMQ account,
- Create new cluster. Save the
- Go to the "Access Management" tab and create a new pub/sub access credentials pair and save them securely.
ESP32 - HW and Sketch
- Ensure you have the necessary drives to connect to the port for uploading the sketch(differs on Windows/Mac OS)
- Download Arduino Sketch.
- Download the attached sketch.
- Change the WiFi credentials, HiveMQ server, topic user and password
- Based on the availability of your network (check your router admin page) add: local_IP, gateway, subnet, primaryDNS, secondaryDNS.
- Attach the LED strip to PIN 5.
- Add the certificate for HiveMQ (if in production).
Downloads
Run the Telegram Bot for Testing
- Choose /start,
- Choose meal of the day,
- Once the recipe is generated, choose \prepare_meal if your satisfied or \cancel if you want to start over,
- 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
- Cut on of the A4 papers so they fit the sides of the box. Make sure you cover all colored parts of the cardboard
- Glue the pieces to the cardboard
- 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.
- punch a hole into the back of the box so you can fit a power supply through
- 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.
- Et Voila, you have your desk lamp!