M5Stack IKEA Clock with HA MQTT Support

UPDATE: The first version code is on https://github.com/febalci/M5Stack_IKEA_Clock now…

So, i have this M5Stack Fire for a while now. Was looking forward to make something with it but couldn’t find a nice project to use this great product. Until now…

Then i stumbled upon this Youtube video in which someone from Japan managed to replicate IKEA Klockis Travel clock with a M5Stack which is pretty cool i believe…

So started hunting for the source code of this project; since i am way too lazy to write it from scratch and leave it as last resort. Luckily, although the page is in Japanese, i managed to find it in this address.

I want to thank a lot to “yankee” who put his code and the development phases in this page. After a quick google translation; i managed to make it work in my M5Stack Fire, at which i found out there are 3 different accelerometers used in different production dates of Fire. So i converted the MPU-9250 code to MPU-6886 code for my Fire version, and it works pretty good.

So, for non link-clickers, this clock shows date and time, and when you roll it over 90 degrees it shows temperature, and roll it again there comes timer and roll one more time, there it is, the alarm setting page.

Although i am happy with the outcome, i wanted to add/change some things on this code to make it HA compatible. Here is what i added/changed so far:

  1. Add blinking RGB LEDs (The leds on both side of M5stack) and Beep sound for both timer and clock alarms.
  2. Convert month/date to date-month (From Japanese/American to European style)
  3. Added MQTT and so you can feed Temperature value from any temperature sensor in HA.
  4. Added screen brightness dim for battery power save
  5. Change background color to reflect heat/cold for temperature screen and added showing minus degree capability

Planning to add:

  1. Set clock alarm from HA
  2. Show battery percentage value
  3. Disable battery power save screen dim mode when plugged in.

The possibilities are endless with the addition of MQTT and HA i think… But so far here is the outcome screens:




I haven’t measured how long the battery lasts yet. I am going to post it later. And also here are the screens from MQTT fed temperature screens and changing background colors to reflect heat:




I am going to post the code on github very soon, just trying to tidy it since the code is all over the place right now…

EDIT: Here is the Alarm Beeping Video.

4 Likes

This is awesome.

1 Like

Here is the code as i promised:
M5Stack IKEA Clock

Compiled with Arduino IDE 2.0

Command Topic: m5ikea/command

Command message:

{
    "temperature": -8,
    "brightness": 10,
    "powersave": true
}

You can use only one of, or more of the commands in the json like:

{"temperature": 34}

temperature (signed float): It still will show as signed integer in the clock.

brightness (unsigned integer): Between 0-100, 100 being brightest, 1 dimmest, 0 shut down LCD.

powersave (boolean): true dims the LCD to “10” after keeping the clock some sceonds in the same position, whether plugged in or battery.

Added “alarm” and “timer” mqtt commands to set timer and alarm from HA.

{
    "temperature": -8,
    "brightness": 10,
    "powersave": true,
    "timer" : "03:15",
    "alarm" : "14:12"    
}

As far as i see, the battery lasts around 3 hours will full brightness, with %40 brightness it lasts about 5-6 hours… Never tried it with external battery pack or M5 AA battery module.

Nice project!
Better if someone translate it using Esphome! :slight_smile:

For reference, here is an automation example to update temperature and brightness with MQTT:

- alias: M5IKEA Temperature
  description: Send Outside Temperature to M5IKEA
  trigger:
  - entity_id: sensor.calisma_odasi_sensor
    platform: state
  condition: 
    - condition: template
      value_template: "{{ (trigger.from_state.state | float - trigger.to_state.state | float(trigger.from_state.state)) | abs >= 0.1 }} "
  action:
  - data_template:
      topic: m5ikea/command 
      payload: "{\"temperature\": \"{{ states(\"sensor.calisma_odasi_sensor\")}}\", \"brightness\": 50}"
    service: mqtt.publish