From 90e7f63ec1b69a64cf8329b3d7ca051711c2ead8 Mon Sep 17 00:00:00 2001 From: KemoNine Date: Sun, 30 Jun 2019 16:00:05 -0400 Subject: [PATCH] Include i2c dip switch for plant controls in main dashboard --- .../esphome/plant_dashboard/local_plants.h | 72 ------ .../plant_dashboard/plant_dashboard.yaml | 208 +++++++++++++++--- hardware/esphome/plant_dashboard/plants.h | 147 +++++++++++++ 3 files changed, 327 insertions(+), 100 deletions(-) delete mode 100644 hardware/esphome/plant_dashboard/local_plants.h create mode 100644 hardware/esphome/plant_dashboard/plants.h diff --git a/hardware/esphome/plant_dashboard/local_plants.h b/hardware/esphome/plant_dashboard/local_plants.h deleted file mode 100644 index 7b0c374..0000000 --- a/hardware/esphome/plant_dashboard/local_plants.h +++ /dev/null @@ -1,72 +0,0 @@ -#include "esphome.h" -#include "tca9548a.h" -#include -#include - -class LocalPlantsSensor : public PollingComponent, public sensor::Sensor { - - private: - Adafruit_seesaw plant_1_ss; - - public: - sensor::Sensor *plant_1_sensor = new sensor::Sensor(); - sensor::Sensor *plant_2_sensor = new sensor::Sensor(); - sensor::Sensor *plant_3_sensor = new sensor::Sensor(); - sensor::Sensor *plant_4_sensor = new sensor::Sensor(); - sensor::Sensor *plant_5_sensor = new sensor::Sensor(); - sensor::Sensor *plant_6_sensor = new sensor::Sensor(); - sensor::Sensor *plant_7_sensor = new sensor::Sensor(); - sensor::Sensor *plant_8_sensor = new sensor::Sensor(); - - // 4294967295UL == never per sources - LocalPlantsSensor() : PollingComponent(60*60*1000) { } - - void setup() override { - // Plant 1 : Adafruit STEMMA Soil Sensor - enableMuxPort(1); - plant_1_ss.begin(0x36); - disableMuxPort(1); - } - - void update() override { - enableMuxPort(0); - double plant_1_value = -1; - disableMuxPort(0); - plant_1_sensor->publish_state(plant_1_value); - - enableMuxPort(1); - double plant_2_value = plant_1_ss.touchRead(0); - disableMuxPort(1); - plant_2_sensor->publish_state(plant_2_value); - - enableMuxPort(2); - double plant_3_value = -1; - disableMuxPort(2); - plant_3_sensor->publish_state(plant_3_value); - - enableMuxPort(3); - double plant_4_value = -1; - disableMuxPort(3); - plant_4_sensor->publish_state(plant_4_value); - - enableMuxPort(4); - double plant_5_value = -1; - disableMuxPort(4); - plant_5_sensor->publish_state(plant_5_value); - - enableMuxPort(5); - double plant_6_value = -1; - disableMuxPort(5); - plant_6_sensor->publish_state(plant_6_value); - - enableMuxPort(6); - double plant_7_value = -1; - disableMuxPort(6); - plant_7_sensor->publish_state(plant_7_value); - - enableMuxPort(7); - double plant_8_value = -1; - disableMuxPort(7); - plant_8_sensor->publish_state(plant_8_value); - } -}; diff --git a/hardware/esphome/plant_dashboard/plant_dashboard.yaml b/hardware/esphome/plant_dashboard/plant_dashboard.yaml index de23688..a698db0 100644 --- a/hardware/esphome/plant_dashboard/plant_dashboard.yaml +++ b/hardware/esphome/plant_dashboard/plant_dashboard.yaml @@ -19,7 +19,7 @@ esphome: - sht1x.h - max1704xsensor.h - veml6075.h - - local_plants.h + - plants.h libraries: - SPI - Wire @@ -70,9 +70,9 @@ esphome: delay(500); ESP_LOGD("on_boot: -10:", "END delay(500)"); ////////////////////////////////////////////////// - ESP_LOGD("on_boot: -10:", "LocalPlants"); - id(ptr_component_local_plants)->update(); - ESP_LOGD("on_boot: -10:", "END local_plants"); + ESP_LOGD("on_boot: -10:", "Plants"); + id(ptr_component_plants)->update(); + ESP_LOGD("on_boot: -10:", "END plants"); ////////////////////////////////////////////////// ESP_LOGD("on_boot: -10:", "delay(500)"); delay(500); @@ -85,6 +85,14 @@ esphome: ESP_LOGD("on_boot: -10:", "Value uva: %.1f", id(uva).state); ESP_LOGD("on_boot: -10:", "Value uvb: %.1f", id(uvb).state); ESP_LOGD("on_boot: -10:", "Value uv_index: %.1f", id(uv_index).state); + ESP_LOGD("on_boot: -10:", "Value Plant_1_Enabled: %f", id(Plant_1_Enabled).state); + ESP_LOGD("on_boot: -10:", "Value Plant_2_Enabled: %f", id(Plant_2_Enabled).state); + ESP_LOGD("on_boot: -10:", "Value Plant_3_Enabled: %f", id(Plant_3_Enabled).state); + ESP_LOGD("on_boot: -10:", "Value Plant_4_Enabled: %f", id(Plant_4_Enabled).state); + ESP_LOGD("on_boot: -10:", "Value Plant_5_Enabled: %f", id(Plant_5_Enabled).state); + ESP_LOGD("on_boot: -10:", "Value Plant_6_Enabled: %f", id(Plant_6_Enabled).state); + ESP_LOGD("on_boot: -10:", "Value Plant_7_Enabled: %f", id(Plant_7_Enabled).state); + ESP_LOGD("on_boot: -10:", "Value Plant_8_Enabled: %f", id(Plant_8_Enabled).state); ESP_LOGD("on_boot: -10:", "Value Plant_1: %.1f", id(Plant_1).state); ESP_LOGD("on_boot: -10:", "Value Plant_2: %.1f", id(Plant_2).state); ESP_LOGD("on_boot: -10:", "Value Plant_3: %.1f", id(Plant_3).state); @@ -93,6 +101,14 @@ esphome: ESP_LOGD("on_boot: -10:", "Value Plant_6: %.1f", id(Plant_6).state); ESP_LOGD("on_boot: -10:", "Value Plant_7: %.1f", id(Plant_7).state); ESP_LOGD("on_boot: -10:", "Value Plant_8: %.1f", id(Plant_8).state); + ESP_LOGD("on_boot: -10:", "Value Plant_1_Remote_Enabled: %f", id(Plant_1_Remote_Enabled).state); + ESP_LOGD("on_boot: -10:", "Value Plant_2_Remote_Enabled: %f", id(Plant_2_Remote_Enabled).state); + ESP_LOGD("on_boot: -10:", "Value Plant_3_Remote_Enabled: %f", id(Plant_3_Remote_Enabled).state); + ESP_LOGD("on_boot: -10:", "Value Plant_4_Remote_Enabled: %f", id(Plant_4_Remote_Enabled).state); + ESP_LOGD("on_boot: -10:", "Value Plant_5_Remote_Enabled: %f", id(Plant_5_Remote_Enabled).state); + ESP_LOGD("on_boot: -10:", "Value Plant_6_Remote_Enabled: %f", id(Plant_6_Remote_Enabled).state); + ESP_LOGD("on_boot: -10:", "Value Plant_7_Remote_Enabled: %f", id(Plant_7_Remote_Enabled).state); + ESP_LOGD("on_boot: -10:", "Value Plant_8_Remote_Enabled: %f", id(Plant_8_Remote_Enabled).state); ESP_LOGD("on_boot: -10:", "Value Battery_Voltage: %.1f", id(Battery_Voltage).state); ESP_LOGD("on_boot: -10:", "Value Battery_Level: %.1f", id(Battery_Level).state); ESP_LOGD("on_boot: -10:", "Value Battery_Sleeping: %.1f", id(Battery_Sleeping).state); @@ -186,8 +202,8 @@ globals: - id: ptr_component_max1704x type: "MAX1704xSensor*" restore_value: no - - id: ptr_component_local_plants - type: "LocalPlantsSensor*" + - id: ptr_component_plants + type: "PlantsSensor*" restore_value: no - id: early_boot type: bool @@ -269,11 +285,35 @@ sensor: expire_after: 12h - platform: custom lambda: |- - LocalPlantsSensor* local_plants = new LocalPlantsSensor(); - id(ptr_component_local_plants) = local_plants; - App.register_component(local_plants); - return {local_plants->plant_1_sensor, local_plants->plant_2_sensor, local_plants->plant_3_sensor, local_plants->plant_4_sensor, local_plants->plant_5_sensor, local_plants->plant_6_sensor, local_plants->plant_7_sensor, local_plants->plant_8_sensor}; + PlantsSensor* plants = new PlantsSensor(); + id(ptr_component_plants) = plants; + App.register_component(plants); + return {plants->plant_1_enabled, plants->plant_2_enabled, plants->plant_3_enabled, plants->plant_4_enabled, plants->plant_5_enabled, plants->plant_6_enabled, plants->plant_7_enabled, plants->plant_7_enabled, plants->plant_1_sensor, plants->plant_2_sensor, plants->plant_3_sensor, plants->plant_4_sensor, plants->plant_5_sensor, plants->plant_6_sensor, plants->plant_7_sensor, plants->plant_8_sensor, plants->plant_1_remote_enabled, plants->plant_2_remote_enabled, plants->plant_3_remote_enabled, plants->plant_4_remote_enabled, plants->plant_5_remote_enabled, plants->plant_6_remote_enabled, plants->plant_7_remote_enabled, plants->plant_8_remote_enabled }; sensors: + - name: "Plant 1 - Enabled" + id: Plant_1_Enabled + expire_after: 12h + - name: "Plant 2 - Enabled" + id: Plant_2_Enabled + expire_after: 12h + - name: "Plant 3 - Enabled" + id: Plant_3_Enabled + expire_after: 12h + - name: "Plant 4 - Enabled" + id: Plant_4_Enabled + expire_after: 12h + - name: "Plant 5 - Enabled" + id: Plant_5_Enabled + expire_after: 12h + - name: "Plant 6 - Enabled" + id: Plant_6_Enabled + expire_after: 12h + - name: "Plant 7 - Enabled" + id: Plant_7_Enabled + expire_after: 12h + - name: "Plant 8 - Enabled" + id: Plant_8_Enabled + expire_after: 12h - name: "Plant 1" id: Plant_1 accuracy_decimals: 2 @@ -306,6 +346,30 @@ sensor: id: Plant_8 accuracy_decimals: 2 expire_after: 12h + - name: "Plant 1 - Remote - Enabled" + id: Plant_1_Remote_Enabled + expire_after: 12h + - name: "Plant 2 - Remote - Enabled" + id: Plant_2_Remote_Enabled + expire_after: 12h + - name: "Plant 3 - Remote - Enabled" + id: Plant_3_Remote_Enabled + expire_after: 12h + - name: "Plant 4 - Remote - Enabled" + id: Plant_4_Remote_Enabled + expire_after: 12h + - name: "Plant 5 - Remote - Enabled" + id: Plant_5_Remote_Enabled + expire_after: 12h + - name: "Plant 6 - Remote - Enabled" + id: Plant_6_Remote_Enabled + expire_after: 12h + - name: "Plant 7 - Remote - Enabled" + id: Plant_7_Remote_Enabled + expire_after: 12h + - name: "Plant 8 - Remote - Enabled" + id: Plant_8_Remote_Enabled + expire_after: 12h - platform: custom lambda: |- MAX1704xSensor* max1704x = new MAX1704xSensor(); @@ -388,24 +452,112 @@ display: it.image(0, 32, id(last_sync_icon)); it.strftime(32, 39, id(deja_vu_mono), "%Y-%m-%d %H:%M", id(sntp_time).now()); // Plants - it.image(0, 64, id(inverted_cat_nip)); - it.image(37, 64, id(inverted_christmas_cactus)); - it.image(74, 64, id(inverted_cat_grass)); - it.image(111, 64, id(inverted_tarragon)); - it.image(148, 64, id(inverted_tulip)); - it.image(185, 64, id(inverted_poinsettia)); - it.image(222, 64, id(inverted_bamboo)); - it.image(259, 64, id(inverted_vase)); - it.image(0, 96, id(cat_nip)); - it.image(37, 96, id(christmas_cactus)); - it.image(74, 96, id(cat_grass)); - it.image(111, 96, id(tarragon)); - it.image(148, 96, id(tulip)); - it.image(185, 96, id(poinsettia)); - it.image(222, 96, id(bamboo)); - it.image(259, 96, id(vase)); - it.image(222, 32, id(disabled_tulip)); - it.image(259, 32, id(disabled_vase)); + //if (id(Plant_1_Remote_Enabled).state) { + // it.image(0, 64, id(vase)); + //} + //else { + // it.image(0, 64, id(disabled_vase)); + //} + if (id(Plant_2_Remote_Enabled).state) { + it.image(37, 64, id(vase)); + } + else { + it.image(37, 64, id(disabled_vase)); + } + if (id(Plant_3_Remote_Enabled).state) { + it.image(74, 64, id(vase)); + } + else { + it.image(74, 64, id(disabled_vase)); + } + if (id(Plant_4_Remote_Enabled).state) { + it.image(111, 64, id(vase)); + } + else { + it.image(111, 64, id(disabled_vase)); + } + if (id(Plant_5_Remote_Enabled).state) { + it.image(148, 64, id(vase)); + } + else { + it.image(148, 64, id(disabled_vase)); + } + if (id(Plant_6_Remote_Enabled).state) { + it.image(185, 64, id(vase)); + } + else { + it.image(185, 64, id(disabled_vase)); + } + if (id(Plant_7_Remote_Enabled).state) { + it.image(222, 64, id(vase)); + } + else { + it.image(222, 64, id(disabled_vase)); + } + if (id(Plant_8_Remote_Enabled).state) { + it.image(259, 64, id(vase)); + } + else { + it.image(259, 64, id(disabled_vase)); + } + if (id(Plant_1_Enabled).state) { + if (id(Plant_1).state < 1.0) { + it.image(0, 96, id(inverted_bamboo)); + } + else { + it.image(0, 96, id(bamboo)); + } + } + else { + it.image(0, 96, id(disabled_tulip)); + } + if (id(Plant_2_Enabled).state) { + if (id(Plant_2).state < 500.0) { + it.image(37, 96, id(inverted_cat_nip)); + } + else { + it.image(37, 96, id(cat_nip)); + } + } + else { + it.image(37, 96, id(disabled_tulip)); + } + if (id(Plant_3_Enabled).state) { + it.image(74, 96, id(tulip)); + } + else { + it.image(74, 96, id(disabled_tulip)); + } + if (id(Plant_4_Enabled).state) { + it.image(111, 96, id(tulip)); + } + else { + it.image(111, 96, id(disabled_tulip)); + } + if (id(Plant_5_Enabled).state) { + it.image(148, 96, id(tulip)); + } + else { + it.image(148, 96, id(disabled_tulip)); + } + if (id(Plant_6_Enabled).state) { + it.image(185, 96, id(tulip)); + } + else { + it.image(185, 96, id(disabled_tulip)); + } + if (id(Plant_7_Enabled).state) { + it.image(222, 96, id(tulip)); + } + else { + it.image(222, 96, id(disabled_tulip)); + } + if (id(Plant_8_Enabled).state) { + it.image(259, 96, id(tulip)); + } + else { + it.image(259, 96, id(disabled_tulip)); + } } font: diff --git a/hardware/esphome/plant_dashboard/plants.h b/hardware/esphome/plant_dashboard/plants.h new file mode 100644 index 0000000..000dd54 --- /dev/null +++ b/hardware/esphome/plant_dashboard/plants.h @@ -0,0 +1,147 @@ +#include "esphome.h" +#include "tca9548a.h" +#include +#include + +#define DIP_ADDR 0x65 + +class PlantsSensor : public PollingComponent, public sensor::Sensor { + + private: + Adafruit_seesaw plant_2_ss; + + public: + sensor::Sensor *plant_1_enabled = new sensor::Sensor(); + sensor::Sensor *plant_2_enabled = new sensor::Sensor(); + sensor::Sensor *plant_3_enabled = new sensor::Sensor(); + sensor::Sensor *plant_4_enabled = new sensor::Sensor(); + sensor::Sensor *plant_5_enabled = new sensor::Sensor(); + sensor::Sensor *plant_6_enabled = new sensor::Sensor(); + sensor::Sensor *plant_7_enabled = new sensor::Sensor(); + sensor::Sensor *plant_8_enabled = new sensor::Sensor(); + + sensor::Sensor *plant_1_sensor = new sensor::Sensor(); + sensor::Sensor *plant_2_sensor = new sensor::Sensor(); + sensor::Sensor *plant_3_sensor = new sensor::Sensor(); + sensor::Sensor *plant_4_sensor = new sensor::Sensor(); + sensor::Sensor *plant_5_sensor = new sensor::Sensor(); + sensor::Sensor *plant_6_sensor = new sensor::Sensor(); + sensor::Sensor *plant_7_sensor = new sensor::Sensor(); + sensor::Sensor *plant_8_sensor = new sensor::Sensor(); + + sensor::Sensor *plant_1_remote_enabled = new sensor::Sensor(); + sensor::Sensor *plant_2_remote_enabled = new sensor::Sensor(); + sensor::Sensor *plant_3_remote_enabled = new sensor::Sensor(); + sensor::Sensor *plant_4_remote_enabled = new sensor::Sensor(); + sensor::Sensor *plant_5_remote_enabled = new sensor::Sensor(); + sensor::Sensor *plant_6_remote_enabled = new sensor::Sensor(); + sensor::Sensor *plant_7_remote_enabled = new sensor::Sensor(); + sensor::Sensor *plant_8_remote_enabled = new sensor::Sensor(); + + // 4294967295UL == never per sources + PlantsSensor() : PollingComponent(60*60*1000) { } + + void setup() override { + // Plant 2 : Adafruit STEMMA Soil Sensor + enableMuxPort(1); + plant_2_ss.begin(0x36); + disableMuxPort(1); + } + + void update() override { + Wire.requestFrom(DIP_ADDR, 2); + byte dip_values_1 = Wire.read(); + byte dip_values_2 = Wire.read(); + + boolean plant_1 = bitRead(dip_values_1, 7); + boolean plant_2 = bitRead(dip_values_1, 6); + boolean plant_3 = bitRead(dip_values_1, 5); + boolean plant_4 = bitRead(dip_values_1, 4); + boolean plant_5 = bitRead(dip_values_1, 3); + boolean plant_6 = bitRead(dip_values_1, 2); + boolean plant_7 = bitRead(dip_values_1, 1); + boolean plant_8 = bitRead(dip_values_1, 0); + boolean plant_1_remote = bitRead(dip_values_2, 7); + boolean plant_2_remote = bitRead(dip_values_2, 6); + boolean plant_3_remote = bitRead(dip_values_2, 5); + boolean plant_4_remote = bitRead(dip_values_2, 4); + boolean plant_5_remote = bitRead(dip_values_2, 3); + boolean plant_6_remote = bitRead(dip_values_2, 2); + boolean plant_7_remote = bitRead(dip_values_2, 1); + boolean plant_8_remote = bitRead(dip_values_2, 0); + + plant_1_enabled->publish_state(plant_1); + plant_2_enabled->publish_state(plant_2); + plant_3_enabled->publish_state(plant_3); + plant_4_enabled->publish_state(plant_4); + plant_5_enabled->publish_state(plant_5); + plant_6_enabled->publish_state(plant_6); + plant_7_enabled->publish_state(plant_7); + plant_8_enabled->publish_state(plant_8); + plant_1_remote_enabled->publish_state(plant_1_remote); + plant_2_remote_enabled->publish_state(plant_2_remote); + plant_3_remote_enabled->publish_state(plant_3_remote); + plant_4_remote_enabled->publish_state(plant_4_remote); + plant_5_remote_enabled->publish_state(plant_5_remote); + plant_6_remote_enabled->publish_state(plant_6_remote); + plant_7_remote_enabled->publish_state(plant_7_remote); + plant_8_remote_enabled->publish_state(plant_8_remote); + + double plant_1_value = -1; + if (plant_1) { + enableMuxPort(0); + disableMuxPort(0); + } + plant_1_sensor->publish_state(plant_1_value); + + double plant_2_value = -1; + if (plant_2) { + enableMuxPort(1); + plant_2_value = plant_2_ss.touchRead(0); + disableMuxPort(1); + } + plant_2_sensor->publish_state(plant_2_value); + + double plant_3_value = -1; + if (plant_3) { + enableMuxPort(2); + disableMuxPort(2); + } + plant_3_sensor->publish_state(plant_3_value); + + double plant_4_value = -1; + if (plant_4) { + enableMuxPort(3); + disableMuxPort(3); + } + plant_4_sensor->publish_state(plant_4_value); + + double plant_5_value = -1; + if (plant_5) { + enableMuxPort(4); + disableMuxPort(4); + } + plant_5_sensor->publish_state(plant_5_value); + + double plant_6_value = -1; + if (plant_6) { + enableMuxPort(5); + disableMuxPort(5); + } + plant_6_sensor->publish_state(plant_6_value); + + double plant_7_value = -1; + if (plant_7) { + enableMuxPort(6); + disableMuxPort(6); + } + plant_7_sensor->publish_state(plant_7_value); + + double plant_8_value = -1; + if (plant_8) { + enableMuxPort(7); + disableMuxPort(7); + } + plant_8_sensor->publish_state(plant_8_value); + } +};