Sibo Tablet + ophaalkalender goodness

I recently did a complete renovation where now my complete house is running on HomeAssistant (including all lights, climate control, … ).

One thing I’m happy about is a Sibo tablet that I’ve build in (https://www.alibaba.com/product-detail/SIBO-Customized-Android-Wall-Mount-Tablet_60366060799.html?spm=a2700.7724857.normalList.46.5dd568eaxYjRIL)

Now, each time I need to put out the trash, the tablet shows a red background (see picture). If there is a birthday, it’s green.

It works as follows:

  • I have some automations that create persistent notifications (e.g. when I need to put out the trash or there is a birthday)
  • I wrote a custom android service that listens to the html 5 server sent events from homeassistant and which then turns the correct background on
3 Likes

Hi there @rdehuyss ,

Is there any way you could share how you did the html 5 sending events?

1 Like

Hi @Vasco,

HomeAssistant has everything build-in: https://developers.home-assistant.io/docs/en/external_api_server_sent_events.html

Is this enough to get you started? I did not experience any problems with the api…

1 Like

Thanks I’ll look into it! Wasn’t aware :smile:

hola como pudistes meter homeasistant ahi.

How can you control the gpio’s on this tablet? Can anybody help me with this?

There is a library you can use to do so. I contacted the seller and they gave it to me immediately. I don’t know if I can share it myself though.

Can you copy a part of your configuration to show me how you did?
I have mailed sibo to see what they have.
Thanks for your reply.

I subscribe to the server sent events of homeassistant. This is the code in the eventlistener:

package com.example.hassbackground.service;

import android.app.smdt.SmdtManager;
import android.util.Log;

import com.here.oksse.ServerSentEvent;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.Date;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class HassEventHandler implements ServerSentEvent.Listener {

    private SmdtManager smdtManager;
    private Date lastMessageDate;
    private Date lastHttpGetDate;

    public HassEventHandler(HassService service) {
        this.smdtManager = SmdtManager.create(service);
        try {
            checkForNotifications();
        } catch (Exception e) {
            Log.e("HassService", "Error", e);
        }
    }

    @Override
    public void onOpen(ServerSentEvent sse, Response response) {

    }

    @Override
    public void onMessage(ServerSentEvent sse, String id, String event, String message) {
        Log.i("HassBackground", event + " - " + message);
        this.lastMessageDate = new Date();
        if(message.equals("ping")) return;
        try {
            JSONObject jsonObject = new JSONObject(message);
            if(jsonObject.getString("event_type").equals("state_changed") && jsonObject.getJSONObject("data").getString("entity_id").startsWith("persistent_notification")) {
                checkForNotifications();
            }
        }
        catch (Exception e) {
            Log.e("HassBackground", "MessageError", e);
        }
    }

    @Override
    public void onComment(ServerSentEvent sse, String comment) {

    }

    @Override
    public boolean onRetryTime(ServerSentEvent sse, long milliseconds) {
        return false;
    }

    @Override
    public boolean onRetryError(ServerSentEvent sse, Throwable throwable, Response response) {
        return false;
    }

    @Override
    public void onClosed(ServerSentEvent sse) {

    }

    @Override
    public Request onPreRetry(ServerSentEvent sse, Request originalRequest) {
        return null;
    }

    public Date getLastMessageDate() {
        return lastMessageDate;
    }

    public Date getLastHttpGetDate() {
        return lastHttpGetDate;
    }

    private void checkForNotifications() throws Exception {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url("http://192.168.1.250:8123/api/states")
                .addHeader("Content-Type", "application/json")
                .addHeader("Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIzNjE5NWI4MjQ4NGI0M2IyYTliMDQ2OGVjMDBmOTZiMiIsImlhdCI6MTU0ODU4MjEyNSwiZXhwIjoxODYzOTQyMTI1fQ.Yx3b71JXEwleSTWyFweHVQSAHrM714Nhz9loXVYltt0")
                .build();

        try (Response response = okHttpClient.newCall(request).execute()) {
            String result = response.body().string();
            JSONArray jsonArray = new JSONArray(result);
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject entity = jsonArray.getJSONObject(i);
                if(entity.getString("entity_id").startsWith("persistent_notification") && entity.getString("state").equals("notifying")) {
                    if(entity.getString("entity_id").contains("todo_")) {
                        showRedBackground();
                    } else if(entity.getString("entity_id").contains("verjaardag")) {
                        showGreenBackground();
                    }
                    return;
                }
            }

        } catch (Exception e) {

        } finally {
            this.lastHttpGetDate = new Date();
        }
        showNoBackground();
    }

    private void showNoBackground() {
        if(smdtManager == null) return;
        smdtManager.smdtSetExtrnalGpioValue (1,true);
        smdtManager.smdtSetExtrnalGpioValue (2,true);
    }

    private void showBlueBackground() {
        if(smdtManager == null) return;
        smdtManager.smdtSetExtrnalGpioValue (1,true);
        smdtManager.smdtSetExtrnalGpioValue (2,false);
    }

    private void showGreenBackground() {
        if(smdtManager == null) return;
        smdtManager.smdtSetExtrnalGpioValue (1,false);
        smdtManager.smdtSetExtrnalGpioValue (2,true);
    }

    private void showRedBackground() {
        if(smdtManager == null) return;
        smdtManager.smdtSetExtrnalGpioValue (1,false);
        smdtManager.smdtSetExtrnalGpioValue (2,false);
    }
}