Last active
November 26, 2023 13:05
-
-
Save tjunussov/5b53057826fd5d4c90b121ba6d225cbd to your computer and use it in GitHub Desktop.
ESP-Home caperplus_q2_uart_sensor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
substitutions: | |
device_name: esphome_caperplus | |
pretty_name: "Water Quality" | |
# ip_address: 192.168.99.56 | |
esphome: | |
name: $device_name | |
platform: ESP8266 | |
board: d1_mini | |
# board: esp01_1m | |
build_path: "./build/${device_name}" | |
includes: | |
- ./caperplus/caperplus_q2_uart_sensor.h | |
# Enable logging | |
logger: | |
baud_rate: 0 #disable logging over uart | |
# Enable Home Assistant API | |
api: | |
encryption: | |
key: "WI2Opg0gcCLIfVprOdFcZMvNlNsKQ3rdYQ62QgKlEjA=" | |
ota: | |
password: "deeedd73341a5550752c69bc7224810c" | |
wifi: | |
ssid: !secret wifi_ssid | |
password: !secret wifi_password | |
# Enable fallback hotspot (captive portal) in case wifi connection fails | |
ap: | |
ssid: "Caperplus Hotspot" | |
password: "12345678" | |
captive_portal: | |
mqtt: | |
broker: mqtt.elpass.kz | |
port: 18883 | |
username: nurlan | |
password: !secret mqtt_password | |
on_connect: | |
- light.turn_on: "l1" | |
on_disconnect: | |
- light.turn_off: "l1" | |
uart: | |
id: uart_bus | |
rx_pin: GPIO3 | |
parity: NONE | |
data_bits: 8 | |
stop_bits: 1 | |
baud_rate: 9600 | |
light: | |
- platform: status_led | |
name: "Status1" | |
id: "l1" | |
pin: | |
number: GPIO2 | |
inverted: true | |
sensor: | |
- platform: custom | |
lambda: |- | |
auto caper = new CaperPlusQ2UartSensor(id(uart_bus)); | |
App.register_component(caper); | |
return {caper->temperature_sensor, caper->ph_sensor, caper->tds_sensor}; | |
sensors: | |
- name: "Water Temperature" | |
unit_of_measurement: "°C" | |
accuracy_decimals: 1 | |
state_class: measurement | |
device_class: temperature | |
- name: "Water pH" | |
unit_of_measurement: "pH" | |
icon: mdi:ph | |
accuracy_decimals: 2 | |
state_class: measurement | |
- name: "Water TDS" | |
unit_of_measurement: "ppm" | |
accuracy_decimals: 0 | |
state_class: measurement | |
# sensor: | |
# - platform: template | |
# name: "CaperPlus Q2 Temperature" | |
# id: temperature_sensor | |
# unit_of_measurement: "°C" | |
# accuracy_decimals: 1 | |
# - platform: template | |
# name: "CaperPlus Q2 pH" | |
# id: ph_sensor | |
# unit_of_measurement: "pH" | |
# accuracy_decimals: 2 | |
# - platform: template | |
# name: "CaperPlus Q2 TDS" | |
# id: tds_sensor | |
# unit_of_measurement: "ppm" | |
# accuracy_decimals: 0 | |
# interval: | |
# - interval: 500ms | |
# then: | |
# - lambda: |- | |
# if (id(uart_bus).available() >= 62) { | |
# uint8_t data[62]; | |
# // Read each byte individually | |
# for (int i = 0; i < 62; ++i) { | |
# if (!id(uart_bus).read_byte(data + i)) { | |
# // If unable to read a byte, break out of the loop | |
# break; | |
# } | |
# } | |
# // Check for header | |
# if (data[0] != 0xFF || data[1] != 0xFF || data[2] != 0x00 || data[3] != 0x3A) { | |
# return; | |
# } | |
# // Parse pH | |
# uint16_t value = (data[49] << 8) | data[50]; | |
# float pH = value / 100.0; | |
# id(ph_sensor).publish_state(pH); | |
# // Parse TDS | |
# uint16_t tds = (data[53] << 8) | data[54]; | |
# id(tds_sensor).publish_state(tds); | |
# // Parse Temperature | |
# value = (data[55] << 8) | data[56]; | |
# float temperature = value / 100.0; | |
# id(temperature_sensor).publish_state(temperature); | |
# } | |
# <<: !include ../../common/standard-static.yaml | |
# <<: !include ../../common/sensor/standard.yaml | |
# <<: !include ../../common/text_sensor/standard.yaml | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment