How do i use home assistant and add functions?

hi. I have added a esp32c3 to my home assistant , (someone said home assistant makes everything much easier xD) so i have the esp32c3 connected with a dht22 humidity and temp, wich i want to view in home assstant… BUT HOW!??

I have it all working in arduino, but NOTHING works in home assistant…
inside the esp home tab it says:
With ESPHome, you can go from a few lines of YAML straight to a custom-made firmware. For example, to include a DHT22. temperature and humidity sensor, you just need to include 8 lines of YAML in your configuration file:

Then just click UPLOAD and the sensor will magically appear in Home Assistant:

Where is the yaml file? where is the upload? wow creat tutorial xD plz help

On the ESPHome website you can find code examples for everything you can connect.
This also applies to DHT22, did that code not work? (Copy and Paste)
Have you configured right pin ie GPIOXX
Is your ESP up and running in ESPHome?

https://esphome.io/components/sensor/dht

It is hard to tell what exactly you have done.

Arduino code will not automatically giving you a connection to HA.

Esphome is an alternative to the Arduino code editor and compiler.

I don’t usually recommend youtube videos, but there are some good intros to esphome on there.

where should i copy paste the code? thats what im wondering about…

You say that you have installed the ESPHome extension and that you have also added your ESP32-C3 device.
If you have done this, you will also find its configuration file when you open ESPHome. The configuration file has the name that you named your device.
When editing that file, you should paste your code under the heading captive_portal:
Under the heading, you can start by adding the code

web_server:
port: 80

Then you can look at the measurement values via the device’s web server.
If you are not sure how to do this, there are many videos on YouTube on how to do it.
Here are some examples…

https://www.youtube.com/results?search_query=esphome+och+dht22

This is an sample of an esp32 - DHT22 config…
#####################################
esphome:
name: “esp32-my-dht22”
friendly_name: ESP32 My DHT22

esp32:
board: esp32dev
framework:
type: arduino

logger:

api:
encryption:
key: “blablabla6/RtldMxWQr28kolFsblablabla=”

ota:
password: “blablabla4150blabla342eblablabla”

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: on
manual_ip:
static_ip: 192.168.1.50
gateway: 192.168.1.1
subnet: 255.255.255.0
dns1: 192.168.1.1

ap:
ssid: “Esp32-My DHT22”
password: “blablabla”

captive_portal:

web_server:
port: 80

sensor:

  • platform: dht
    pin: GPIO21
    temperature:
    name: “Living Room Temperature”
    humidity:
    name: “Living Room Humidity”
    update_interval: 60s

this is what i have: esphome:
name: lol
friendly_name: lol

esp32:
board: esp32-c3-devkitm-1
framework:
type: arduino

Enable logging

logger:

Enable Home Assistant API

api:
encryption:
key: “HQ+Tc5drbgKerhPXlfHvGjC3NGTVEQFxEgUmbMcknnM=”

ota:
password: “bed46d929eef9ab93ccf5710a9396b1b”

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password

Enable fallback hotspot (captive portal) in case wifi connection fails

ap:
ssid: “Lol Fallback Hotspot”
password: “ZfmTK7MeZras”

captive_portal:
web_server:
port: 80

sensor:

platform: dht
pin: GPIO01
temperature:
name: “Living Room Temperature”
humidity:
name: “Living Room Humidity”
update_interval: 60s

i get error, line 39 and 41…

Failed config

captive_portal: [source /config/esphome/lol.yaml:31]

[web_server] is an invalid option for [captive_portal]. Did you mean [web_server_base_id]?
web_server:
port: [source /config/esphome/lol.yaml:32]

Component not found: port.

swedish btw? och…

It is important to indicate the correct name of the port, not GPIO01 but GPIO1.

Then I don’t think port 1 is suitable for this purpose.
Use port GPIO4 instead.

And, do you have any Pull-Up resistor?

pull up resistor on the dht22? i have the am2302 (dht22 on board) so i don’t need it i think , ill try with the gpio4 (i have the xiao esp32_c3…

i get error no matter what i do!!!

web_server: [source /config/esphome/lol.yaml:33]

[sensor] is an invalid option for [web_server]. Please check the indentation.
sensor:
platform: [source /config/esphome/lol.yaml:35]

Component not found: platform.
dht
pin: [source /config/esphome/lol.yaml:36]

Component not found: pin.
GPIO4
update_interval: [source /config/esphome/lol.yaml:37]

Component not found: update_interval.
60s

But, did you change GPIO?

sensor:

platform: dht
pin: GPIO01
pin: GPIO4

And if GPIO4 doesn’t work, try writing D3 which is another name for port GPIO4.
pin: D3

You have got to use code formatting! The spacing of different things in that code matter. When you dont format the code and just copy/paste then it all just gets shoved over to the left margin. No one looking at that knows if you just used some bad spacing or its something totally different. Its 3 (```) without the number 3 or the (). You put 3 above the code block and 3 under it at the end.

You have an error for just abour everything and its probably your spacing. Quit freaking out and post your whole config, top to bottom AND use the code formatting!

Your not using code formatting either… how do you plan to help someone with left aligned text for your “sample DHT22 config” ? They cant see how the syntax is supposed to be formatted or worse, they left align all their config just like the sample you gave them to use.
You ever seen a dog chase its tail??? Thats kinda whats going on here.

You’re right that we should copy the code in here correctly, but I think ticsyboy has this covered.
The problem is probably that he hasn’t entered the correct port that the sensor is connected to.

Thats the conclusion you came to after seeing the laundry list of errors? They just used the wrong gpio? Even though the error shows they used “GPIO4”
Maybe they should just keep going down the line and trying another perfectly fine gpio next?

hello :slight_smile:

I got it to work a little better, it was the wrong board… I have the xiao esp32c3 not the devkit one… so i changed it and here is my code:

esphome:
name: garage-sensor
friendly_name: Garage Sensor

esp32:
board: seeed_xiao_esp32c3
variant: esp32c3
framework:
type: arduino

Enable logging

logger:

Enable Home Assistant API

api:
encryption:
key: “HQ+Tc5drbgKerhPXlfHvGjC3NGTVEQFxEgUmbMcknnM=”

ota:
password: “bed46d929eef9ab93ccf5710a9396b1b”

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password

Enable fallback hotspot (captive portal) in case wifi connection fails

ap:
ssid: “Lol Fallback Hotspot”
password: “ZfmTK7MeZras”

captive_portal:
sensor:

  • platform: dht
    pin: 2
    temperature:
    name: “Living Room Temperature”
    humidity:
    name: “Living Room Humidity”
    update_interval: 60s
    web_server:

but i don’t get the dht sensor on home assistant…

Post your code correctly. It’s not hard. The forum had rules, follow them or go away.

@ticsyboy
You must copy your code correctly so that we can see if it is correct.
In the Reply dialogue, first click on this symbol </> , and then paste your code.

Copy the code from the heading captive_portal: and down, that’s enough.

And I mention once again that you must write the port you are using in a correct way.
If you have the device that my picture shows, write GPIO4 or D2, (not just 2).

EDIT…
Add the code below just under the captive_portal: heading and upload the configuration again.

web_server:
  port: 80

Once the device has rebooted and online, click on VISIT and you should get your readings similar as my picture shows.


esphome:
  name: hemmis
  friendly_name: hemmis

esp32:
  board: esp32-c3-devkitm-1
  variant: esp32c3
  framework:
    type: esp-idf

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "6Q6KlUXNo/sFmWFl95FQ9w+xrD0wGvPkI9nhIRYOKbo="

ota:
  password: "3e0cf106f66397e5c25b617030953960"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Hemmis Fallback Hotspot"
    password: "BDjQBIjT7kdG"

captive_portal:
web_server:
sensor:
  - platform: dht
    model: DHT22_TYPE2
    pin: 2
    temperature:
      name: "Temperature"
    humidity:
      name: "Humidity"
    update_interval: 60s