![[Pasted image 20241018000423.png]] ## Introduction This tutorial will guide you through setting up a system to measure and record the energy produced by a solar array, wind turbine, or biomass-powered generator. Once set up, you can easily add other sensors and actuators to build various automated systems, including solar-and-trash-powered biospheres! ## Bill of Materials | Item | Description | | -------------------------- | --------------------------------------------------------------- | | Raspberry Pi 4B | The Pi5 is launching soon but may require different setup | | SD Cards | 16GB+ and 32GB+ | | Argon One case | For the Raspberry Pi | | SSD | 128GB or larger | | PeaceFair PZEM-017 | Energy Monitor | | Distribution Blocks | For power distribution | | ESP32 - DEVKIT 1 | Microcontroller | | TTL to 485 converter board | For communication with [[PeaceFair PZEM-017]] | | Level Shifter | For voltage conversion | | Breadboard | For prototyping | | Jumper Wires | For connections | | Lever Lock Connectors | For secure connections | | **Total Cost** | $200-250 | ![[Pasted image 20241018000440.png]] ## Software 1. **RaspberryPi Imager**: For flashing software onto SD cards 2. **Home Assistant**: Open-source smart home platform 3. **ESPhome**: For flashing firmware onto ESP32/ESP8266 boards 4. **InfluxDB**: Time-series database for long-term data storage 5. **Grafana**: For data visualization and analysis 6. **HACS (Home Assistant Community Store)**: For community-developed themes and integrations 7. **LCARS Theme**: Star Trek-style theme (optional) 8. **Rhasspy Voice Assistant**: Local voice assistant for Home Assistant ## Setup Steps ### Preparing the Raspberry Pi 1. Download and install RaspberryPi Imager 2. Flash Boot Utility onto 16GB SD card 3. Assemble Raspberry Pi in Argon One Case 4. Install SSD and adjust jumpers to bypass off switch 5. Boot Pi with boot SD, then shut down 6. Use Imager Tool to flash Home Assistant onto 32GB SD card 7. Insert SD card into Pi and connect to router via ethernet 8. Boot the Pi ### Setting up Home Assistant 1. Log in and set up Home Assistant ### 1. **Set Up ESPHome in Home Assistant** 1. In Home Assistant, go to **Settings** > **Add-ons** > **Add-on Store**. 2. Search for **ESPHome**, click on it, and install the add-on. 3. Start the add-on and enable **Show in Sidebar** for easy access. ### 2. **Prepare Your ESP-WROOM-32 Configuration** 1. Open the ESPHome add-on in Home Assistant. 2. Click **+ New Device** to create a configuration. 3. Enter a **name** for your device (e.g., "esp32_sensor"). 4. Select **ESP32** as the device type. 5. Choose your Wi-Fi **SSID** and **password** to connect the ESP32 to your network. 6. Set a strong password for OTA updates to ensure secure future updates. ESPHome will generate a basic configuration YAML file. You can customize it later, but for now, it will include the essentials to get the ESP-WROOM-32 communicating with Home Assistant. ### 3. **Connect the ESP-WROOM-32 to the Raspberry Pi** 1. Plug the ESP-WROOM-32 into one of the Raspberry Pi’s USB ports. 2. In the ESPHome interface in Home Assistant, open the device’s configuration and click **Install**. 3. Choose **Plug into this computer** and select the correct USB port. ### 4. **Flash the ESP-WROOM-32** ESPHome will compile the firmware and flash it onto the board through the USB connection. This process may take a few minutes. 1. Once the flashing is complete, the ESP-WROOM-32 will automatically restart and attempt to connect to your Wi-Fi network. 2. If the setup was successful, you should see the ESP device online in ESPHome and in Home Assistant. ### 5. **Enable Future OTA Updates** Now that the initial setup is complete, you can update the ESP32 over-the-air (OTA) in the future without needing a physical connection. 1. To make changes or add features, edit the device’s YAML configuration in ESPHome. 2. Save and select **Install**, then **Wirelessly** to upload new firmware OTA. ### Basic YAML Configuration Example Here’s an example of the ESPHome YAML configuration that should now be installed. Now you can modify this code by inserting in between the "Logger" and "API" sections. ```yaml esphome: name: esp32_sensor platform: ESP32 board: esp-wrover-kit wifi: ssid: "Your_WiFi_SSID" password: "Your_WiFi_Password" # Enable OTA updates ota: password: "Your_OTA_Password" # Enable logging logger: # Additional Code Goes Here # API section is for Home Assistant communication, do not remove api: password: "Your_API_Password" ``` This configuration enables Wi-Fi, logging, OTA updates, and the API required for communication with Home Assistant. ### Setting up the [[DC Energy Monitor]] 1. Connect [[PeaceFair PZEM-017]] to ESP32 using TTL to 485 converter and level shifter 2. Edit device code in ESPhome 3. Upload new firmware 4. Reconfigure device in Home Assistant to add new sensor readings ### Adding InfluxDB and Grafana 1. Install InfluxDB add-on 2. Install Grafana add-on 3. Configure both for data storage and visualization ### Installing HACS and LCARS Theme 1. Install HACS integration 2. Use HACS to install LCARS theme 3. Follow documentation to activate the theme 4. Restart Home Assistant ## Conclusion You now have a fully functional solar energy monitoring system with long-term data storage and visualization capabilities. You can expand this system by adding more sensors and creating automations based on the collected data.