Is there any way to connect Firebase to Hassbian

Hello @Fraid,

I don’t really get you here. I think that the app only should be connected to one EndPoint at a given time, when the EndPoint changes from WebSocketAPI to Firebase, the app should request all the states within the database and update the HomeAssistant class accordingly. If we have multiple endpoints connected at the same time and the states differs from WebsocketAPI and Firebase, the complexity of the app increases.

I didn’t know that. I had one Java and one Android course at university. To be honest, I’m bad at doing GUI, I am more of a backend developer writing stuff in C++ (that’s what I do as a living), but Java is a really neat language too!

I think for retrieving data, we should use some callback methods, the FirebaseEndPoint should be a publisher that the ConnectionHandler is subscribing for, and ConnectionHandler is a publisher that the HomeAssistant is a subscriber for. In this case the HomeAssistant class is not aware of which endpoint that is connected to, all it knows is that the ConnectionHandler is connected to one endpoint and everything is encapsulated. :wink:

Could you explain what we should have these methods for?

Should you call this method and the Endpoints should block the calling thread and wait for new data to be retrieved? Please explain :wink:

Haha! Good, but Google do some good stuff for developers!

Lovelace data can be retrieved from the WebSocketAPIEndPoint.

That’s good news that we are in the same boat!! :slight_smile:

Cheers :wink:

Hi @payano,

I pushed the changed I made for the POC. Can you take a look at https://github.com/Fraid/homeassist-ng.

You’ll see how i turn on my kittle using node-red with :

FirebaseDBManager.callService

I only send from HA-NG to node red, didn’t update the UI, but this can be done by calling following when we setup Firebase once:

FirebaseDBManager.waitOnStatesChange()

If you want to test it, let me know I’ll make a bigger tutorial but basically :
Add your google-services.json at the level of app/build.gradle, and install app.
Create a node red flow with firebase listening to homeassistant/request and forward everything to ha-service like :

And sure it’s one connexion at the time, we sync only if Firebase mode.
WebSocketAPIEndPoint…will see at time :smile:.

The change I made on my repo should answer all your question. If not please let me know.
If I got time also i’ll update the UI as well, so we will have a full picture how I send/receive data through firebase.

Cheers :wink:

Hello @Fraid.
That’s good news and nice that you have a working POC.
Yes it would be really nice if you could share a tutorial on how to set up Firebase. :wink:

Regarding the data types available in Firebase, i noticed that you wrote a comment saying that Firebase does not support BigDecimal, is suppose BigDecimal is another name for double? Is it necessary to have 64 bits of float precision?

How would we know when we shouldn’t use Firebase mode? I suppose that Firebase will be accessible all the time :slight_smile:

Great work!

By the way, I want to decouple JSON from the internals of the code, and only use it when communicating to some of the endpoint nodes. I have created a JSONParser on my Github repo which takes care of all the strings and converts them to the right datatype. UUID, Date, Double, Float, Long and Int.

It would be neat if you could send a PR so i can merge it with master and publish it on Google Play. :slight_smile:

Hi @payano,

So database setup

  1. Log in to https://console.firebase.google.com
  2. Create a new project or use an existing one
  3. Click on « Database » tab, and scroll down to « Realtime Database »
  4. Create a test mode database, because auth doesn’t work with node red a the time.
  1. Go back to Project overview (Top left), create a new android app
  2. Follow the instruction, at the end you’ll get the google-services.json

I just made the tutorial, if you have any issue please let me know, we may need this tutorial after :smiley:!

At the time, it was just a test, so didn’t spend time on it.
But from what I remember, I need to make a converter using String.
I need to verify that, but yes I think some sensor may need that for accuracy, I that may cause issue if we skip that part.

First let’s define our word with HA-S for home-assistant instance (the one install on raspberry or muc…etc) and HA-A for Android app.

So, firebase is enable in Firebase.yaml on HA-S. That part should be created and i’m not into python, but @seba made a sample should be easier.

Then, HA-A will fetch and save the setting and active firebase mode if all the following are true:

  • Device is not in local mode
  • Device is online
  • Firebase is connected to HA-S

Your repo help me a lot! :wink:

Their is some issue we need to fix before or think about if before (soon :smiley: !).

Using node red and firebase:

  • The authentification process in node red process isn’t done. So your firebase db should be in read/write for everyone. Not really an issue if you’re don’t share your db url (https://DB_NAME.firebaseio.com)
  • If you just want to make action we need to update the UI.
  • Same for data, user will need to specify what to sync within node red

Direct connexion with a firebase.py and firebase.yaml on HA-S:

  • firebase.py need to be done.
  • HA-A need mainly to handle firebase callback at least for an alpha version.

So node red will easily work but user will need to create the flow (like this node red flow), at lease just to send the data to HA-S from HA-A that could be an alpha option to publish.
That part I can handle it, but do you think people will be interested ?

The best I think is having a direct connexion with HA-S and Firebase.
Need more work, but it’s better for end user. This option will not required any action except setting up the firebase or import a google-services.json file .

JSONParser don’t really understand that part, but i know that jackson library does that, you can customize the deserialize/serialize.

Hello @Fraid,

I did follow your guide to setup Firebase, but I got confused on how to configure Node Red, I have never used it before, so I got stuck there :confused:

Okay, perhaps we should break the problem down into smaller parts and create tasks for them. I’m not sure how much time it takes to make the implementation in the current codebase, but I want to change the connection handling so we can have multiple endpoints. Today the app uses REST API as primary connection method and have the possibility to add websocket api for callbacks.

What do you mean by that?

How should we tackle the problem with connecting to multiple endpoints, are you thinking of replacing the websocketapi with firebase even when you are on the local area connection and can do a direct connection to the home assistant server?

I tried the Jackson library, but I did my own and can customize it as I choose to. :blush:

I think it would be wise to create issues/tasks for the work that has to be done so we can do them one by one.

Cheers! :blush:

My bad, I’ll make one.
So, i’ll assume you got your firebase instance, and have installed the apk with the google-services.json.

Now node-red, this part i’ll assume everything is setup and running with HA and node-red!

1- Install nod-red-contrib-firebase (You need to click on the tab “install”)


2- I found yesterday that you can import/export a flow, please import this one flow_ha_request

3- You should have the correct flow at this point, double click on onFBEvent() and set your database name then press add.
Unless you don’t have choice, don’t worry about auth type it’s not supported yet, and your database should be read/write for everyone .


4- Press the deploy button (top-right)
5- On device, open the app, stop your WIFI but keep the 3g/4g connexion, and turn on/off a light/or switch…if everything go well your face should be like this now :joy: !

Real quick, when I say direct connexion, I mean like a module in HA that just sync data to firebase on demand and listen for any entry to “homeassistant/request” (see seba post). I’m sure when node-red will be setup, you’ll understand, because it’s the same thing .

I don’t think we should use Firebase as a main db because:

  • it’s cloud service
  • There is a limit of 20k query per day or something around it. It’s ok for communication, but if you sync every sensor, every second, you’ll reach the limit of 20k.

For dev time with current repo, I think it’s easier with node red. Like less than one full week because there still some R&D to do for the distribution part.

With the import feature I discovered, the main task for node-red will be:

  • Create the nod-red flow for sync data
  • Create the nod-red flow for request (Already done : flow_ha_request)
  • Handle callback of Firebase to update states, guess this will do ?
  getContentResolver().update(Uri.parse("content://com.payano.homeassistant.provider.EntityContentProvider/"), entity.getContentValues(), "ENTITY_ID='" + entity.entityId + "'", null);
  • Better way for firebase configuration for end user (we definitively can’t ask end user to generate an APK -_- ).

I don’t think I’ll get time today but probably tomorrow. I’ll work a little on it, and will add some issue for task.

Great! i have created a section in the wiki, task is created: https://github.com/payano/homeassist-ng/issues/16
It would be nice to have the configuration with pictures documented there.

I have also created a task “Implement firebase” https://github.com/payano/homeassist-ng/issues/17. I don’t know if the task is too large or if we should split it up even further, i think you can decide that better than me. :slight_smile:

Yes, do we have any solution for that problem. It would be nice to have a, url + password in the settings to connect to the user Firebase account.

1 Like

Hi @payano,

Work still in progress on my side, firebase config also work within the app! Will push after error handling probably this week.

Where you able to setup everything on your side? Can you pull my last commit when you get a chance?

:wink:

Is there any update on this? Im also want to extract xiaomi smart home data and send it to my Firebase database

do you want to do it from HA ? would it work for you from node -red ?