How to get the time in an ESPHome configuration?

Fair ask…

external_components:
  - source:
      type: git
      url: https://github.com/ssieb/esphome_components
    components: [ ht16k33_alpha ]

substitutions:
  device_name: adafruit-test
  friendly_name: adafruit_test

packages:
  wifi: !include common/wifi.yaml
  device_base: !include common/esp8266.yaml

# -------------------------- Overrides --------------------------
esp8266:
  board: d1_mini

i2c:
  scl: D1 #GPIO3
  sda: D2 #GPIO5
  frequency: 50000
  scan: true

time:
  - platform: homeassistant
    id: homeassistant_time

text_sensor:
  - platform: template
    name: "Current Time"
    id: current_time
    lambda: |-
      char str[6]; // Space for "HH:MM\0"
      time_t currTime = id(homeassistant_time).now().timestamp;
      strftime(str, sizeof(str), "%H%M", localtime(&currTime));
      return { str };
    update_interval: 60s

display:
  - platform: ht16k33_alpha
    address: 0x71
    scroll: false
    lambda: |-
      char formatted_time[12];  // Space for "HHMM\0"
      snprintf(formatted_time, sizeof(formatted_time), "%s", id(current_time).state.c_str());
      it.set_brightness(0.1);
      it.print(formatted_time);

  - platform: ht16k33_alpha
    address: 0x70
    scroll: false
    lambda: |-
      it.set_brightness(0.1);
      it.print("TEST"); 

Just as a contrast, I use a seed studio sensecap indicator (https://www.seeedstudio.com/SenseCAP-Indicator-D1Pro-p-5644.html with openhasp to do a bedside glucose/time display. Works just great.

Here is a screenie.

image

Looks more versatile than mine:

Mine currently gets all its data via MQTT. How does the Sensecap get its data?

Via mqtt from HA.

bedside:
  objects:
    - obj: 'p1b4'
      properties: 
        text: '{{ states("sensor.blood_sugar") }}mmol/L'
    - obj: 'p1b2'
      properties:
        text: '{{ states("sensor.blood_sugar_trend")}}'
    - obj: "p1b3"
      properties:
        "text": "{% from 'easy_time.jinja' import clock %}{{ clock() }}"
    - obj: 'p1b5'
      properties:
        "text": '{{ states("sensor.blood_sugar_delta")}}'

Cool. My wife likes the look of the device. Can it be used for other features of Home Assistant?

1 Like

Take a look at Overview - openHASP

Thanks, but I already have four HASP devices including one in a desktop stand. She wants something where she can also see the front-porch camera.

No i don’t believe you can cast a video too it. A picture, yes.

Maybe if the picture is updated every ten or twenty seconds? Enough to determine who is at the door.

That might work. Use the openhasp.push_image service. See Example Automations - openHASP

I wanted this format - “Mon 5. Feb” and got it with:

auto now = id(rtc_time).now();
// check valid time
if (now.is_valid()) {
  char dateStr[20];
  // Manually construct the date string cuz %-d is not supported
  sprintf(dateStr, "%s %d. %s", now.strftime("%a").c_str(), now.day_of_month, now.strftime("%b").c_str());
  it.printf(w/2 + hxadd, hy, id(text_small), get_time_color, TextAlign::CENTER, dateStr);
}