diff --git a/img/screen_growsmart.png b/img/screen_growsmart.png new file mode 100644 index 0000000000000000000000000000000000000000..cdc677fc0875f8b781e45f91acbe879cc207bace Binary files /dev/null and b/img/screen_growsmart.png differ diff --git a/packages/display_cyd2usb.yaml b/packages/display_cyd2usb.yaml index c59784393c3e5c30ee21706c3d4873dc4b7a2277..db2e010db9be91d219944b416080a5014f0662db 100644 --- a/packages/display_cyd2usb.yaml +++ b/packages/display_cyd2usb.yaml @@ -27,14 +27,7 @@ display: dimensions: height: 320 width: 240 - lambda: |- - it.fill(id(Color::BLACK)); - it.line(0, 0, 50, 50); - it.filled_circle(60, 160, 30, id(green)); - it.filled_circle(180, 160, 30, id(red)); - it.print(60, 160, id(mdi_large), TextAlign::CENTER, ""); - it.print(180, 160, id(mdi_large), TextAlign::CENTER, ""); - it.print(216, 0, id(mdi_medium), id(wifi_iconstring).c_str()); + lambda: id(update_display).execute(); # Set up the xpt2046 touch platform touchscreen: @@ -90,29 +83,60 @@ light: red: output_red green: output_green blue: output_blue - gamma_correct: 1.0 restore_mode: ALWAYS_ON effects: - pulse: name: "Default" transition_length: 3s update_interval: 3s - min_brightness: 33% + min_brightness: 50% max_brightness: 100% + - strobe: + name: "Alert" + colors: + - state: true + brightness: 100% + red: 100% + green: 0% + blue: 0% + duration: 250ms + - state: false + duration: 250ms on_turn_on: - light.turn_on: id: led effect: "Default" + brightness: 100% + red: 0% + green: 100% + blue: 0% interval: - - interval: 5s + - interval: 10s then: - - if: - condition: - - lambda: "return !id(recent_touch);" - then: - - light.turn_on: - id: backlight - brightness: 25% - else: - - lambda: "id(recent_touch) = false;" + - lambda: |- + // dim the display to 50% after 10s, and to 25% after 20s + if (id(recent_touch)) + { + id(recent_touch) = false; + id(screen_timeout_short) = true; + } + else if (id(screen_timeout_short)) + { + id(screen_timeout_short) = false; + id(screen_timeout_long) = true; + auto call = id(backlight).turn_on(); + call.set_brightness(0.5); + call.perform(); + } + else if (id(screen_timeout_long)) + { + id(screen_timeout_long) = false; + auto call = id(backlight).turn_on(); + call.set_brightness(0.25); + call.perform(); + } + +button: + - platform: factory_reset + name: Factory Reset diff --git a/packages/mqtt.yaml b/packages/mqtt.yaml index 50e46787c246e9468ac62b357e221db94e89f365..d3665a3fcd1a5ce4de1bab138b82be7a5d86039a 100644 --- a/packages/mqtt.yaml +++ b/packages/mqtt.yaml @@ -5,4 +5,13 @@ mqtt: client_id: $devicename discovery: false topic_prefix: growsmart/$devicename + log_topic: + topic: growsmart/$devicename/log + level: INFO + birth_message: + topic: growsmart/$devicename/status + payload: online + will_message: + topic: growsmart/$devicename/status + payload: offline reboot_timeout: 0s diff --git a/packages/screen.yaml b/packages/screen.yaml index 4afe3bf1a5f6471beca199301bf58742cbdbf4b7..5387051203ddad4a955a079079be05c15b17b345 100644 --- a/packages/screen.yaml +++ b/packages/screen.yaml @@ -1,52 +1,45 @@ +substitutions: + graph_duration: 15min + graph_grid_x: 1min -# Set up some global variables for some values that we want to persist globals: - - id: wifi_iconstring - type: std::string - restore_value: no - initial_value: '""' - id: recent_touch type: bool - restore_value: no - initial_value: "true" + initial_value: 'true' + - id: screen_timeout_short + type: bool + - id: screen_timeout_long + type: bool + - id: temperature + type: float + initial_value: '0.0' + - id: humidity + type: float + initial_value: '0.0' + - id: ec + type: float + initial_value: '0.0' + - id: ph + type: float + initial_value: '0.0' -# ============================================================ -# ESPHome Display related setup -# -# Create a font to use, add and remove glyphs as needed -# The Material Design Icon font is going to be used to display wifi -# state as well as displaying the lightbulb icons font: - - file: 'packages/fonts/materialdesignicons-webfont.ttf' - id: mdi_large - size: 48 - glyphs: [ - "", # lightbulb-on - "", # lightbulb-off - ] - - file: "packages/fonts/materialdesignicons-webfont.ttf" - id: mdi_medium - size: 24 - glyphs: [ - "", # no-wifi - "", # low-wifi - "", # wifi-1 - "", # wifi-2 - "", # wifi-3 - "", # wifi-4 - ] + - file: + type: gfonts + family: Roboto + weight: 700 + id: font_default + size: 16 + glyphs: '!"%()+=,-_.:°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ abcdefghijklmnopqrstuvwxyzåäö' -# Create a Home Assistant blue color -color: - - id: green - hex: 00FF00 - - id: red - hex: FF0000 +image: + - file: "img/screen_growsmart.png" + id: growsmart + type: RGB24 -# Setup two binary sensors for the two areas for touch binary_sensor: - platform: touchscreen - name: Light Green + name: "LED Default" x_min: 0 x_max: 120 y_min: 0 @@ -55,12 +48,10 @@ binary_sensor: then: - light.turn_on: id: led - red: 0.0 - green: 1.0 - blue: 0.0 + effect: Default - platform: touchscreen - name: Light Red + name: "LED Alert" x_min: 120 x_max: 240 y_min: 0 @@ -69,43 +60,129 @@ binary_sensor: then: - light.turn_on: id: led - red: 1.0 - green: 0.0 - blue: 0.0 + effect: Alert - -# Setup a script that can update the UI values independent of the display lambda -# so that we're not trying to pull the WiFi signal strength every single frame script: - - id: update_ui_values + - id: update_display then: - - lambda: |- - if (isnan(id(wifi_signal_pct).state)) - id(wifi_iconstring) = ""; // No-wifi - else if (id(wifi_signal_pct).state < 10) - id(wifi_iconstring) = ""; // low-wifi - else if (id(wifi_signal_pct).state < 30) - id(wifi_iconstring) = ""; // wifi-1 - else if (id(wifi_signal_pct).state < 50) - id(wifi_iconstring) = ""; // wifi-2 - else if (id(wifi_signal_pct).state < 75) - id(wifi_iconstring) = ""; // wifi-3 - else - id(wifi_iconstring) = ""; // wifi-4 + - lambda: |- + if (id(temperature) == 0.0 || id(humidity) == 0.0 || id(ph) == 0.0 || id(ec) == 0.0) + { + esp_display->image(0, 0, id(growsmart)); + return; + } + esp_display->fill(id(Color::BLACK)); + esp_display->printf(0, 0, id(font_default), "Temperature: %.2f °C", id(temperature)); + esp_display->graph(0, 18, id(graph_temperature)); + esp_display->printf(0, 80, id(font_default), "Humidity: %.2f%%", id(humidity)); + esp_display->graph(0, 98, id(graph_humidity)); + esp_display->printf(0, 160, id(font_default), "pH: %.2f", id(ph)); + esp_display->graph(0, 178, id(graph_ph)); + esp_display->printf(0, 240, id(font_default), "EC: %.2f mS", id(ec)); + esp_display->graph(0, 258, id(graph_ec)); -# Update the UI state every 10 seconds -interval: - - interval: 1s - then: - - script.execute: update_ui_values +color: + - id: color_red + red: 100% + green: 0% + blue: 0% + - id: color_green + red: 0% + green: 100% + blue: 0% + - id: color_blue + red: 0% + green: 0% + blue: 100% + +graph: + - id: graph_temperature + duration: ${graph_duration} + x_grid: ${graph_grid_x} + y_grid: 1.0 + width: 240 + height: 60 + min_value: 18 + max_value: 32 + min_range: 2 + max_range: 2 + traces: + - sensor: mqtt_temperature + continuous: true + #line_thickness: 2 + color: color_green + - id: graph_humidity + duration: ${graph_duration} + x_grid: ${graph_grid_x} + y_grid: 1.0 + width: 240 + height: 60 + min_value: 40 + max_value: 90 + min_range: 2 + max_range: 2 + traces: + - sensor: mqtt_humidity + continuous: true + #line_thickness: 2 + color: color_green + - id: graph_ph + duration: ${graph_duration} + x_grid: ${graph_grid_x} + y_grid: 1.0 + width: 240 + height: 60 + min_value: 4 + max_value: 8 + min_range: 2 + max_range: 2 + traces: + - sensor: mqtt_ph + continuous: true + #line_thickness: 2 + color: color_green + - id: graph_ec + duration: ${graph_duration} + x_grid: ${graph_grid_x} + y_grid: 1.0 + width: 240 + height: 60 + min_value: 0 + max_value: 3 + min_range: 2 + max_range: 2 + traces: + - sensor: mqtt_ec + continuous: true + #line_thickness: 2 + color: color_green -# Wifi sensor that drives the UI signal strength icon sensor: - - platform: wifi_signal # Reports the WiFi signal strength in % - name: "WiFi Signal Percent" - filters: - - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0); - unit_of_measurement: "Signal %" - id: wifi_signal_pct - update_interval: 60s - entity_category: "diagnostic" + - platform: mqtt_subscribe + id: mqtt_temperature + name: "Temperature" + topic: growsmart/growbox/sensor/air__temperature/state + on_value: + then: + - lambda: 'id(temperature) = x;' + - platform: mqtt_subscribe + id: mqtt_humidity + name: "Humidity" + topic: growsmart/growbox/sensor/air__humidity/state + on_value: + then: + - lambda: 'id(humidity) = x;' + - platform: mqtt_subscribe + id: mqtt_ec + name: "EC" + topic: growsmart/growbox/sensor/ec/state + on_value: + then: + - lambda: 'id(ec) = x;' + - platform: mqtt_subscribe + id: mqtt_ph + name: "pH" + topic: growsmart/growbox/sensor/ph/state + on_value: + then: + - lambda: 'id(ph) = x;'