add ESP32 example
This commit is contained in:
commit
67030e13ea
|
@ -0,0 +1,388 @@
|
||||||
|
* ESP + BME680 + SSD1306 display
|
||||||
|
|
||||||
|
** Initial prompt
|
||||||
|
|
||||||
|
#+begin_quote
|
||||||
|
|
||||||
|
generate an esphome configuration to send sensor data of BME680 to home-assistant
|
||||||
|
|
||||||
|
#+end_quote
|
||||||
|
|
||||||
|
Response:
|
||||||
|
#+begin_src yaml
|
||||||
|
esphome:
|
||||||
|
name: my_sensor
|
||||||
|
platform: ESP32
|
||||||
|
|
||||||
|
# Enable the BME680 sensor
|
||||||
|
sensor:
|
||||||
|
- platform: bme680
|
||||||
|
name: "BME680 Sensor"
|
||||||
|
temperature:
|
||||||
|
name: "Temperature"
|
||||||
|
unit_of_measurement: "°C"
|
||||||
|
humidity:
|
||||||
|
name: "Humidity"
|
||||||
|
unit_of_measurement: "%"
|
||||||
|
pressure:
|
||||||
|
name: "Pressure"
|
||||||
|
unit_of_measurement: "hPa"
|
||||||
|
air_quality:
|
||||||
|
name: "Air Quality"
|
||||||
|
unit_of_measurement: "ppm"
|
||||||
|
|
||||||
|
# Enable MQTT to send the sensor data to Home Assistant
|
||||||
|
mqtt:
|
||||||
|
broker: YOUR_MQTT_BROKER_ADDRESS
|
||||||
|
client_id: my_sensor
|
||||||
|
username: YOUR_MQTT_USERNAME
|
||||||
|
password: YOUR_MQTT_PASSWORD
|
||||||
|
|
||||||
|
# Configure the sensors to be published to MQTT
|
||||||
|
binary_sensor:
|
||||||
|
- platform: mqtt
|
||||||
|
name: "Temperature"
|
||||||
|
state_topic: "my_sensor/sensor/temperature"
|
||||||
|
- platform: mqtt
|
||||||
|
name: "Humidity"
|
||||||
|
state_topic: "my_sensor/sensor/humidity"
|
||||||
|
- platform: mqtt
|
||||||
|
name: "Pressure"
|
||||||
|
state_topic: "my_sensor/sensor/pressure"
|
||||||
|
- platform: mqtt
|
||||||
|
name: "Air Quality"
|
||||||
|
state_topic: "my_sensor/sensor/air_quality"
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_quote
|
||||||
|
This configuration will enable the BME680 sensor and send the temperature,
|
||||||
|
humidity, pressure, and air quality data to Home Assistant via MQTT. You will
|
||||||
|
need to replace YOUR_MQTT_BROKER_ADDRESS, YOUR_MQTT_USERNAME, and
|
||||||
|
YOUR_MQTT_PASSWORD with your own MQTT broker address, username, and password.
|
||||||
|
|
||||||
|
I hope this helps! Let me know if you have any questions.
|
||||||
|
#+end_quote
|
||||||
|
|
||||||
|
** use the specific board
|
||||||
|
|
||||||
|
#+begin_quote
|
||||||
|
it is connected on pin 6 of an ESP8266 nodemcu v4
|
||||||
|
#+end_quote
|
||||||
|
|
||||||
|
#+begin_src yaml
|
||||||
|
# Enable I2C on the ESP8266
|
||||||
|
i2c:
|
||||||
|
sda: D2
|
||||||
|
scl: D1
|
||||||
|
|
||||||
|
# Enable the BME680 sensor
|
||||||
|
sensor:
|
||||||
|
- platform: bme680
|
||||||
|
name: "BME680 Sensor"
|
||||||
|
temperature:
|
||||||
|
name: "Temperature"
|
||||||
|
unit_of_measurement: "°C"
|
||||||
|
humidity:
|
||||||
|
name: "Humidity"
|
||||||
|
unit_of_measurement: "%"
|
||||||
|
pressure:
|
||||||
|
name: "Pressure"
|
||||||
|
unit_of_measurement: "hPa"
|
||||||
|
air_quality:
|
||||||
|
name: "Air Quality"
|
||||||
|
unit_of_measurement: "ppm"
|
||||||
|
# Specify the I2C bus and address of the BME680 sensor
|
||||||
|
i2c_id: i2c
|
||||||
|
address: 0x77
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** Request to use a display
|
||||||
|
#+begin_quote
|
||||||
|
I'd also like to display the current sensor values on a SSD1306 with a refresh
|
||||||
|
rate of 30seconds
|
||||||
|
#+end_quote
|
||||||
|
|
||||||
|
Response:
|
||||||
|
|
||||||
|
#+begin_quote
|
||||||
|
To display the current sensor values on a SSD1306 OLED display with a refresh
|
||||||
|
rate of 30 seconds, you can use the ssd1306 component in ESPHome and set the
|
||||||
|
update interval for the sensor values to 30 seconds.
|
||||||
|
|
||||||
|
Here is an example configuration that will display the temperature, humidity,
|
||||||
|
pressure, and air quality values from the BME680 sensor on a SSD1306 OLED
|
||||||
|
display with a refresh rate of 30 seconds:
|
||||||
|
#+end_quote
|
||||||
|
|
||||||
|
#+begin_src yaml
|
||||||
|
esphome:
|
||||||
|
name: my_sensor
|
||||||
|
platform: ESP8266
|
||||||
|
|
||||||
|
# Enable I2C on the ESP8266
|
||||||
|
i2c:
|
||||||
|
sda: D2
|
||||||
|
scl: D1
|
||||||
|
|
||||||
|
# Enable the BME680 sensor
|
||||||
|
sensor:
|
||||||
|
- platform: bme680
|
||||||
|
name: "BME680 Sensor"
|
||||||
|
temperature:
|
||||||
|
name: "Temperature"
|
||||||
|
unit_of_measurement: "°C"
|
||||||
|
update_interval: 30s
|
||||||
|
humidity:
|
||||||
|
name: "Humidity"
|
||||||
|
unit_of_measurement: "%"
|
||||||
|
update_interval: 30s
|
||||||
|
pressure:
|
||||||
|
name: "Pressure"
|
||||||
|
unit_of_measurement: "hPa"
|
||||||
|
update_interval: 30s
|
||||||
|
air_quality:
|
||||||
|
name: "Air Quality"
|
||||||
|
unit_of_measurement: "ppm"
|
||||||
|
update_interval: 30s
|
||||||
|
# Specify the I2C bus and address of the BME680 sensor
|
||||||
|
i2c_id: i2c
|
||||||
|
address: 0x77
|
||||||
|
|
||||||
|
# Enable the SSD1306 OLED display
|
||||||
|
display:
|
||||||
|
- platform: ssd1306
|
||||||
|
name: OLED Display
|
||||||
|
reset_pin: D1
|
||||||
|
address: 0x3C
|
||||||
|
id: display
|
||||||
|
|
||||||
|
# Display the sensor values on the OLED display
|
||||||
|
text_sensor:
|
||||||
|
- platform: template
|
||||||
|
name: "Temperature Display"
|
||||||
|
lambda: |-
|
||||||
|
return format_string("Temperature: {}°C", id(temperature).state);
|
||||||
|
- platform: template
|
||||||
|
name: "Humidity Display"
|
||||||
|
lambda: |-
|
||||||
|
return format_string("Humidity: {}%", id(humidity).state);
|
||||||
|
- platform: template
|
||||||
|
name: "Pressure Display"
|
||||||
|
lambda: |-
|
||||||
|
return format_string("Pressure: {}hPa", id(pressure).state);
|
||||||
|
- platform: template
|
||||||
|
name: "Air Quality Display"
|
||||||
|
lambda: |-
|
||||||
|
return format_string("Air Quality: {}ppm", id(air_quality).state);
|
||||||
|
|
||||||
|
# Display the sensor values on the OLED display
|
||||||
|
display:
|
||||||
|
- platform: ssd1306
|
||||||
|
display_id: display
|
||||||
|
text:
|
||||||
|
- id: temperature_display
|
||||||
|
x: 0
|
||||||
|
y: 0
|
||||||
|
- id: humidity_display
|
||||||
|
x: 0
|
||||||
|
y: 8
|
||||||
|
- id: pressure_display
|
||||||
|
x: 0
|
||||||
|
y: 16
|
||||||
|
- id: air_quality_display
|
||||||
|
x: 0
|
||||||
|
y: 24
|
||||||
|
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** Request some tweaks
|
||||||
|
#+begin_quote
|
||||||
|
the sensor should be named 'airQualityHallway' and humidity should be displayed
|
||||||
|
next to temperature, not below it. Also show the date and time on the display
|
||||||
|
#+end_quote
|
||||||
|
|
||||||
|
#+begin_src yaml
|
||||||
|
esphome:
|
||||||
|
name: my_sensor
|
||||||
|
platform: ESP8266
|
||||||
|
|
||||||
|
# Enable I2C on the ESP8266
|
||||||
|
i2c:
|
||||||
|
sda: D2
|
||||||
|
scl: D1
|
||||||
|
|
||||||
|
# Enable the BME680 sensor
|
||||||
|
sensor:
|
||||||
|
- platform: bme680
|
||||||
|
name: "airQualityHallway"
|
||||||
|
temperature:
|
||||||
|
name: "Temperature"
|
||||||
|
unit_of_measurement: "°C"
|
||||||
|
update_interval: 30s
|
||||||
|
humidity:
|
||||||
|
name: "Humidity"
|
||||||
|
unit_of_measurement: "%"
|
||||||
|
update_interval: 30s
|
||||||
|
pressure:
|
||||||
|
name: "Pressure"
|
||||||
|
unit_of_measurement: "hPa"
|
||||||
|
update_interval: 30s
|
||||||
|
air_quality:
|
||||||
|
name: "Air Quality"
|
||||||
|
unit_of_measurement: "ppm"
|
||||||
|
update_interval: 30s
|
||||||
|
# Specify the I2C bus and address of the BME680 sensor
|
||||||
|
i2c_id: i2c
|
||||||
|
address: 0x77
|
||||||
|
|
||||||
|
# Enable the SSD1306 OLED display
|
||||||
|
display:
|
||||||
|
- platform: ssd1306
|
||||||
|
name: OLED Display
|
||||||
|
reset_pin: D1
|
||||||
|
address: 0x3C
|
||||||
|
id: display
|
||||||
|
|
||||||
|
# Display the sensor values on the OLED display
|
||||||
|
text_sensor:
|
||||||
|
- platform: template
|
||||||
|
name: "Temperature and Humidity Display"
|
||||||
|
lambda: |-
|
||||||
|
return format_string("Temperature: {}°C Humidity: {}%", id(temperature).state, id(humidity).state);
|
||||||
|
- platform: template
|
||||||
|
name: "Pressure Display"
|
||||||
|
lambda: |-
|
||||||
|
return format_string("Pressure: {}hPa", id(pressure).state);
|
||||||
|
- platform: template
|
||||||
|
name: "Air Quality Display"
|
||||||
|
lambda: |-
|
||||||
|
return format_string("Air Quality: {}ppm", id(air_quality).state);
|
||||||
|
- platform: template
|
||||||
|
name: "Date and Time Display"
|
||||||
|
lambda: |-
|
||||||
|
return now().strftime("%Y-%m-%d %H:%M:%S");
|
||||||
|
|
||||||
|
# Display the sensor values and date/time on the OLED display
|
||||||
|
display:
|
||||||
|
- platform: ssd1306
|
||||||
|
display_id: display
|
||||||
|
text:
|
||||||
|
- id: temperature_and_humidity_display
|
||||||
|
x: 0
|
||||||
|
y: 0
|
||||||
|
- id: pressure_display
|
||||||
|
x: 0
|
||||||
|
y: 8
|
||||||
|
- id: air_quality_display
|
||||||
|
x: 0
|
||||||
|
y: 16
|
||||||
|
- id: date_and_time_display
|
||||||
|
x: 0
|
||||||
|
y: 24
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** Change the display output
|
||||||
|
|
||||||
|
#+begin_quote
|
||||||
|
please align date/time in the bottom right corner. use a slightly larger font
|
||||||
|
for temperature and humidity
|
||||||
|
#+end_quote
|
||||||
|
|
||||||
|
Response:
|
||||||
|
#+begin_quote
|
||||||
|
To align the date and time in the bottom right corner of the OLED display, you
|
||||||
|
can use the x and y coordinates of the display component to specify the position
|
||||||
|
of the text on the display. You can also use the font_size option to specify a
|
||||||
|
larger font size for the temperature and humidity values.
|
||||||
|
|
||||||
|
Here is an updated configuration that includes the changes you requested:
|
||||||
|
#+end_quote
|
||||||
|
|
||||||
|
#+begin_src yaml
|
||||||
|
esphome:
|
||||||
|
name: my_sensor
|
||||||
|
platform: ESP8266
|
||||||
|
|
||||||
|
# Enable I2C on the ESP8266
|
||||||
|
i2c:
|
||||||
|
sda: D2
|
||||||
|
scl: D1
|
||||||
|
|
||||||
|
# Enable the BME680 sensor
|
||||||
|
sensor:
|
||||||
|
- platform: bme680
|
||||||
|
name: "airQualityHallway"
|
||||||
|
temperature:
|
||||||
|
name: "Temperature"
|
||||||
|
unit_of_measurement: "°C"
|
||||||
|
update_interval: 30s
|
||||||
|
humidity:
|
||||||
|
name: "Humidity"
|
||||||
|
unit_of_measurement: "%"
|
||||||
|
update_interval: 30s
|
||||||
|
pressure:
|
||||||
|
name: "Pressure"
|
||||||
|
unit_of_measurement: "hPa"
|
||||||
|
update_interval: 30s
|
||||||
|
air_quality:
|
||||||
|
name: "Air Quality"
|
||||||
|
unit_of_measurement: "ppm"
|
||||||
|
update_interval: 30s
|
||||||
|
# Specify the I2C bus and address of the BME680 sensor
|
||||||
|
i2c_id: i2c
|
||||||
|
address: 0x77
|
||||||
|
|
||||||
|
# Enable the SSD1306 OLED display
|
||||||
|
display:
|
||||||
|
- platform: ssd1306
|
||||||
|
name: OLED Display
|
||||||
|
reset_pin: D1
|
||||||
|
address: 0x3C
|
||||||
|
id: display
|
||||||
|
|
||||||
|
# Display the sensor values on the OLED display
|
||||||
|
text_sensor:
|
||||||
|
- platform: template
|
||||||
|
name: "Temperature and Humidity Display"
|
||||||
|
lambda: |-
|
||||||
|
return format_string("Temperature: {}°C Humidity: {}%", id(temperature).state, id(humidity).state);
|
||||||
|
- platform: template
|
||||||
|
name: "Pressure Display"
|
||||||
|
lambda: |-
|
||||||
|
return format_string("Pressure: {}hPa", id(pressure).state);
|
||||||
|
- platform: template
|
||||||
|
name: "Air Quality Display"
|
||||||
|
lambda: |-
|
||||||
|
return format_string("Air Quality: {}ppm", id(air_quality).state);
|
||||||
|
- platform: template
|
||||||
|
name: "Date and Time Display"
|
||||||
|
lambda: |-
|
||||||
|
return now().strftime("%Y-%m-%d %H:%M:%S");
|
||||||
|
|
||||||
|
# Display the sensor values and date/time on the OLED display
|
||||||
|
display:
|
||||||
|
- platform: ssd1306
|
||||||
|
display_id: display
|
||||||
|
text:
|
||||||
|
- id: temperature_and_humidity_display
|
||||||
|
x: 0
|
||||||
|
y: 0
|
||||||
|
font_size: 16
|
||||||
|
- id: pressure_display
|
||||||
|
x: 0
|
||||||
|
y: 8
|
||||||
|
- id: air_quality_display
|
||||||
|
x: 0
|
||||||
|
y: 16
|
||||||
|
- id: date_and_time_display
|
||||||
|
x: 64
|
||||||
|
y: 56
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_quote
|
||||||
|
This configuration will display the temperature and humidity values in a larger
|
||||||
|
font size and will align the date and time in the bottom right corner of the
|
||||||
|
OLED display. The `text_sensor
|
||||||
|
#+end_quote
|
||||||
|
|
||||||
|
Note: the explaination seems to be snipped here for some reason
|
Loading…
Reference in New Issue