Nightlight / clock

Hi Guys just wanted to share my
(children’s) nightlight/clock

Based on ESPHome inside the cheap 5 euro Ikea light.
It has a clock whose light intensity is controlled by home assistant.
With a light ring
TM1637 0.56"
SK6812 Ledring

It is set to get green based on a schedule so she knows she can come out of bed.



Screenshot 2024-02-01 153326

Also figured out how to set correct time setings from ESPHome

For those who are struglig to remove leading zero
or show 12hr format here you go

display:
platform: tm1637
clk_pin: GPIO18
dio_pin: GPIO19
update_interval: 2s
intensity: 0
lambda: |-
it.strftime(“%-I:%M %p”, id(hass_time).now());
it.set_intensity(id(juna_clock_intensity).state);

time_format 24hr use : “%H.%M”
time_format 12hr use: “%I.%M”
time_format 12hr with leading zero removed use: “%-l:%M%p”
edit - not working in esp home … the test in the script worked like charme

12hr format is easier to read for younger children

hope this can help others

1 Like

Awesome! Thank you for showing how you achieved removal of the leading zero. I’ve been trying to figure this out for some time.

Nice project, BTW.

Hi Blackwell

As a script it works, but from ESPHome the screen remains black.
tried several thing.
sorry man
Screenshot 2024-02-02 080436

i know values can be shown on the display so my next thing to try is to put the time in to a sensor or an input_number so the time 02:34 will become 2.34 as a value.
this will take me some time as my experience is not that far

maybe somebody has some thoughts

So I discovered :unamused:

I’m happy I fell across your message though as I’m using a script were the %-I worked perfectly. Thanks

SUCCES !! :grinning:
Removing the leading zero

Step 1

Dump the time as AM/PM value in a sensor with a dot as separator (readable for the display lateron in ESPHome)

note the details
-I = hours in am pm
. = used as separator (dot)

Add the following sensor in your configuration.yaml

- platform: template
    sensors:
      timenew:
        friendly_name: 'XTime'
        value_template: "{{ now().strftime('%-I.%M') }}

this results in the next new entity (Note 9:40 becomes 9.4)

Screenshot_1

This sensor we can now use in ESPHome…
First reboot home assistant

Import that sensor and use it as an ID.

sensor:
  - platform: homeassistant
    entity_id: sensor.timenew
    id: timenew

Now we will use this value to show the time
we start writing the time lower than 10 from the second digit on the display
and set the value fixed as a 2 decimal digit .2f"

equal or higher from the first digit. Compared to the time as sensor

display:
  platform: tm1637
  clk_pin: GPIO18
  dio_pin: GPIO19
  update_interval: 2s
  intensity: 0
  lambda: |-
        if (id(timenew).state < 10) {
          it.printf(1, "%.2f", id(timenew).state); 
          it.set_intensity(id(juna_clock_intensity).state);
        } else {
          it.printf(0, "%.2f", id(timenew).state);
          it.set_intensity(id(juna_clock_intensity).state);
        }

see result below

Screenshot_6
Screenshot_7

Nice project!
You could also add a capacitive sensor inside to switch on/off the light.

There is a zigbee switch on the wall.
With a rolling selector in the background rolling through all the presets.

On a timer it goes to green indicating she may come out of bed.
Plus side. No noise that wakes her.
Only one led goes to green for reduced brightness.