Y-Clock to HomeAssistant

As you might now I’m a huge fan of SmartHome and tinkering. One of the things I enjoy most is to make existing devices smart by adding e.g. an ESP. So, due to the fact that I’m always searching for new projects, I stumbled over the Y-Clock project of the Pixelkönig (see here). And believe me, I love it.
So many thanks to the Pixelkönig.

What does Y-Clock do? It turns an IKEA FREKVENS (a LED cube) into a LED matrix display, which is able to show the time and some cute animations. Further, its possible to send text messages to that cube in two lines, over MQTT.

I know that Pixelkönig is currently working on that project, and he mentioned in his blog, that he is going to implement some features that will make it possible to integrate that cube into your SmartHome. But as you might guess, I’m a little to impatient so I needed to find a way to send messages to that Cube over HomeAssistant and to set the brightness.

Workaround #1 – Only anonymous MQTT connection

I know that Pixelkönig will fix that in future, but if you face the problem, that you are currently using a non anonymous MQTT broker, and you are neither not willing to change that, nor you what to update the MQTT connection credentials of all your devices, you can do the following steps for a workaround.

  • Create a mirrored, anonymous MQTT broker
  • Configure topics in HomeAssistant configuration

Luckily its pretty easy to host another MQTT broker instance, thanks to Docker and Eclipse Mosquitto. Simply create a docker-compose.yml file with the following content:

version: "3.7"

services:
  mosquitto:
    image: eclipse-mosquitto
    hostname: mosquitto
    container_name: mosquitto
    restart: unless-stopped
    ports:
      - "1883:1883"
      - "9001:9001"
    volumes:
      - ./conf:/etc/mosquitto
      - ./conf/mosquitto.conf:/mosquitto/config/mosquitto.conf

Pretty important in that file is the line:

- ./conf/mosquitto.conf:/mosquitto/config/mosquitto.conf

After that, create a folder named conf/ and a new file named mosquitto.conf. That file need to have the following content:

allow_anonymous true
listener 1883

That defines that the second MQTT broker is going to allow anonymous connections. Thats essentially to send messages to our cube. Thats nothing new, I know. But if you want to add that broker to HomeAssistant you’ll face the fact, that HomeAssistant only allows one MQTT broker. So how to solve that case?
Because of the fact, that the second, anonymous MQTT broker only runs in the local network, we can make use of the mirroring feature of two MQTT brokers. Mosquitto has the functionality that it is able to sync two or more MQTT brokers by simply adding a few lines to the config file we recently created:

connection ha-broker      //name of the connection
address 192.168.0.42:1883 //connection address
topic # both 0            //topics which should be mirrored (in this case every topic)
remote_username admin     //username of the MQTT broker you are connecting to
remote_password password  //password of the connection

Than simply run docker compose up and there we have a MQTT copy of the broker which is configured in HomeAssistant. Hurray!

Last step is, to add the MQTT topics as entities in HomeAssistant.
In the Y-Clock web interface you can configure the topics in the Network section.

Then you need do extend the configuration.yaml of HomeAssitstant with the following lines:

mqtt:
  text:
    - command_topic: yclock/line1
      unique_id: "y_clock_line_001"
      device:
        name: "YClock"
        identifiers: "yclock_001"
      name: "YClock - Line 1"
      object_id: "yclock-line1"
    - command_topic: yclock/line2
      unique_id: "y_clock_line_002"
      device:
        name: "YClock"
        identifiers: "yclock_001"
      name: "YClock - Line 2"
      object_id: "yclock-line2"

Restart your HomeAssistant and tadaa! You did it! By editing the just created text entities, the content will be shown on your cube!

Workaround #2 – Set brightness in HomeAssistant

To be able to set the brightness of the cube in HomeAssistant, we will take advantage of the fact, that settings are set in the web interface of Y-Clock over HTTP requests. The following steps will be necessary:

  • Create a Helper entity
  • Configure a REST Command
  • Add an Automation

The result will look like the following entity

First define a input_number Helper entity with settings like:

  • Name: Cube Brightness
  • Icon: mdi:cube
  • Minimum value: 0
  • Maximum value: 10
  • Display mode: Slider
  • Step size: 1
  • Entity ID: input_number.cube_brightness

Second, extend the configuration.yaml with the following part:

rest_command:
  cube_display_brightness:
    url: "http://{{ ip }}/display?brightness={{ level }}&action=savebrightness"

The parts in the curly braces are variables which will be set in the following automation. Restart your HomeAssistant after changing the config.

Third and last: Create the automation which listens to changes of the state of the Helper entity. You need to fill in the IP of your cube in the data part.

alias: Set Cube Brightness
description: ""
trigger:
  - platform: state
    entity_id:
      - input_number.cube_brightness
condition: []
action:
  - service: rest_command.cube_display_brightness
    data:
      ip: 192.168.0.42
      level: "{{ states('input_number.cube_brightness') }}"
mode: single

So, by changing the state of the Helper entity, its value will be send by performing a REST GET request to your cube and the brightness will be adjusted.

One response

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert