Last active
February 21, 2021 09:28
-
-
Save Bazmundi/01c835bd86759e918d7eaa5f9a8eb587 to your computer and use it in GitHub Desktop.
TTGO T-Camera on ESPHome that also talks and listens to MQTT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
esphome: | |
name: t_camv162 | |
platform: ESP32 | |
board: esp-wrover-kit | |
wifi: | |
ssid: "xxxx-xxxx" | |
password: "xxxxxxxx" | |
manual_ip: | |
static_ip: xxx.xxx.xxx.xxx | |
subnet: xxx.xxx.xxx.xxx | |
gateway: xxx.xxx.xxx.xxx | |
# Enable fallback hotspot (captive portal) in case wifi connection fails | |
ap: | |
ssid: "T Camv162 Fallback Hotspot" | |
password: "xxxxxxxxxxxx" | |
captive_portal: | |
# Enable logging | |
logger: | |
# Enable Home Assistant API | |
api: | |
ota: | |
# So b8f009c0d984 is actually the mac or chip_id of the esp32 I am downloading this code onto. | |
# Very grubby yes BUT ESPHome does not allow lambda or templates except for certain narrow circumstances. | |
# Note later I am using get_mac_address(), you could also use get_mac_address_pretty() I guess. The point is that | |
# a payload may us a mac address or some other algorithmic means to fill a json response, so why not for will and say | |
# birth? Would otherwise love to have used get_mac_address() in will and birth etc. | |
mqtt: | |
broker: xxx.xxx.xxx.xxx | |
topic_prefix: /os/cameras/b8f009c0d984 | |
birth_message: | |
topic: /os/cameras/status | |
payload: "b8f009c0d984 online" | |
will_message: | |
topic: /os/cameras/status | |
payload: "b8f009c0d984 lost" | |
shutdown_message: | |
topic: /os/cameras/status | |
payload: "b8f009c0d984 offline" | |
log_topic: /os/debug | |
client_id: b8f009c0d984 | |
# /os/herald is literally the place gadets on my home server declare themselves on birth, as part of a automated | |
# discovery process. This would normally be paired with will on /os/lwt BUT, again, no can dooey because ESPHome | |
# does not take into account use cases where will, birth or shutdown payload may be richer than a status text string. | |
# /os/soundOff topic is used outside of birth to have all gadgets report their up status. | |
on_message: | |
topic: /os/soundOff | |
then: | |
- mqtt.publish_json: | |
topic: !lambda |- | |
return "/os/herald"; | |
payload: !lambda |- | |
root["gadgetType"] = 3; | |
root["gadgetId"] = get_mac_address(); | |
root["online"] = 1; | |
binary_sensor: | |
- platform: gpio | |
pin: GPIO19 | |
name: PIR | |
id: movement | |
device_class: motion | |
# So here is the means I preferred to build the literal topic, but assigning the mac address programmatically | |
# This approach would cut down on having zillions of copies of the same file, each with hard mac addresses added. | |
on_state: | |
then: | |
- mqtt.publish: | |
topic: !lambda |- | |
return "/os/cameras/" + get_mac_address() +"/motion"; | |
payload: !lambda |- | |
return id(movement).state ? "1" : "0"; | |
- platform: gpio | |
pin: | |
number: GPIO15 | |
mode: INPUT_PULLUP | |
inverted: True | |
name: Button | |
- platform: status | |
name: Status | |
sensor: | |
- platform: wifi_signal | |
name: WiFi Signal | |
update_interval: 10s | |
- platform: uptime | |
name: Uptime | |
esp32_camera: | |
name: Camera | |
external_clock: | |
pin: GPIO4 | |
frequency: 20MHz | |
i2c_pins: | |
sda: GPIO18 | |
scl: GPIO23 | |
data_pins: [GPIO34, GPIO13, GPIO14, GPIO35, GPIO39, GPIO38, GPIO37, GPIO36] | |
vsync_pin: GPIO5 | |
href_pin: GPIO27 | |
pixel_clock_pin: GPIO25 | |
# power_down_pin: GPIO26 | |
resolution: 640x480 | |
jpeg_quality: 10 | |
vertical_flip: true | |
horizontal_mirror: true | |
i2c: | |
sda: GPIO21 | |
scl: GPIO22 | |
font: | |
- file: "fonts/times-new-roman.ttf" | |
id: tnr1 | |
size: 20 | |
- file: "fonts/times-new-roman.ttf" | |
id: tnr2 | |
size: 35 | |
- file: "fonts/times-new-roman.ttf" | |
id: tnr3 | |
size: 70 | |
time: | |
- platform: homeassistant | |
id: homeassistant_time | |
display: | |
- platform: ssd1306_i2c | |
model: "SSD1306 128x64" | |
address: 0x3C | |
rotation: 180 | |
lambda: |- | |
if(id(movement).state) { | |
it.print(64, 54, id(tnr3), TextAlign::BASELINE_CENTER, "Boo!"); | |
} else { | |
it.strftime(64, 0, id(tnr1), TextAlign::TOP_CENTER,"%d-%m-%Y", id(homeassistant_time).now()); | |
it.strftime(64, 64, id(tnr2), TextAlign::BASELINE_CENTER, "%H:%M", id(homeassistant_time).now()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As per
The logic of the use of MQTT as per.