Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookbook: mqtt-bmp180-oled.yaml #87

Closed
rradar opened this issue Nov 27, 2018 · 10 comments
Closed

Cookbook: mqtt-bmp180-oled.yaml #87

rradar opened this issue Nov 27, 2018 · 10 comments

Comments

@rradar
Copy link
Contributor

rradar commented Nov 27, 2018

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 (mhaack/mqtt-bme280-homie#6). What would be the best job for it? For sure esphomeyaml! ✨ 🎇 🎆

Part list:

  • esp m3 (for any other esp/board just change platform/board in your yaml!)
    image
  • bmp180/bmp085 (or for bme280 change the sensor platform)
    image
  • oled display
    image
  • some wires (for example dupont cables) to hook things up

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
Copy link
Contributor Author

rradar commented Nov 27, 2018

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 ❓ 😁

@OttoWinter
Copy link
Member

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
Copy link
Contributor Author

rradar commented Dec 2, 2018

@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
Copy link
Contributor Author

rradar commented Dec 15, 2018

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? 😕

@flozsc
Copy link

flozsc commented Dec 17, 2018

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
Copy link

mihalski commented Dec 18, 2018

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

@rradar
Copy link
Contributor Author

rradar commented Dec 18, 2018

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

@Mynasru
Copy link
Contributor

Mynasru commented Dec 20, 2018

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

@minsuke
Copy link

minsuke commented Sep 17, 2019

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
Copy link
Member

@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.

@esphome esphome locked and limited conversation to collaborators Oct 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants