Skip to content
Snippets Groups Projects
Commit 3bb175d4 authored by Jan Grewe's avatar Jan Grewe
Browse files

add growbox-screen

parent 0cce99f2
No related branches found
No related tags found
1 merge request!1add growbox-screen
Pipeline #1178 passed
...@@ -25,3 +25,5 @@ deploy_configs: ...@@ -25,3 +25,5 @@ deploy_configs:
- cp -rv *.yaml packages /srv/esphome/growsmart/ - cp -rv *.yaml packages /srv/esphome/growsmart/
tags: tags:
- shell - shell
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
substitutions:
devicename: "growbox-screen"
comment: "Grow Box Screen"
packages:
base: !include packages/base.yaml
esp32: !include packages/esp32.yaml
time: !include packages/time.yaml
mqtt: !include packages/mqtt.yaml
display: !include packages/display_cyd2usb.yaml
screen: !include packages/screen.yaml
i2c:
sda: 27
scan: false
spi:
- id: tft
clk_pin: GPIO14
mosi_pin: GPIO13
miso_pin: GPIO12
- id: touch
clk_pin: GPIO25
mosi_pin: GPIO32
miso_pin: GPIO39
display:
- platform: ili9xxx
id: esp_display
model: ili9342
spi_id: tft
cs_pin: GPIO15
dc_pin: GPIO2
color_order: rgb
transform:
swap_xy: true
mirror_x: true
mirror_y: true
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());
# Set up the xpt2046 touch platform
touchscreen:
platform: xpt2046
spi_id: touch
cs_pin: GPIO33
interrupt_pin: GPIO36
update_interval: 50ms
threshold: 400
calibration:
x_min: 180
x_max: 3800
y_min: 240
y_max: 3860
transform:
mirror_x: true
# When the display is touched, turn on the backlight,
# store that we had a recent touch, and update the UI
on_touch:
then:
- light.turn_on:
id: backlight
brightness: 100%
- lambda: |-
id(recent_touch) = true;
output:
- platform: ledc
pin: GPIO21
id: backlight_pwm
- platform: ledc
id: output_red
pin: GPIO4
inverted: true
- platform: ledc
id: output_green
pin: GPIO16
inverted: true
- platform: ledc
id: output_blue
pin: GPIO17
inverted: true
light:
- platform: monochromatic
output: backlight_pwm
name: Display Backlight
id: backlight
restore_mode: ALWAYS_ON
- platform: rgb
name: LED
id: led
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%
max_brightness: 100%
on_turn_on:
- light.turn_on:
id: led
effect: "Default"
interval:
- interval: 5s
then:
- if:
condition:
- lambda: "return !id(recent_touch);"
then:
- light.turn_on:
id: backlight
brightness: 25%
else:
- lambda: "id(recent_touch) = false;"
...@@ -3,5 +3,7 @@ esp32: ...@@ -3,5 +3,7 @@ esp32:
framework: framework:
type: arduino type: arduino
i2c:
wifi: wifi:
power_save_mode: none power_save_mode: none
File added
File added
# 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"
# ============================================================
# 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
]
# Create a Home Assistant blue color
color:
- id: green
hex: 00FF00
- id: red
hex: FF0000
# Setup two binary sensors for the two areas for touch
binary_sensor:
- platform: touchscreen
name: Light Green
x_min: 0
x_max: 120
y_min: 0
y_max: 320
on_press:
then:
- light.turn_on:
id: led
red: 0.0
green: 1.0
blue: 0.0
- platform: touchscreen
name: Light Red
x_min: 120
x_max: 240
y_min: 0
y_max: 320
on_press:
then:
- light.turn_on:
id: led
red: 1.0
green: 0.0
blue: 0.0
# 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
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
# Update the UI state every 10 seconds
interval:
- interval: 1s
then:
- script.execute: update_ui_values
# 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"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment