Hi,
I have built a little door sign with a max7219digit matrix display (4 segments) and Wemos D1 controller.
I want to show a random text, every time someone steps in front of the door. The text variables are entered from a HA dashboard.
So far I managed to show one line of text; I am struggeling with two issues:
- only show 1 (out of 4 possible) string at a time
- have the display active with a timeout.
- I can’t get the output value of the photo resistor converted right into a type that the it.intensity method accepts.
about #1: with the code below, the text randomly jumps while scrolling through all possible variables.
about #2: how can I build a timeout function that turns the display off after x seconds once activated. right now, it just stays active as long as someone is standing in front of the sensor.
about #3: what method do I need to use on the id(adc_val).state) in order to cast a decimal ( I suppose) value type? c_str fails with an exception.
Maybe these are all noob questions, however, this is an early journey on HA and ESPhome for me…
Any help or suggestions is appreciated.
TY
this is the code I have:
# https://gist.github.com/debsahu/0ad5e1de664763e84994cc3a4a5d5dc0
# (original source)
esphome:
name: veneer_display
platform: ESP8266
board: d1_mini
wifi:
networks:
- ssid: !secret WiFissid
password: !secret WiFipassword
power_save_mode: high
fast_connect: true
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Veneer Display Fallback Hotspot"
password: !secret WiFipassword
web_server:
port: 80
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
# password: !secret esphome_haapi_pass
ota:
password: !secret espOta
binary_sensor:
- platform: gpio
pin: D2
name: "Door Sensor"
id: door_sensor
device_class: motion
time:
- platform: homeassistant
id: homeassistant_time
spi:
clk_pin: D5 # D5 is connected to CLK of MAX7219
mosi_pin: D7 # D7 is connected to MOSI of MAX7219
display:
- platform: max7219digit
cs_pin: D8 # D8 is connected to CS of MAX7219
num_chips: 4
intensity: 3
scroll_speed: 100ms
update_interval: 100ms
lambda: |-
std::string doortxt_1 = id(doortxt1).state.c_str();
std::string doortxt_2 = id(doortxt2).state.c_str();
std::string doortxt_3 = id(doortxt3).state.c_str();
std::string doortxt_4 = id(doortxt4).state.c_str();
std::string door_txt[4] = {doortxt_1,doortxt_2,doortxt_3,doortxt_4};
int v1 = rand() % 4 + 1;
it.printf(0, 0, id(digit_font), TextAlign::TOP_LEFT, "%s", door_txt[v1].c_str());
it.intensity(atoi(id(adc_val).state));
it.scroll_left();
static int coun = 0;
if (id(door_sensor).state) {
it.turn_on_off(true);
} else{
it.turn_on_off(false);
}
font:
- file: "Amiko.ttf"
id: digit_font
size: 8
text_sensor:
- platform: wifi_info
ip_address:
name: "Veneer Display IP Address"
ssid:
name: "Veneer Display Connected SSID"
bssid:
name: "Veneer Display Connected BSSID"
- platform: homeassistant
name: "Door Txt1"
id: doortxt1
entity_id: input_text.door_txt_1
- platform: homeassistant
name: "Door Txt2"
id: doortxt2
entity_id: input_text.door_txt_2
- platform: homeassistant
name: "Door Txt3"
id: doortxt3
entity_id: input_text.door_txt_3
- platform: homeassistant
name: "Door Txt4"
id: doortxt4
entity_id: input_text.door_txt_4
- platform: homeassistant
name: "HA Brightness"
id: habri
entity_id: input_number.veneer_bri
sensor:
- platform: wifi_signal
name: "Veneer Display WiFi Signal Sensor"
update_interval: 60s
- platform: uptime
name: "Veneer Display Uptime Sensor"
- platform: adc
id: adc_val
pin: A0 # A photoresistor is connected to 3.3V and A0, A0 is connected to GND with 10k resistor
name: "Veneer Display Brightness"
update_interval: 10s
unit_of_measurement: "adc"
filters:
- multiply: 3.3
- calibrate_linear:
- 0.0 -> 0.0
- 3.3 -> 15