mirror of
https://github.com/nuttytree/ESPHome-Devices.git
synced 2024-08-30 18:12:19 +00:00
Add standard common files and master_bed device
This commit is contained in:
parent
f5b8b0dd8b
commit
4b9e559291
23
.standard.yaml
Normal file
23
.standard.yaml
Normal file
@ -0,0 +1,23 @@
|
||||
substitutions:
|
||||
device_id:
|
||||
device_name:
|
||||
platform:
|
||||
board:
|
||||
|
||||
esphome:
|
||||
<<: !include common/esphome.yaml
|
||||
|
||||
<<: !include common/common.yaml
|
||||
<<: !include common/logger.yaml
|
||||
|
||||
binary_sensor:
|
||||
<<: !include common/binary_sensors.yaml
|
||||
|
||||
sensor:
|
||||
<<: !include common/sensors.yaml
|
||||
|
||||
switch:
|
||||
<<: !include common/switches.yaml
|
||||
|
||||
text_sensor:
|
||||
<<: !include common/text_sensors.yaml
|
36
bed_sensor.h
Normal file
36
bed_sensor.h
Normal file
@ -0,0 +1,36 @@
|
||||
#include "esphome.h"
|
||||
|
||||
class BedSensor : public PollingComponent {
|
||||
private:
|
||||
const int melissaGpio = D0;
|
||||
const int chrisGpio = D1;
|
||||
const int sensorGpio = A0;
|
||||
|
||||
public:
|
||||
BinarySensor *melissaInBed = new BinarySensor();
|
||||
BinarySensor *chrisInBed = new BinarySensor();
|
||||
BinarySensor *someoneInBed = new BinarySensor();
|
||||
|
||||
BedSensor() : PollingComponent(5000) { }
|
||||
|
||||
void setup() override {
|
||||
pinMode(melissaGpio, OUTPUT);
|
||||
pinMode(chrisGpio, OUTPUT);
|
||||
}
|
||||
|
||||
void update() override {
|
||||
digitalWrite(melissaGpio, HIGH);
|
||||
digitalWrite(chrisGpio, LOW);
|
||||
int melissaValue = analogRead(sensorGpio);
|
||||
ESP_LOGD("bed_sensor_melissa", "The value of sensor is: %i", melissaValue);
|
||||
melissaInBed->publish_state(melissaValue < 300);
|
||||
|
||||
digitalWrite(melissaGpio, LOW);
|
||||
digitalWrite(chrisGpio, HIGH);
|
||||
int chrisValue = analogRead(sensorGpio);
|
||||
ESP_LOGD("bed_sensor_chris", "The value of sensor is: %i", chrisValue);
|
||||
chrisInBed->publish_state(chrisValue < 300);
|
||||
|
||||
someoneInBed->publish_state(!melissaInBed->state && !chrisInBed->state && melissaValue < 800 && chrisValue < 800);
|
||||
}
|
||||
};
|
2
common/api.yaml
Normal file
2
common/api.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
api:
|
||||
password: !secret ${device_id}_api_pwd:
|
2
common/binary_sensor/status.yaml
Normal file
2
common/binary_sensor/status.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
platform: status
|
||||
name: ${device_name} Status
|
1
common/binary_sensors.yaml
Normal file
1
common/binary_sensors.yaml
Normal file
@ -0,0 +1 @@
|
||||
- !include common/binary_sensor/status.yaml
|
3
common/common.yaml
Normal file
3
common/common.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
<<: !include wifi.yaml
|
||||
<<: !include api.yaml
|
||||
<<: !include ota.yaml
|
3
common/esphome.yaml
Normal file
3
common/esphome.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
name: ${device_id}
|
||||
platform: ${platform}
|
||||
board: ${board}
|
2
common/logger.yaml
Normal file
2
common/logger.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
logger:
|
||||
level: DEBUG
|
3
common/logger_tuya.yaml
Normal file
3
common/logger_tuya.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
logger:
|
||||
level: NONE
|
||||
baud_rate: 0
|
2
common/ota.yaml
Normal file
2
common/ota.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
ota:
|
||||
password: !secret ${device_id}_ota_pwd:
|
2
common/secrets.yaml
Normal file
2
common/secrets.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
---
|
||||
<<: !include ../secrets.yaml
|
2
common/sensor/uptime.yaml
Normal file
2
common/sensor/uptime.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
- platform: uptime
|
||||
name: ${device_name} Uptime
|
2
common/sensor/wifi.yaml
Normal file
2
common/sensor/wifi.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
- platform: wifi_signal
|
||||
name: ${device_name} WiFi Signal
|
2
common/sensors.yaml
Normal file
2
common/sensors.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
- !include common/sensor/uptime.yaml
|
||||
- !include common/sensor/wifi.yaml
|
3
common/switch/restart.yaml
Normal file
3
common/switch/restart.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
- platform: restart
|
||||
id: restart
|
||||
name: Restart ${device_name}
|
1
common/switches.yaml
Normal file
1
common/switches.yaml
Normal file
@ -0,0 +1 @@
|
||||
- !include common/switch/restart.yaml
|
2
common/text_sensor/version.yaml
Normal file
2
common/text_sensor/version.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
- platform: version
|
||||
name: ${device_name} Version
|
3
common/text_sensor/wifi.yaml
Normal file
3
common/text_sensor/wifi.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
platform: wifi_info
|
||||
ip_address:
|
||||
name: ${device_name} IP Address
|
2
common/text_sensors.yaml
Normal file
2
common/text_sensors.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
- !include common/text_sensor/version.yaml
|
||||
- !include common/text_sensor/wifi.yaml
|
12
common/wifi.yaml
Normal file
12
common/wifi.yaml
Normal file
@ -0,0 +1,12 @@
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
manual_ip:
|
||||
static_ip: !secret ${device_id}_ip
|
||||
subnet: !secret ip_subnet
|
||||
gateway: !secret ip_gateway
|
||||
ap:
|
||||
ssid: ${device_id}
|
||||
password: !secret ${device_id}_cp_pwd
|
||||
|
||||
captive_portal:
|
47
master_bed.yaml
Normal file
47
master_bed.yaml
Normal file
@ -0,0 +1,47 @@
|
||||
substitutions:
|
||||
device_id: master_bed
|
||||
device_name: Master Bed
|
||||
platform: ESP8266
|
||||
board: nodemcuv2
|
||||
|
||||
esphome:
|
||||
<<: !include common/esphome.yaml
|
||||
includes:
|
||||
- bed_sensor.h
|
||||
|
||||
<<: !include common/common.yaml
|
||||
<<: !include common/logger.yaml
|
||||
|
||||
binary_sensor:
|
||||
<<: !include common/binary_sensors.yaml
|
||||
- platform: custom
|
||||
lambda: |-
|
||||
auto bedSensor = new BedSensor();
|
||||
App.register_component(bedSensor);
|
||||
return {bedSensor->melissaInBed, bedSensor->chrisInBed, bedSensor->someoneInBed};
|
||||
binary_sensors:
|
||||
- name: "Melissa is in Bed"
|
||||
id: melissa_in_bed
|
||||
device_class: occupancy
|
||||
- name: "Chris is in Bed"
|
||||
id: chris_in_bed
|
||||
device_class: occupancy
|
||||
- name: "Someone is in Bed"
|
||||
id: someone_in_bed
|
||||
device_class: occupancy
|
||||
|
||||
sensor:
|
||||
<<: !include common/sensors.yaml
|
||||
- platform: template
|
||||
name: "Master Bed Count"
|
||||
id: master_bed_count
|
||||
accuracy_decimals: 0
|
||||
icon: "mdi:hotel"
|
||||
lambda: |-
|
||||
return id(melissa_in_bed).state + id(chris_in_bed).state + id(someone_in_bed).state;
|
||||
|
||||
switch:
|
||||
<<: !include common/switches.yaml
|
||||
|
||||
text_sensor:
|
||||
<<: !include common/text_sensors.yaml
|
Loading…
Reference in New Issue
Block a user