====== Home Assistant Installation ====== This guide was written using Home Assistant version 2024.5.x. ==== Raspberry Pi Setup ==== - Install Raspberry Pi imager https://www.raspberrypi.com/software/. {{ 1rbdl.png }} - Insert the Micro SD card to the SD card reader. - Run the application. - Choose Device (Raspberry Pi 4 in this case). - Choose Operating System (“Other specific-purpose OS” -> “Home assistants and home automation” -> “Home Assistant” -> “Home Assistant OS 12.x”). - Choose Storage. {{ 2rbst.png }} - Click “Next” -> “Yes”. (Ignore Microsoft Error messages). - Remove the Micro SD card. - Insert the Micro SD card into the Raspberry Pi’s Micro SD card slot. - Connect Raspberry Pi to power via the USB-C (or Micro-USB depending on the model) port. - Connect the Raspberry Pi to your network via the ethernet port on the Pi, make sure your computer is connected to the same network as well. - Home Assistant Installation happens automatically if the Micro SD card is inserted and the Raspberry Pi is powered on. This might take a few minutes. If you want to monitor the installation, connect the Raspberry Pi through its mini-HDMI port to a display. - Open a web explorer, navigate to http://homeassistant.local:8123/ and hit enter. - Wait for the setup to finish and click on “Create My Smart Home”. - Create a user using your preferred credentials. ==== HACS Installation ==== Home Assistant Community Store (HACS) is a third-party download manager for Home Assistant which contains various custom integrations. We need to install LocalTuya integration through HACS to locally control the pet feeder. This guide was written using HACS version 1.34.0. - Go to your user profile and enable “Advanced mode”. {{ 3ha.png }} - Go “Settings” -> “Add-ons” -> “Add-on store” -> search “SSH” -> Install “Terminal & SSH”. - After the installation is complete, enable “Show in sidebar” {{ 4ssh.png }} - Navigate to “Terminal” on the sidebar, if it appears not to be running or if you are receiving error codes, refresh the instance. - Copy and paste (CTRL+SHIFT+V to paste) the following command to the terminal and hit Enter. This will initiate the installation of HACS.\\ wget -O - https://get.hacs.xyz | bash - {{ 5ssh.png }} - After the installation is completed, restart the home assistant (“Settings” -> three dots on the top right -> “Restart Home Assistant” -> “Restart Home Assistant”). - Home Assistant should automatically restart, if the browser crashes, refresh the browser page to access Home Assistant again. - Navigate to “Settings” -> “Devices & Services” -> Click “Add Integration” on the bottom right corner. - Type “HACS” on the search bar, click on the result. {{ {{ 6hacs.png }} }} - Check all but the last checkbox and submit. {{ {{ 7hacscb.png }} }} - Create a github account if you don’t have one. - HACS will ask you to activate device through your github account. Follow the instructions provided and link HACS with your github account. {{ 8hacsgit.png }} {{ 9hacsgit.png }} - Click on “Authorize” and exit github. - If everything is set correctly you should have installed HACS on your Home Assistant. Do not pick an area on the pop-up and click on “finish”. - Now HACS should show up on the sidebar of Home Assistant UI. ==== LocalTuya integration Installation ==== LocalTuya integration is what we need to control the pet feeder locally. This guide was written for LocalTuya version 5.2.1. - On the HACS tab, click on “Integrations”. {{ {{ 10hacs.png }} }} - Click on "Explore & Download Repositories" on the bottom right, on the pop-up search, type "LocalTuya". Click on the result. {{ 10ltuya.png }} - Click on “Download” on the bottom right. Click on “Download” again on the pop-up. {{ 11ltuyai.png }} ==== Adding Pet Feeder to Home Assistant ==== - Download the “Tuya Smart” app to your smartphone (version 5.13.0 was used for this guide). - Press both buttons on the pet feeder at the same time. - Run the “Tuya Smart” app, press “Add Device”, the Pet feeder should appear automatically, turn on your Bluetooth if it doesn’t. Insert the wireless credentials and press login. **Make sure the pet feeder and the Home Assistant are in the same network**. - Navigate to [[https://auth.tuya.com/register?from=https%3A%2F%2Fdeveloper.tuya.com%2Fen%2F | Tuya IoT development platform]] and create an account. {{ 12tuyacc.png }} - Once the account is created, navigate to the [[https://platform.tuya.com/ | developer platform]] on the top right corner of the page you were redirected to. - Skip the tutorials, hover the cursor over “Cloud” on the sidebar and click on “Development”. {{ 12ltuyacloud.png }} - Click on “Create Cloud Project" on the Development page. Fill in the project details. Pick “Custom” Development method and “Central European Data Center”, pick the rest as you see fit. {{ 13tuyacproj.png }} - In the next step, add "Smart Home Basic Service" and "[Deprecate]Device Log Query" to the selected API services. Click on "Authorize". {{ 13tuyzapi.png }} - Now that the project is created, let’s add the pet feeder to the project. Navigate to “Devices” -> “Link Tuya App Account” -> "Add App Account". {{ 14tuya.png }} - A QR code will appear, open the “Tuya Smart” app on your phone, press on “Me” on the bottom right and then press on the scan icon on the top right, scan the QR code. - After the QR code is scanned, pick “Automatic Device Linking Method” and click on OK. {{ 16tuyaaut.png }} - Once the linking is complete, you should be able to see your account details on the “Link Tuya App Account” tab. **Make note of the “UID”**, we will use this later. Click on “Manage Devices”. {{ 17uid.png }} - If the Pet Feeder is shown as unlinked, check the checkbox next to the pet feeder and hit “Link Device”. {{ 18deviceadd.png }} - Confirm the pet feeder exists on the “All Devices” tab, do not close this webpage. {{ 19deviceconf.png }} - Navigate back to the [[http://homeassistant.local:8123/ | Home Assistant UI]] - Go to “Settings” -> “Devices & Services” -> “Add Integration” on the bottom right corner, Search for “LocalTuya”. Click on “LocalTuya Integration”. {{ 20addlt.png }} - Once LocalTuya is installed, Cloud API configuration pop up will appear. Make sure API server region is EU. For the rest of the credentials, we need to navigate back to [[https://platform.tuya.com/ | Tuya developer platform]]. {{ 21cred1.png }} - On the left sidebar, hover on “Cloud” -> “Development” -> “Open Project”. The “Client ID” and the “Secret” can be found under the “Overview” tab of the cloud project. (not the Overview on the sidebar, the one under our project name). {{ 22keysecret.png }} - Insert the credentials back to Home Assistant. Use the previously mentioned “UID” from “Link Tuya App Account” tab and click on “Submit”. - LocalTuya Integration is now linked with your Tuya Development Account. We still need to configure the pet feeder for local use. - You will be redirected to LocalTuya integration page, if not, Navigate to “Settings” -> “Devices & Integrations” -> “LocalTuya”. - Click on “Configure” on the same page -> “Add a New Device” -> “Pet Feeder” (which should be recognized automatically) and submit. {{ 23configlt.png }} {{ 24loctuyaconf.png }} {{ 25adddev.png }} {{ 26pfcfg.png }} - Skip to step 23 if the credentials of the Pet Feeder are configured automatically. If the Pet Feeder’s configuration is **not set automatically**, navigate back to the Tuya Developer Platform, hover on the “Cloud” icon on the sidebar -> “API Explorer”. {{ 26pfcfga.png }} - On the API explorer, Navigate to “Query Devices in Project” on “Device Management”. - Type “1” to “page_size” and click on “Submit Request”. - The response query gives us credentials of the device. We can find the local key and device id (called “id”). {{ 26pfcfgb.png }} - The Host address can be obtained via your router’s web interface. - After you submit, you will be met with the “Entity Type Selection” pop-up. The pet feeder has different functions such as dispensing food or turning the LED on the pet feeder on and off. Each of these functions has their own “Data Point ID” to communicate with the cloud. We need to intercept these Data Points and create separate entities to control the device via the Home Assistant. {{ 27entitiy.png }} - Do not exit the Home Assistant instance and navigate back to Tuya Developer Platform. Open your project and navigate to “All Devices” tab under “Devices” and click on “Debug Device”. {{ 28debug.png }} - On the device debugging page, under “Standard Instructions Set” are the functions of the device we can set new values for. Under “Standard Status Set” are the previously mentioned functions and the available sensors of the device. - To find out which Data Point is associated with which function of the device, navigate to “Device Logs” tab. {{ 28debug.png }} - Turn the developer console on of your browser (CTRL+SHIFT+I or F12 for Google Chrome). Navigate to “Network” tab on the developer console. - Notice the “Select DP ID” dropdown menu on the top left side of the page. - While the Developer console is on, click on the DP ID dropdown menu and select “Manual Feed”, click on “Search”. - After you click on “Search”, you should see the network tab of your developer console update with several different logs. “list” is the one we are looking for. {{ 30devc.png }} - Click on “list”, and navigate to the “Payload” tab, “Code” is the Data Point ID we are looking for. In this case it’s 3. {{ 32devcn.png }} - The ID is our Data Point, which is 3. - Navigate back to “Device Debugging” tab, make note of the manual_feed’s type and values. It’s an integer with a minimum value of 1, maximum value of 20 and with a step of 1. {{ 33feed.png }} - Navigate back to Home Assistant, last time, we were at the Entity Type Selection pop-up. “Settings” -> “Devices & Services” -> “LocalTuya” -> “Configure” -> “Add a new Device” -> ”Submit” -> “Submit”. - Let’s add the manual feed function to LocalTuya. LocalTuya includes integers in “number”, pick it from the dropdown menu and submit. {{ 34int.png }} - The “ID” dropdown menu includes DP IDs of the pet feeder, we know 3 is manual feed. From the dropdown menu, pick 3. Call it Manual Feed. The minimum value is 1, maximum value is 20 and the increment between values is 1. Click “Submit’. {{ 35manfeed.png }} - On the next step, the entity type selection will appear again, for now, check the “Do not add any more entities” and click “Submit” (we can always add more later). {{ 36dontadd.png }} - Now let’s see if the manual feed entity works. Click on "1 device" below the logo of localtuya. {{ 37ltd.png }} - Slide the Manual Feed to any value and check the Pet Feeder is dispensing food. {{ 38ctrl.png }} - Add more entities by repeating step 26 and beyond.