-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
311 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* This example shows how to use continuous mode to take | ||
range measurements with the VL53L0X. It is based on | ||
vl53l0x_ContinuousRanging_Example.c from the VL53L0X API. | ||
The range readings are in units of mm. */ | ||
|
||
#include <Wire.h> | ||
#include <VL53L0X.h> | ||
|
||
// Include esphome | ||
#include "esphome.h" | ||
|
||
// Uncomment this line to use long range mode. This | ||
// increases the sensitivity of the sensor and extends its | ||
// potential range, but increases the likelihood of getting | ||
// an inaccurate reading because of reflections from objects | ||
// other than the intended target. It works best in dark | ||
// conditions. | ||
|
||
#define LONG_RANGE | ||
|
||
class VL53L0XSensor : public PollingComponent, public Sensor { | ||
public: | ||
VL53L0X sensor; | ||
|
||
VL53L0XSensor(int update_interval) : PollingComponent(update_interval){} | ||
|
||
void setup() override { | ||
Wire.begin(); | ||
|
||
sensor.init(); | ||
sensor.setTimeout(1000); | ||
|
||
#if defined LONG_RANGE | ||
// lower the return signal rate limit (default is 0.25 MCPS) | ||
sensor.setSignalRateLimit(0.1); | ||
// increase laser pulse periods (defaults are 14 and 10 PCLKs) | ||
sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18); | ||
sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14); | ||
#endif | ||
|
||
// Start continuous back-to-back mode (take readings as | ||
// fast as possible). To use continuous timed mode | ||
// instead, provide a desired inter-measurement period in | ||
// ms (e.g. sensor.startContinuous(100)). | ||
//sensor.startContinuous(); | ||
} | ||
|
||
void update() override { | ||
int reading1 = sensor.readRangeSingleMillimeters(); | ||
// int reading2 = sensor.readRangeContinuousMillimeters(); | ||
// int reading3 = sensor.readRangeContinuousMillimeters(); | ||
// int averageReading = ((reading1+reading2+reading3)/3); | ||
publish_state(reading1); | ||
ESP_LOGD("vl53l0x", "Salt level is: %f mm", this->state); | ||
if (sensor.timeoutOccurred()) { ESP_LOGD(" TIMEOUT"); } | ||
} | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
esphome: | ||
name: watersoftener | ||
platform: ESP8266 | ||
board: esp01_1m | ||
libraries: | ||
- "VL53L0X" | ||
includes: | ||
- "vl53l0x_sensor.h" | ||
|
||
wifi: | ||
ssid: "barley" | ||
password: "1107claussen" | ||
|
||
|
||
# Enable logging | ||
logger: | ||
level: DEBUG | ||
esp8266_store_log_strings_in_flash: False | ||
|
||
# Enable Home Assistant API | ||
api: | ||
|
||
ota: | ||
|
||
sensor: | ||
- platform: custom | ||
lambda: |- | ||
auto my_sensor = new VL53L0XSensor(30000); | ||
App.register_component(my_sensor); | ||
return {my_sensor}; | ||
sensors: | ||
name: "My Water Softener VL53L0X Sensor" | ||
unit_of_measurement: mm | ||
# filters: | ||
# - exponential_moving_average: | ||
# alpha: 0.1 | ||
# send_every: 15 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
################################################################ | ||
## Packages / TEMPLATE | ||
################################################################ | ||
|
||
################################################ | ||
## Customize | ||
################################################ | ||
|
||
homeassistant: | ||
customize: | ||
################################################ | ||
## Node Anchors | ||
################################################ | ||
|
||
package.node_anchors: | ||
customize: &customize | ||
package: 'water_softener' | ||
|
||
expose: &expose | ||
<<: *customize | ||
haaska_hidden: false | ||
homebridge_hidden: false | ||
|
||
################################################ | ||
## Alarm Panels | ||
################################################ | ||
|
||
################################################ | ||
## Automations | ||
################################################ | ||
|
||
################################################ | ||
## Binary Sensors | ||
################################################ | ||
|
||
################################################ | ||
## Cameras | ||
################################################ | ||
|
||
################################################ | ||
## Device Trackers | ||
################################################ | ||
|
||
################################################ | ||
## Fans | ||
############ | ||
|
||
################################################ | ||
## Frontend | ||
################################################ | ||
|
||
################################################ | ||
## Groups | ||
################################################ | ||
|
||
################################################ | ||
## Input Boolean | ||
################################################ | ||
|
||
################################################ | ||
## Input Numbers | ||
################################################ | ||
|
||
################################################ | ||
## Input Select | ||
################################################ | ||
|
||
################################################ | ||
## iOS | ||
################################################ | ||
|
||
################################################ | ||
## Light | ||
################################################ | ||
|
||
################################################ | ||
## Media Player | ||
################################################ | ||
|
||
################################################ | ||
## Plant | ||
################################################ | ||
|
||
################################################ | ||
## Proximity | ||
################################################ | ||
|
||
################################################ | ||
## Scripts | ||
################################################ | ||
|
||
################################################ | ||
## Sensors | ||
################################################ | ||
|
||
################################################ | ||
## Thermostats | ||
################################################ | ||
|
||
################################################ | ||
## Zone | ||
################################################ | ||
|
||
######################## | ||
# Alarm Panel | ||
######################## | ||
alarm_control_panel: | ||
|
||
######################## | ||
## Automation | ||
######################## | ||
automation: | ||
|
||
######################## | ||
# Binary Sensors | ||
######################## | ||
binary_sensor: | ||
|
||
######################## | ||
# Cameras | ||
######################## | ||
camera: | ||
|
||
######################## | ||
# Device Trackers | ||
######################## | ||
device_tracker: | ||
|
||
######################## | ||
# Fans | ||
######################## | ||
fan: | ||
|
||
######################## | ||
# Frontend | ||
######################## | ||
frontend: | ||
|
||
######################## | ||
# Groups | ||
######################## | ||
group: | ||
|
||
######################## | ||
# Input Booleans | ||
######################## | ||
input_boolean: | ||
|
||
######################## | ||
# Input Numbers | ||
######################## | ||
input_number: | ||
|
||
######################## | ||
# Input Select | ||
######################## | ||
input_select: | ||
|
||
######################## | ||
# iOS | ||
######################## | ||
ios: | ||
|
||
######################## | ||
# Light | ||
######################## | ||
light: | ||
|
||
######################## | ||
# Media Player | ||
######################## | ||
media_player: | ||
|
||
|
||
######################## | ||
# Plant | ||
######################## | ||
plant: | ||
|
||
######################## | ||
# Proximity | ||
######################## | ||
proximity: | ||
|
||
######################## | ||
# Scenes | ||
######################## | ||
scene: | ||
|
||
######################## | ||
# Scripts | ||
######################## | ||
script: | ||
|
||
######################## | ||
# Sensor | ||
######################## | ||
sensor: | ||
- platform: filter | ||
entity_id: sensor.my_water_softener_vl53l0x_sensor | ||
name: "Water Softener Salt Level" | ||
filters: | ||
- filter: time_simple_moving_average | ||
window_size: "6:00" | ||
precision: 0 | ||
|
||
######################## | ||
# Switch | ||
######################## | ||
switch: | ||
|
||
######################## | ||
# Zone | ||
######################## | ||
zone: |