GEM + Grafana + Home Assistant

Discuss anything which doesn't fall into the other categories here.
heimdm
Posts: 10
Joined: Mon Sep 12, 2016 9:09 am

GEM + Grafana + Home Assistant

Post by heimdm » Sat Nov 27, 2021 8:38 pm

I have Grafana setup and have data being ingested. I wanted to add Home Assistant as well. I am struggling with how to get the data in to both Grafana and Home Assistant. I know, I could hook up both serial ports on each GEM, but was hoping there might be a way without going that route.
ben
Site Admin
Posts: 4262
Joined: Fri Jun 04, 2010 9:39 am

Re: GEM + Grafana + Home Assistant

Post by ben » Mon Nov 29, 2021 10:48 am

heimdm wrote:
Sat Nov 27, 2021 8:38 pm
I have Grafana setup and have data being ingested. I wanted to add Home Assistant as well. I am struggling with how to get the data in to both Grafana and Home Assistant. I know, I could hook up both serial ports on each GEM, but was hoping there might be a way without going that route.
How are you sending to your computer? Should be able to multiplex it somehow via software (listen via Python and send to both programs).
Ben
Brultech Research Inc.
E: ben(at)brultech.com
heimdm
Posts: 10
Joined: Mon Sep 12, 2016 9:09 am

Re: GEM + Grafana + Home Assistant

Post by heimdm » Mon Nov 29, 2021 1:27 pm

The home assistant plugin uses TCP Server mode on the GEM. The plugin simply requires you to put in the port. On the Grafana side it just needs to get into the database via btmon.py in either TCP client or server mode.

1) Can btmon.py be configured to act as TCP client and send traffic to Home Assistant that is acting as TCP client?
2) Can the gem be configured to send traffic to multiple network destinations?

Right now, while I wait for my ethernet modules to arrive, I have COM1 (gem) connected to an IP2SL global cache box, and then running VSPE (Virtual Serial Port Emmulator) to connect to the IP2SL (globalcache) and send it to an IP destination. I haven't found a way to multiplex that traffic and send it to multiple destinations.
heimdm
Posts: 10
Joined: Mon Sep 12, 2016 9:09 am

Re: GEM + Grafana + Home Assistant

Post by heimdm » Mon Nov 29, 2021 1:54 pm

After my last reply I tried a few different things with VSPE... and seem to have got the multiplex thing to work.

1. Create a Connector to COM1 (local PC)
2. Create a TCPClient to the global cache IP2SL (TCP 1 => <globalcache-ip>:4999
3. Create a Splitter Device to virtualize COM1 and expose it as COM10 (COM1 => COM10)
4. Create a bridge between COM10 and Home Assistant (Serial Port <=> TCP Client)
5. Create a bridge between COM10 and Grafana (Serial Port <=> TCP Client).

This does appear to work, the only challenge would be having to build a windows VM to run this port replication configuration and making sure it is always running. If you could somehow set multiple server destinations in the GEM network configuration, that would probably be ideal, but I am guessing that probably isn't trival to do within the GEM firmware.
ben
Site Admin
Posts: 4262
Joined: Fri Jun 04, 2010 9:39 am

Re: GEM + Grafana + Home Assistant

Post by ben » Mon Nov 29, 2021 2:07 pm

heimdm wrote:
Mon Nov 29, 2021 1:27 pm
The home assistant plugin uses TCP Server mode on the GEM. The plugin simply requires you to put in the port. On the Grafana side it just needs to get into the database via btmon.py in either TCP client or server mode.

1) Can btmon.py be configured to act as TCP client and send traffic to Home Assistant that is acting as TCP client?
2) Can the gem be configured to send traffic to multiple network destinations?

Right now, while I wait for my ethernet modules to arrive, I have COM1 (gem) connected to an IP2SL global cache box, and then running VSPE (Virtual Serial Port Emmulator) to connect to the IP2SL (globalcache) and send it to an IP destination. I haven't found a way to multiplex that traffic and send it to multiple destinations.
1) BTMon.py is only setup to ingest packets and convert to different formats.
2) The GEM can only send to one client at a time.

What I would do is take something like this: https://github.com/pricheal/python-clie ... /server.py

- Modify run so it just runs forever with each client (I think below should work)

Code: Select all

    
    def run(self):
        while self.signal:
            try:
                data = self.socket.recv(32)
                if data != "":
                    print("ID " + str(self.id) + ": " + str(data.decode("utf-8")))
                    for client in connections:
                        if client.id != self.id:
                            client.socket.sendall(data)
            except socket.error:
                pass
            
            time.sleep(0.2)
- Modify the host, port to use the same values every time.
- Setup BTMon.py and HA to connect to it.
- Setup the GEM to connect to it.

It should push the GEM packet to both BTMon.py and HA.

Your response came in before I posted this, what are you running HA and BTMon.py on?
Ben
Brultech Research Inc.
E: ben(at)brultech.com
heimdm
Posts: 10
Joined: Mon Sep 12, 2016 9:09 am

Re: GEM + Grafana + Home Assistant

Post by heimdm » Mon Nov 29, 2021 3:25 pm

I am running it as linux VM's mostly, HA is running virtually as well.
heimdm
Posts: 10
Joined: Mon Sep 12, 2016 9:09 am

Re: GEM + Grafana + Home Assistant

Post by heimdm » Fri Dec 10, 2021 10:18 am

Now that my ethernet modules have arrived I am circle back on this.

1) Within the GEM network setting, I configured the GEM to act as TCP Server and send data to Home Assistant on port 8000. Home Assistant then gets all the data from the various GEMs in one spot.
2) Within the btmon3.py script instances, I have them running as a service/daemon, it is running in TCP client mode, and dumps the data into my sql database.

This easily gets the data into both Home Assistant and Grafana. In the end, the data is mostly in the home assistant database, so you could configure grafana to search the home assistant database. However, it is a lot easier to work with the database that btmon creates over home assistant, mostly because with btmon all the data is in a single record for the given time stamp.
grafana.png
grafana.png (98.03 KiB) Viewed 5958 times
home-assistant.png
home-assistant.png (50.02 KiB) Viewed 5958 times
jkmonroe
Posts: 4
Joined: Wed Apr 25, 2018 7:54 pm

Re: GEM + Grafana + Home Assistant

Post by jkmonroe » Sun Dec 12, 2021 11:13 am

I have the dashbox, but another option that works would be to setup the GEM in Home Assistant, and then configure InfluxDB and pipe GEM data from Home Assistant to InfluxDB. From there you can easily pull into Grafana and it has the added benefit of not crushing your HASS DB. This is what I am doing and it works really well.
scyto
Posts: 258
Joined: Sun Apr 06, 2014 7:24 pm

Re: GEM + Grafana + Home Assistant

Post by scyto » Tue Dec 14, 2021 2:45 pm

I am utterly confused by the home assistant integration (i see there are 17 of us using it though!)

I have never managed to get the GEM to send data to home assistant.
I configured the tab in GEM but nothing is ever seen by hass.
Can i get dashobx to send instead?
scyto
Posts: 258
Joined: Sun Apr 06, 2014 7:24 pm

Re: GEM + Grafana + Home Assistant

Post by scyto » Tue Dec 14, 2021 2:51 pm

scyto wrote:
Tue Dec 14, 2021 2:45 pm
I am utterly confused by the home assistant integration (i see there are 17 of us using it though!)

I have never managed to get the GEM to send data to home assistant.
I configured the tab in GEM but nothing is ever seen by hass.
Can i get dashobx to send instead?
I seem to have answered my own question, this works.
Attachments
Screenshot 2021-12-14 115032.png
Screenshot 2021-12-14 115032.png (47.86 KiB) Viewed 5939 times
Post Reply