diff --git a/.standard.yaml b/.standard.yaml new file mode 100644 index 0000000..4296d4b --- /dev/null +++ b/.standard.yaml @@ -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 \ No newline at end of file diff --git a/bed_sensor.h b/bed_sensor.h new file mode 100644 index 0000000..9743706 --- /dev/null +++ b/bed_sensor.h @@ -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); + } +}; \ No newline at end of file diff --git a/common/api.yaml b/common/api.yaml new file mode 100644 index 0000000..889379a --- /dev/null +++ b/common/api.yaml @@ -0,0 +1,2 @@ +api: + password: !secret ${device_id}_api_pwd: diff --git a/common/binary_sensor/status.yaml b/common/binary_sensor/status.yaml new file mode 100644 index 0000000..c339cbc --- /dev/null +++ b/common/binary_sensor/status.yaml @@ -0,0 +1,2 @@ +platform: status +name: ${device_name} Status \ No newline at end of file diff --git a/common/binary_sensors.yaml b/common/binary_sensors.yaml new file mode 100644 index 0000000..6e4f714 --- /dev/null +++ b/common/binary_sensors.yaml @@ -0,0 +1 @@ +- !include common/binary_sensor/status.yaml diff --git a/common/common.yaml b/common/common.yaml new file mode 100644 index 0000000..d892ae6 --- /dev/null +++ b/common/common.yaml @@ -0,0 +1,3 @@ +<<: !include wifi.yaml +<<: !include api.yaml +<<: !include ota.yaml \ No newline at end of file diff --git a/common/esphome.yaml b/common/esphome.yaml new file mode 100644 index 0000000..d720092 --- /dev/null +++ b/common/esphome.yaml @@ -0,0 +1,3 @@ +name: ${device_id} +platform: ${platform} +board: ${board} \ No newline at end of file diff --git a/common/logger.yaml b/common/logger.yaml new file mode 100644 index 0000000..35e6ada --- /dev/null +++ b/common/logger.yaml @@ -0,0 +1,2 @@ +logger: + level: DEBUG \ No newline at end of file diff --git a/common/logger_tuya.yaml b/common/logger_tuya.yaml new file mode 100644 index 0000000..1a657ab --- /dev/null +++ b/common/logger_tuya.yaml @@ -0,0 +1,3 @@ +logger: + level: NONE + baud_rate: 0 \ No newline at end of file diff --git a/common/ota.yaml b/common/ota.yaml new file mode 100644 index 0000000..fa47b26 --- /dev/null +++ b/common/ota.yaml @@ -0,0 +1,2 @@ +ota: + password: !secret ${device_id}_ota_pwd: diff --git a/common/secrets.yaml b/common/secrets.yaml new file mode 100644 index 0000000..ede7dc9 --- /dev/null +++ b/common/secrets.yaml @@ -0,0 +1,2 @@ +--- +<<: !include ../secrets.yaml \ No newline at end of file diff --git a/common/sensor/uptime.yaml b/common/sensor/uptime.yaml new file mode 100644 index 0000000..8804578 --- /dev/null +++ b/common/sensor/uptime.yaml @@ -0,0 +1,2 @@ +- platform: uptime + name: ${device_name} Uptime diff --git a/common/sensor/wifi.yaml b/common/sensor/wifi.yaml new file mode 100644 index 0000000..4592dab --- /dev/null +++ b/common/sensor/wifi.yaml @@ -0,0 +1,2 @@ +- platform: wifi_signal + name: ${device_name} WiFi Signal diff --git a/common/sensors.yaml b/common/sensors.yaml new file mode 100644 index 0000000..ea2e621 --- /dev/null +++ b/common/sensors.yaml @@ -0,0 +1,2 @@ +- !include common/sensor/uptime.yaml +- !include common/sensor/wifi.yaml diff --git a/common/switch/restart.yaml b/common/switch/restart.yaml new file mode 100644 index 0000000..d23e1f9 --- /dev/null +++ b/common/switch/restart.yaml @@ -0,0 +1,3 @@ + - platform: restart + id: restart + name: Restart ${device_name} \ No newline at end of file diff --git a/common/switches.yaml b/common/switches.yaml new file mode 100644 index 0000000..4f5dd6a --- /dev/null +++ b/common/switches.yaml @@ -0,0 +1 @@ +- !include common/switch/restart.yaml diff --git a/common/text_sensor/version.yaml b/common/text_sensor/version.yaml new file mode 100644 index 0000000..60ba225 --- /dev/null +++ b/common/text_sensor/version.yaml @@ -0,0 +1,2 @@ +- platform: version + name: ${device_name} Version \ No newline at end of file diff --git a/common/text_sensor/wifi.yaml b/common/text_sensor/wifi.yaml new file mode 100644 index 0000000..c2bc08f --- /dev/null +++ b/common/text_sensor/wifi.yaml @@ -0,0 +1,3 @@ +platform: wifi_info +ip_address: + name: ${device_name} IP Address \ No newline at end of file diff --git a/common/text_sensors.yaml b/common/text_sensors.yaml new file mode 100644 index 0000000..7e91565 --- /dev/null +++ b/common/text_sensors.yaml @@ -0,0 +1,2 @@ +- !include common/text_sensor/version.yaml +- !include common/text_sensor/wifi.yaml diff --git a/common/wifi.yaml b/common/wifi.yaml new file mode 100644 index 0000000..0f9deea --- /dev/null +++ b/common/wifi.yaml @@ -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: \ No newline at end of file diff --git a/master_bed.yaml b/master_bed.yaml new file mode 100644 index 0000000..cb6302d --- /dev/null +++ b/master_bed.yaml @@ -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 \ No newline at end of file