esphome / esphome-docs

Source for esphome.io documentation files.
https://esphome.io/
Other
352 stars 1.81k forks source link

Cookbook: mqtt-bmp180-oled.yaml #87

Closed rradar closed 5 years ago

rradar commented 6 years ago

I was inspired by mqtt-bme280-homie (https://github.com/mhaack/mqtt-bme280-homie/) and wanted to extend it to also work without active wifi/mqtt connection (https://github.com/mhaack/mqtt-bme280-homie/issues/6). What would be the best job for it? For sure esphomeyaml! :sparkles: :sparkler: :fireworks:

Part list:

The total hardware costs are around $5 when ordered directly from the country of origin.

For the font I used five by five licensed under CC BY 4.0 from dafont: https://www.dafont.com/de/fivebyfive.font

esphomeyaml:
  name: mqtt-bmp180-oled
  platform: ESP8266
  board: esp8285

wifi:
  ssid: 'xxx'
  password: 'xxx'

mqtt:
  broker: 'xxx'
  username: 'xxx'
  password: 'xxx'

# Enable logging
logger:

ota:
  password: 'xxx'

i2c:
  sda: 0
  scl: 2
  scan: False

binary_sensor:
  - platform: status
    name: "mqtt-bmp180-oled Status"
    id: status

sensor:
  - platform: wifi_signal
    name: "mqtt-bmp180-oled WiFi Signal"
    update_interval: 60s
    id: signal

  - platform: bmp085
    temperature:
      name: "mqtt-bmp180-oled Temperature"
      id: temperature
    pressure:
      name: "mqtt-bmp180-oled Pressure"
      id: pressure
    update_interval: 60s

switch:
  - platform: restart
    name: "mqtt-bmp180-oled Restart"

font:
  - file: "five.ttf"
    id: five8
    size: 8

time:
  - platform: sntp
    id: time
    servers:
      - 0.pool.ntp.org

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    address: 0x3C
    lambda:  |-
      it.printf(0, 10, id(five8), "Temp: %.1f Celsius", id(temperature).value);
      it.printf(0, 20, id(five8), "Pressure: %.1f hPa", id(pressure).value);
      it.strftime(0, 35, id(five8), "Time: %H:%M", id(time).now());
      it.strftime(0, 45, id(five8), "Date: %d.%m.%Y", id(time).now());
      it.printf(0, 60, id(five8), "Wifi: %s", id(status).value ? "Online" : "Offline");
      it.printf(80, 60, id(five8), "%.1f", id(signal).value);

And the result looks like this:

image

rradar commented 6 years ago

Little off topic: the original homie sketch by @mhaack has 4 pages (Temperature, Humidity, etc.) witha very nice layout and a very nice sliding animation/effect while changing the single pages.

Looks a little bit like this and is probably based on homie-display (https://github.com/luebbe/homie-display) from @luebbe

image image

Something like this (more than one page and animations) is not yet possible with esphomeyaml - right :question: :grin:

OttoWinter commented 6 years ago

Awesome setup! Thanks for sharing!

By cookbook entry I meant creating an entry here: https://esphomelib.com/esphomeyaml/index.html#cookbook 😅

I will try to convert this guide to the docs format soon, so that other users can profit from this :)

@rradar As for the last post: Yes, more than one page is possible:

display:
- platform: some_platform
  lambda: |-
    static int i = 1;
    if (i == 1) {
      // draw first page
      i = 1;
    } else if (i == 2) {
      // draw second page
      i = 3;
    } else if (i == 3) {
      // draw last page
      i = 1;
    }

but animations: no, at least not easily. As you have direct access to the display (you can draw each pixel individually) it is of course technically possible, although it would not be fun to implement.

Animations would need a major rethink of the display engine. This "draw the entire display from scratch every time" approach is great for quick development, but makes animations difficult. Animations would require a framework where you first add a bunch of widgets at setup time and modify them each frame.

rradar commented 6 years ago

@OttoWinter I'm trying right now to show more than one page (my idea was to switch the pages after n seconds). I'm not sure how to implement this. With your sketch just page one get's shown. What would be the trigger to change the page here?

Herzliches Dankeschön!

rradar commented 5 years ago

Sorry again for asking but how are the pages triggered with this sketch?

display:
- platform: some_platform
  lambda: |-
    static int i = 1;
    if (i == 1) {
      // draw first page
      i = 1;
    } else if (i == 2) {
      // draw second page
      i = 3;
    } else if (i == 3) {
      // draw last page
      i = 1;
    }

It always stays on page 1 for me? :confused:

flozsc commented 5 years ago

It always stays on page 1 for me? 😕

I think you'll need to set i to 2 after drawing the first page - probably a typo.

display:
- platform: some_platform
  lambda: |-
    static int i = 1;
    if (i == 1) {
      // draw first page
      i = 2;                     // <-- *here*
    } else if (i == 2) {
      // draw second page
      i = 3;
    } else if (i == 3) {
      // draw last page
      i = 1;
    }
mihalski commented 5 years ago

Couldn't the i be the the output from another sensor/input? some sort of toggle.. or timer?

rradar commented 5 years ago

@mihalski I thought a timer (for example 15 seconds) would be sufficient for the first working sketch. Any ideas how to implement this?

Mynasru commented 5 years ago

Isn't i updated every time the display updates (update_interval)?

minsuke commented 5 years ago

hello

can I make a image change process, conditional weather condition. ?

ex) if 1 then cloudy image, if 2 then sunny image.

I don't know how to make it.

OttoWinter commented 5 years ago

@minsuke You'd need to use some C++ if conditions to do that (I think some of the cookbooks on https://esphome.io may have some examples for that).

Anyway, I'm closing this issue because the cookbook is now on esphome.io - not in the GitHub issue section.