All other packages come bundled with the firmware. With this, the Home Assistant part is all set to take in temperature and humidity readings. If you're searching for your own smart devices and aren't sure if they'll work with Home Assistant, a Google search with the device + Home Assistant should at the very least give you some Home Assistant forum questions with answers to help you decide. Home Assistant will automatically scan your network to add devices. With this, Toit is all set and we can begin with programming. Sign Up on Toit and headover to Web serial interface in Chrome or Edge browser only. You'll also see that from Home Assistant, the light bulb symbol of the light also turned on. This site uses Akismet to reduce spam. Finally, well also send a high-temperature notification alert through the Home Assistants mobile phone app. I'm sending the entire state of this MQTT device, which includes the values of 3 sensors, as a JSON object to Home Assistant. Well it's actually quite similar to coding it manually in Home Assistant. If it prompts for opening a.yaml file, select the one which we just created. We are going to use the temperature sensor LM35 connected to the A0 of ESP8266 like in the following picture. And your devices should now be visible either from the overview or unused entities pages. value_template: "{{ value_json.temperature }}", value_template: "{{ value_json.humidity }}", The state_topic parameter defines the MQTT topic which will be subscribed for getting the data. Click on Start Listening. ssh to your Rapsberry Pi. I help you achieve great SEO, higher conversions, and help you grow your business, MQTT Discovery with a NodeMCU and Home Assistant, create a simple MQTT switch in Home Assistant. esp8266 arduino sensors nodemcu mqtt Once restarted, make sure that your ESP32 is running and you should start receiving notifications on your phone if it gets too hot. Add WiFi to your project with this hookup guide for our Dialog's Ultra Low Power DA16200 R3 shield! With everything working as expected, we can now deploy the application. Coming to the main function, we configure the GPIO pins 21 and 22 for I2C communication. The Configurator allows you to browse and modify the files on your Pi. If the syntax is correct, it will display a message "Configuration Valid". Connect the ESP32 to your PC via USB-cable and click on Lets start. We'll setup the Mosquitto broker the same way we did the Configurator. The switch uses the MQTT platform, and has a name called "Example_Switch". Type in the credentials and click on create. nodemcu interfacing This way, your MQTT device announces itself to the broker, without you having to manually configure the broker. It's great to combine this with something like Grafana and InfluxDB, because you'll see the sensor values show up right after you plug in your device. The output should be like the following and will keep on repeating at an interval of 10 seconds. Create a new.toit file in the project folder and name it sht31-mqtt.toit. The light will listen for commands from the topic "room/light", which is the same topic we defined in the ESP32's Light Arduino sketch. In this tutorial we'll cover how to set up Home Assistant, and regardless of whether you created the devices yourself or purchased off the shelf IoT devices, get them working together in harmony. Repeat the same for Humidity and close the dashboard editing. mqtt_server is where your Mosquitto broker have been installed, this would be the ip address of your Raspberry Pi where you have installed Home Assistant. In the post that I've linked to in the introduction, I've explained how you can manually tell Mosquitto to listen to a certain topic. protocol and well be using it to send temperature and humidity values coming from an SHT31-D sensor. we'll need those credentials later when we set up our ESP devices. When the message "on" is received, it will turn on the LED connected to IO pin 13, and when "off" is received, turn the LED off. To view them, click on the 3 vertical dots along the top right and select Unused entities as shown below. For the trigger, we'll select MQTT as the trigger type, with the topic set to "room/plug", and for the payload enter "toggle". To test whether everything is working properly, run the program by clicking on the run button associated with your device in VS codes Toit extension. Well be using it in this tutorial. Execute the following commands in the working directorys terminal: The SHT31-D and MQTT packages (or libraries) are now installed locally in the Toits working directory. Navigate to the configuration file located at /config/configuration.yaml. What we are trying to do can be seen in the following picture: We will have a temperature sensor connected to ESP8266 and using MQTT messaging we will post the temperature reading to Mosquitto MQTT broker in Home Assistant. Once the configuration is valid, press "RESTART" under Server Management, and wait a minute for the changes to be applied. Before we can start using MQTT, we need to configure Home Assistant's MQTT broker. Once it comes back online, click on configuration on the left menu bar, and click on integrations (http://hassio.local:8123/config/integrations/dashboard). Click on Provision, enter the Wi-Fi credentials and wait for the provisioning process to complete. This is a discovery message for the temperature sensor of this certain device: As you can see, this script specifies a value_template for this specific sensor. Luckily, Home Assistant has an amazing feature that helps you to automate this process: MQTT discovery. So as the result we will be able to monitor the temperature. You may receive a few notifications to set up the devices found, typically these are home media devices, such as Google cast, Plex, etc. The line states.sensor.temperature.state | float > 30.00 defines the temperature threshold, which is 30 degrees in this case. Fill in the information for your WiFi credentials (your WiFi network must be on the same network as the Raspberry Pi), your user name and password you created for Home Assistant, and the IP address of the Pi. I hope this was helpful to you! Once the code has uploaded, and the server has restarted, go to your overview or unused entities, and make sure your automation is enabled. Once pressed the button will publish to the topic room/light with message of "on" or "off". is one of the largest open-source platforms for home automation and is very popular for managing things through IoT. The last section explains how you can configure Home Assistant to send alerts using its companion app. Finally, click on the Deploy button associated with your device. If both of those are right, the MQTT broker might not have been set up correctly. "value_json" parses the incoming JSON string as a JSON object, so we can use the dot notation to get nested values. One of the benefits of Home Assistant is it's open source, allowing people from the community to create their own add-ons on top of the officially supported add-ons, which can make customizing it a lot faster and easier than other options. To get our automation to trigger correctly, we'll want to change our topic to "room/plug" and change the message we're sending to only be "toggle", to match the trigger event of our automation. Once the network has been setup, insert the SD card and USB stick, if used, into the Pi. Also, you need to change the last line to your phones name which we noted in the previous step. Execute the following commands in the working directorys terminal: toit pkg install github.com/harshkc03/sht31-d_driver. Enough talk, let's see some code! In our first example we added devices to Home Assistant using devices that we programmed ourselves. Now, click on RE-CONFIGURE MQTT. If. I break my disovery messages into functions, so I can group them together while not pollution the heart of the Arduino program. The float readings are limited to two decimal points and the data is published in the JSON format. Inside the configuration.yaml file, paste the following code at the bottom. Similar to python, YAML files use indentations to indicate nesting, so be careful with your indents when you modify a YAML file. For more information about about Home Assistant, check out some of the links below: Need some inspiration for your next project? In November (2020), I started to work with MQTT to set up a few smart devices in Home Assistant. To check whether there is any error, you will have to look at the Home Assistant log file, this is located at Configuration->General->Log and make sure there is no error related to the configuration. To fix that, we'll need to get Home Assistant to subscribe to those same topics, which is done by adding the components to the configuration file. Even though the server is running in the background, Home Assistant doesn't know what topics the Thing Plus boards are subscribing and publishing to. As we are using I2C communication with the sensor, the connection requires only four wires. In total, there are 3 sensors on the device right now. Automations consist of three parts: The trigger which starts the processing of an automation rule, the optional conditions which can be used to prevent an action from happening when triggered (e.g. If all goes well, one minute later the ESP8266 should have published the temperature reading and you are able to see this like the following picture: Now that we know our MQTT broker is working ok. At this point the temperature reading will not be reflected into the main home screen.

Head over to Configuration > Users and click on Add user. The very first thing would be to install the SHT31-D sensors driver and MQTT package from pkg.toit.io. After that we set up the MQTT client with the username and password, which we had set in the MQTT broker. Now your circuit is complete. With this, Toit is all set and we can begin with programming. Each of these sensors have their own "state", which means they all need their own discovery topic as well. publish client/mqtt.Client temp/float hum/float: print "Published message `$temp` on '$TOPIC'", // Publish readings at interval of 10 seconds, publish client driver.read_temperature driver.read_humidity, Sending high-temperature alerts to mobile phone, The last section explains how you can configure Home Assistant to. Again, this is my personal use for it and it might differ from you own uses. It is recommended to install VS code and Toits language extension as told in the installation link for hassle-free development. Login to your Home Assistant and select Configuration->Integration from the left menu, then click on the yellow + button on the bottom right hand corner and search for Mosquitto: Then click on Configure button in the MQTT tile: Enter the topic to listen to Listen to a topic section in the configuration. If you're able to connect to the network and not the Pi, make sure the IP address is correct, as well as the credentials for Home Assistant. . Make sure the status is. Instead of configuring each sensor in Home Assistant, you're configuring it in your Arduino program and sending that to Home Assistant. This confirms that our MQTT broker is all set. But with having a WiFi remote for your switches, it's likely that battery power would be preferable to allow moving the switch anywhere you'd like. Connect power to the Pi, and wait for the OS to boot. So we can add our own devices, and that's cool I guess, but that was basically working in the MQTT tutorial. YAML files are a human-readable data serialization language, similar to header files in C++, which are commonly used for configuration files. Next, we will create a function for publishing the temperature and humidity readings on the MQTT topic. (480x320), http://hassio.local:8123/lovelace/hass-unused-entities, http://hassio.local:8123/config/integrations/dashboard, http://hassio.local:8123/config/automation, Example 1.5: Controlling the ESP32 from Home Assistant, Using Home Assistant to Expand Your Home Automations. Pretty cool! In the first example, we connected two ESP32 Thing Plus boards to Home Assistant's Mosquitto broker. I won't discuss these specific things, as they will differ for you: I'll discuss each of these topics in separate posts, as they're not relevant for this topic. The parameter repeat: 1 defines the time interval in minutes after which the notification will appear again. Make sure you terminate the run command, which we did in the previous step before deploying the application (Uninstall it under the Apps section in Toit console). In this post, I'll go over a few things that I've done to use this feature to automate my MQTT devices.

In the first example we sent messages over MQTT of "on" and "off" over the "room/light" topic. For all your Computers & Electronics needs. When you push the button this time, you should notice a delay before the plug turns on or off. To see what devices are currently supported from Home Assistant, check out the components page. It makes using new devices as simple as powering it on and leaving it alone. Now to test whether the broker is working properly, add any sample topic in the publish and listening field (make sure the same topic is in both the fields). The second ESP32 will subscribe to the same topic room/light and listen for messages from the switch. Thanks for your comment, I am glad that you find this useful. This way, I can use normal batteries to power this device and have them last much longer. For this first example we'll connect two ESP32 Thing Plus boards to our network over MQTT. Guide for getting going with the Raspberry Pi 3 Model B and Raspberry Pi 3 Model B+ starter kit. The payload is the message being sent over the command topic to turn the light on and off. The temperature sensor LM35 have 3 legs, the first leg is VCC, you can connect this to the 3.3V (ESP8266 boards output is 3.3V). you can quickly set up your ESP32 device using the Web serial interface. My main use of the MQTT devices are plant sensors. Finally, make sure the file is saved and restart the Home Assistant server. First click on "Configurator" from the left menu bar. Once that's done we can save changes by pressing save icon. To check the configuration, go to the tab labeled Configuration NOT Configurator along the left side, and select General, and click "CHECK CONFIG". Fill in the information for your WiFi credentials (your WiFi network must be on the same network as the Raspberry Pi), your user name and password for Home Assistant, and the IP address of the Pi. The second device we'll add is the light component just below the switch component with an empty line separating the switch component with the light component. The output should show that the app was successfully deployed. The data will then be displayed in Home Assistant in interactive cards with the graphical format. Hookup guide for the ESP32 Thing Plus (Micro-B) using the ESP32 WROOM's WiFi/Bluetooth system-on-chip in Arduino. How can you use MQTT Discovery on an NodeMCU? Depending on your setup, you may also need the following. You can also link it with other users on your server, but creating a new one is recommended. It is recommended to install VS code and Toits language extension as told in the installation link for hassle-free development. To create an automation, select configuration from the left menu bar, and click automation (or go to http://hassio.local:8123/config/automation) and click the "Add Automation" button from the bottom right. All programs used in this tutorial can be found inthis Github repository. The data will then be displayed in Home Assistant in interactive cards with the graphical format. This feature is one of my favorite discoveries recently, so I hope you enjoy it as well! Next, go to Configuration > Integrations and click on Configure under Mosquitto broker. The switch will command (or publish to) a topic called "room/light", this is the same name of the mqtt topic we're publishing to in the ESP32's Switch Arduino sketch. The first thing we'll initialize is the broker. Click on Provision, enter the Wi-Fi credentials and wait for the provisioning process to complete. Weekly product releases, special offers, and more. Use RealVNC to connect to your Raspberry Pi to control the graphical desktop remotely across the network.

To view the available add-ons, click on the Hass.io tab on the left side menu, followed by clicking on the ADD-ON STORE tab along the top as shown below (similarly, you can go to http://hassio.local:8123/hassio/store). It doesn't matter where these lines go in the file, but we'll place it just below the discovery. This guide hasn't even scratched the surface of what Home Assistant is capable of. Finally, save the configuration file and restart your Home Assistant server. homeassistant/sensor/plant_sensor_1/temperature/config, homeassistant/sensor/plant_sensor_1/humidity/config, homeassistant/sensor/plant_sensor_1/moisture/config, Reading Sensor data in your Arduino program, Sending MQTT sensor data to Home Assistant. In this example we'll create an automation to be triggered from the first MQTT example to toggle the Wifi Plug of the second example to show how to use Home Assistant to take a device that you made and programmed to control a commercially available device, or in our case a WiFi plug switch. Home Assistant is able to know what the state is of the MQTT light by using the state_topic both in the configuration file as well as publishing to the topic from the light's Arduino sketch. Head over to Supervisor > Add-on store and search for Mosquitto MQTT. After clicking on it, a list of fields will appear. Copy the following lines into the configuration file. In this case you will enter home/livingroom/temperature. When done press save, and restart the server. We'll need the name of the app and our login credentials when we add the plugs to Home Assistant. We enabled MQTT from the add-on store, but now we need to configure it. In this section we'll need to enable two extensions: Configurator and MQTT. In the Payload field, type in any message and click on Publish. The state_topic parameter defines the MQTT topic which will be subscribed for getting the data. With this verified, we can now set the automatic alert. The name is only used to remember what the automation does, so we can simply put "MQTT -> WiFi Plug". Every time we make a change to any of the files, we'll want to first check that the configuration is valid, and then restart Home Assistant. The middle leg is Vout (where the temperature is read from, you can connect this to the analog input of the ESP8266 pin AD0, this is located at the top right hand side of the board as shown in picture. For more information about MQTT, check out the MQTT tutorial. In this case, it is mobile_app_redmi_5. If you don't immediately see your device, you can try searching for your device under the left side bar based on its function.