-
Notifications
You must be signed in to change notification settings - Fork 3
/
nodemcu-7seg.yaml
138 lines (128 loc) · 4.1 KB
/
nodemcu-7seg.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
esphome:
name: nodemcu-7seg
platform: ESP8266
board: nodemcuv2
arduino_version: latest
includes: # get from github link below and put into /config/esphome
# https://learn.adafruit.com/adafruit-led-backpack/0-dot-56-seven-segment-backpack
# https://learn.adafruit.com/adafruit-led-backpack/downloads
# https://github.com/adafruit/Adafruit_LED_Backpack
- Adafruit_LEDBackpack.h
- Adafruit_LEDBackpack.cpp
libraries:
- "Adafruit GFX Library"
- "SPI" # unused dependency
logger: {}
api:
password: password
# this is enough to get sensor data updated.
# if also configured as an espHome integration I got duplicate sensor notifications
ota:
password: password
safe_mode: true
wifi:
ssid: ddwrt2G
password: 'password'
domain: .local.lan
manual_ip:
static_ip: 192.168.0.xxx
gateway: 192.168.0.1
subnet: 255.255.255.0
switch: # controls the LED on the nodemcu8266 (to find it)
- platform: gpio
name: "nodemcu-7seg LED"
pin:
number: D0
inverted: yes
globals: # to share data between lambdas
- id: temp
type: int
# restore_value: no default
# initial_value: '0' default
- id: humid
type: int
sensor:
- platform: homeassistant
id: humidity
internal: True
entity_id: sensor.dark_sky_humidity_rounded
# template sensor value_template: >- {{ states("sensor.dark_sky_humidity")|round(0) }}
on_value:
then:
- lambda: |-
id(humid) = x<100 ? x*100 : 9900;
// shift left two digits and keep at two digits
- platform: homeassistant
id: temperature
internal: True
entity_id: sensor.motion_sensor_temperature_rounded
# template sensor value_template: >- {{ states("sensor.motion_sensor_temperature")|round(0) }}
on_value:
then:
- lambda: |-
id(temp) = x*10; // shift left and save for later
- platform: homeassistant
#name: "time7seg"
id: time7seg
internal: True
entity_id: sensor.time7seg
# template sensor value_template: >- {{states.sensor.time.state.replace(":","") | int }}
# each new minute show time, temperature, humidity, and time
on_value:
then:
- lambda: |-
static Adafruit_7segment matrix = Adafruit_7segment();
matrix.begin(0x70);
static int p;
static unsigned char d;
static bool pm;
pm = (x > 1159);
if (x<100) {
p = x+1200;
d = 0b0000110; // segs 2,3 = numeral 1
} else if (x<1000) {
p = x+1000;
d = 0b00000000; // blank
} else if (x<1300) {
p = x;
d = 0b0000110;
} else {
p = x-200;
if (x<2200) {
d = 0b00000000;
} else {
d = 0b0000110;
}
}
matrix.print(p);
// clear left didgit if hour < 10
matrix.writeDigitRaw(0, d);
// add decimal point to right digit for PM
matrix.writeDigitNum(4, p % 10, pm);
matrix.drawColon(1);
matrix.writeDisplay();
delay(3000);
matrix.print(id(temp));
matrix.writeDigitRaw(4, 0b01100011);
matrix.writeDisplay();
delay(5000);
matrix.print(id(humid));
// % one char
//matrix.writeDigitRaw(4, 0b01010010);
// PC
//matrix.writeDigitRaw(3, 0b01110011);
//matrix.writeDigitRaw(4, 0b01011000);
// % two char
matrix.writeDigitRaw(3, 0b01100011);
matrix.writeDigitRaw(4, 0b01011100);
matrix.writeDisplay();
delay(5000);
matrix.print(p);
matrix.writeDigitRaw(0, d);
matrix.writeDigitNum(4, p % 10, pm);
matrix.drawColon(1);
matrix.writeDisplay();
i2c:
sda: 4 # data = D2 = GPIO4
scl: 5 # clock = D1 = GPIO5
scan: False # Adafruit uses 0x70