Custom component - Divoom TimeBox notifier

NOTE: This does not work with current HA versions, and I won’t be doing any further work on it. New owners welcome to pick it up.

I’ve been working on a custom component to let Home Assistant interact with a TimeBox pixel speaker from Divoom.

So far, the component is able to switch between the built-in display modes (clock, temperature), and upload and display static images. I’m planning on adding support for animations eventually, as well as tools to make converting and loading images a little less hairy.

The repository at https://bitbucket.org/pjhardy/homeassistant-timebox has the component, a handful of images to get started, and docs about using it and creating images.

2 Likes

As an example automation using this, the Australian Bureau of Meterology publishes weather forecast feeds that include a forecast icon code, just a code representing which icon to use when displaying forecast info. I’m scraping that icon code in to a sensor (sensor.weather_forecast_icon), and using this automation to show an icon for the weather forecast on the TimeBox in the morning:

- id: timebox weather icon
  alias: timebox weather icon
  trigger:
    platform: time
    at: 06:30 
  action:
    service: notify.timebox
    data_template:
      message: blank
      data:
        mode: image-file
        file-name: >
          {%- set icons = ['','sunny','clear','mostly-sunny','cloudy','','hazy-foggy','showers','windy','hazy-foggy','showers','rain','scary','scary','scary','storm','showers','showers','scary'] -%}
          {%- set index = states.sensor.weather_forecast_icon.state | int -%}
          {{ iconx[index] }}

Apparently tomorrow it will be mostly sunny.

1 Like

Thank you soo much! This is some great work. I bought a Timebox mini yesterday and will try to follow your docs and include it to HA as well!

1 Like

I haven’t actually tried on a mini, just the full size TimeBox. Hopefully the protocol is close enough that most things work!

Unfortunately I’m using hass.io so I’m not even able to install the dependencies if I understood correctly. I think I would have to create a component out of your code which I have no experience with up to now. I’m still trying to get started with hass.io

Sorry, I was afraid that might be the case, but didn’t know enough about hass.io to say for sure.

Sounds like the issue is that the python module to talk to the TimeBox, in turn uses the PyBluez module for Bluetooth communication, which has native code that has to be compiled. I may be able to update the library to only use the Python standard library, but afraid with the holiday season coming up it’ll be a few weeks at least before I can dedicate any time to it. :frowning:

No worries, I still think you did a great job there. I’m currently trying to use the official hass.io BCM43xx plugin to conect the Timebox at all.

Edit: Okay, I saw that many others had the idea before me but for hass.io it seems that there is no real option currently due to the plugin “limitation”. I did check the HA plugin tutorials and also suceeded with the example. However, unfortunately my skills are not good enough to port your work to a hass.io plugin. I would revert back to hassbian but there are just too many features I like about hass.io.

I’ve just pushed a new version of this custom component that removes the dependency on the PyBluez module - it now connects to the TimeBox using pure python modules. Easier to install and use, and I’m hoping it will now work with hass.io and the Bluetooth add-on. Unfortunately I don’t have a Pi3 to test that on, though.

Hi,
I’m triying to get your library or some of the others that i’ve found on Github to work with a timebox mini but no results.
The connection seems to be ok but nothing is displaying, I’m wonderring if the protocol might be different.
@bigbemme did you manage to display something?

Antoine

You’re almost certainly using different forks of the library I’m using for this component. Sorry, I don’t have the hardware to test the Mini, and can’t really help get it working :frowning:

Sorry, I’m still waiting for my second Pi3 from China to install hasbian and test then. Will let you know…

ok i’ll let you know if i find somthing…

Hi Antoine,
I managed to get it working with hassbian just now. Where did you get stuck?

I got it working now with hassbian and timebox-mini. Here is a small guide:

with hassbian already installed:

  1. download the data from the bitbucket link in the first post of the thread
  2. extract the timebox-images folders to your config folder
  3. create a custom_components folder in you config folder and extract the notify folder in there
  4. turn on the timebox device
  5. type sudo hciconfig hci0 up
  6. type hcitool scan and write down the mac of the timebox somewhere
  7. add the component to the configuration.yaml so that it should look like this:
notify:
  - name: ledbox
    platform: timebox
    mac: your mac address
    image_dir: timebox-images
  1. create a test automation. Here is an example:
- id: id8
  alias: 'Test'
  trigger:
    platform: state
    entity_id: input_boolean.tester
    from: 'off'
    to: 'on'
  action:
    service: notify.ledbox
    data_template:
      message: blank
      data:
        mode: image-file
        file-name: 'sunny'
  1. restart HA and test your automation

ATTENTION: I had some error messages that an image named ha-logo.json was missing and it was indeed not located in the images folder. I simply copied one of the existing images and adjusted it with all 15 so that you basically get a white image. Then simply rename it with ha-logo.json and that will image will be loaded after connecting eg. after a homeassisstant restart.

If you don’t want to test with an automation, you can use the “call service” function and choose your notify platform. Here are two service data examples:

 {
   "message": "",
   "data": {
     "mode": "clock"
   }
 }

and

 {
   "message": "",
   "data": {
     "mode": "image-file",
     "file-name": "storm"
   }
 }

I didn’t manage to try the mode “off” since this is giving me an erroro message.

Hope that helps.

Great thanks to stibbons for this awesome work!

1 Like

Hi,
Thank you both for the head’s up, i’ll look into it when i’ll have some time.
Antoine

Thanks to some prodding from @bigbemme I’ve uploaded a couple of missing image files to my repository. The first is ha-logo.json, which displays the homeassistant logo on the device when the component connects. The second is required to make the “off” command work; the library I’m using doesn’t actually turn the display off so I just send an all-black image. :slight_smile:

Hi,

also got a Timebox mini. I’m running hass.io and trying to use your component.
I can’t setup the platform. Maybe you can help, I just leave the log here:

Error setting up platform timebox
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/components/notify/__init__.py", line 95, in async_setup_platform
    platform.get_service, hass, p_config, discovery_info)
  File "/usr/lib/python3.6/asyncio/futures.py", line 332, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
    future.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/notify/timebox.py", line 45, in get_service
    image_dir)
  File "/config/custom_components/notify/timebox.py", line 55, in __init__
    self._timebox.connect(host=mac)
  File "/config/deps/lib/python3.6/site-packages/timebox.py", line 40, in connect
    self.socket = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM,
AttributeError: module 'socket' has no attribute 'AF_BLUETOOTH'

*sigh*
This is telling me the the version of python hassio is installing doesn’t support bluetooth sockets. I did some digging, and found this old bug in the operating system hassio is based on. Given it’s been around so long I doubt it’ll get fixed any time soon.

Very frustrating, I put a fair amount of work in to porting the library to use bluetooth sockets specifically to try to avoid problems using this component with hassio. :slight_smile:

Unfortunately, I don’t think there’s a lot I can do to resolve it. Looking around on the forum, doing anything apart from device tracking with bluetooth on hassio doesn’t seem to work. And right now I don’t have hardware or time to experiment trying to find another solution that will work. Sorry, but I can’t do much more than call hassio an unsupported platform for the time being :fearful:

Yeah thanks anyway. I switched to hassbian and everything is working fine :grinning:
Only problem i ran into, mode “off” is not working and the error message is quite funny :rofl:

Invalid mode 'off', must be one of 'off', 'clock', 'temp', 'image', 'animation'

Edit: Two more questions. Why did you change the color code to something between 0-15 and did not use the ‘normal’ rgb codes (0-255)? Especially when you are obvious converting it back to ‘normal’ rgb.
My second question: Is there any way to buy you a coffee? :coffee:

Well that’s embarrassing. :smiley: It’s going to be a couple of weeks before I can test anything, sorry (moving soon, all of my hardware is in boxes). But until there’s a real fix, you can go ahead and use the “blank” image that’s already included to turn the display off.

So, the Timebox seems to use 4 bit colour - each channel can only display 16 colours. But the API in the backend library is a little inconsistent. Images only work properly with 4 bit colour. But a lot of other things, like setting a colour for the clock and thermometer display, use 8 bit colour (0-255). That’s why I’m doing conversion for some things. And yes, I know that that’s also my fork of the Timebox library, I might fix it eventually. :slight_smile:

No, and I’m not planning on accepting donations for my code. But I very much appreciate the sentiment. Thank you. :smiley: