egguy / grott-home-assistant-add-on

Grott Home Assistant add-on - Native MQTT plugin
31 stars 10 forks source link

Any way to use this if you're not running HASS Supervised or HASS OS, i.e. HASS in Docker? #9

Closed Freekers closed 1 year ago

Freekers commented 1 year ago

To my knowledge, it's only possible to run add-ons if you're running HASS Supervised or HASS OS. Is there any way to make use of this add-on if you're running HASS in Docker as well?

Thanks!

egguy commented 1 year ago

Hello,

A simple Dockerbuild file, can be:

FROM python:3.9

EXPOSE 5279/tcp
ENV LANG C.UTF-8

# Copy data for add-on
WORKDIR /app
RUN curl -Lk 'https://github.com/johanmeijer/grott/archive/refs/heads/master.zip' --output files.zip && unzip -o files.zip && rm files.zip && mv grott-*/*.py ./
# Move the addon
RUN curl -L 'https://raw.githubusercontent.com/egguy/grott/feature/ha-extension/examples/Home%20Assistent/grott_ha.py' -o grott_ha.py
RUN touch grott.ini

#Install required python packages 
RUN pip3 install paho-mqtt requests influxdb influxdb

CMD ["python", "-u", "grott.py", "-v"]

You can do something like:

If you want a ready-made image, I've generated one on my docker hub (https://hub.docker.com/r/egguy/grott):

docker run -p 5279:5279 --restart on-failure -v $(pwd)/grott.ini:/app/grott.ini egguy/grott:2.7.8

Freekers commented 1 year ago

Thanks for your reply.

Your Docker image seems to be working :) The sensors were automatically created in HASS and Data is flowing in. However, I do see the following warnings/errors in the logging that might need fixing:

     - MQTT jsonmsg: 
             {"device": "XXXXXXXXXXX", "time": "2023-02-15T20:43:33", "buffered": "no",
             "values": {"datalogserial": "XXXXXXXXXX", "pvserial": "XXXXXXXXXX",
             "pvstatus": 0, "pvpowerin": 0, "pv1voltage": 647, "pv1current": 0,
             "pv1watt": 0, "pv2voltage": 650, "pv2current": 0, "pv2watt": 0,
             "pvpowerout": 0, "pvfrequentie": 4999, "pvgridvoltage": 2362,
             "pvgridcurrent": 0, "pvgridpower": 0, "pvgridvoltage2": 0, "pvgridcurrent2":
             0, "pvgridpower2": 0, "pvgridvoltage3": 0, "pvgridcurrent3": 0,
             "pvgridpower3": 0, "totworktime": 44808891, "pvenergytoday": 85,
             "pvenergytotal": 46290, "epvtotal": 47779, "epv1today": 43, "epv1total":
             18890, "epv2today": 44, "epv2total": 28889, "pvtemperature": 243,
             "pvipmtemperature": 253}}
     - Grott MQTT topic used : energy/growatt
     - MQTT send failed: [Errno 99] Cannot assign requested address

And:

     **********************************************************************************
     - Grott - libscrc not installed, no CRC checking only record validation on length!
     **********************************************************************************

Thanks!

egguy commented 1 year ago

For the libscrc it's normal. The CRC is not used for the proxy mode, there's still sanity check in place. It's mostly used in the case of grottserver.

As for the send failed, you can disable the MQTT output in the grott.ini file. e.g.

[MQTT]
nomqtt = True

The HA addon use the data of the MQTT payload, but has it own way of sending (for HA config/autoconfig purpose). You can still have the normal MQTT output (or a second MQTT output to a third party)

Freekers commented 1 year ago

Thanks for the information, I appreciate it.

It seems like the container is ignoring certain variables in the .ini file. I have set verbose to False and nomqtt to True. Yet the container still runs in verbose mode with mqtt enabled.

Container Logging:

2023-02-16T09:28:37.244075046Z   **********************************************************************************
2023-02-16T09:28:37.244103536Z   - Grott - libscrc not installed, no CRC checking only record validation on length!
2023-02-16T09:28:37.244107443Z   **********************************************************************************
2023-02-16T09:28:37.245229667Z Grott Growatt logging monitor : 2.7.8
2023-02-16T09:28:37.246507292Z 
2023-02-16T09:28:37.246523797Z Grott Command line parameters processed:
2023-02-16T09:28:37.246527310Z  verbose:         True
2023-02-16T09:28:37.246530121Z  config file:     grott.ini
2023-02-16T09:28:37.246541521Z  output file:     <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
2023-02-16T09:28:37.246552845Z  nomqtt:          False
2023-02-16T09:28:37.246563663Z  inverterid:      automatic
2023-02-16T09:28:37.246574521Z  pvoutput:        False
2023-02-16T09:28:37.246585909Z  blockcmd:        False
2023-02-16T09:28:37.246596777Z  noipf:           False
2023-02-16T09:28:37.246599396Z 
2023-02-16T09:28:37.246609811Z Grott process configuration file
2023-02-16T09:28:37.246878751Z 
2023-02-16T09:28:37.246908461Z Grott process environmental variables
2023-02-16T09:28:37.247007544Z 
2023-02-16T09:28:37.247028489Z Grott override settings if set in commandline
2023-02-16T09:28:37.247259574Z 
2023-02-16T09:28:37.247283791Z Grott process json layout files
2023-02-16T09:28:37.247442858Z 
2023-02-16T09:28:37.247448005Z Grott proxy mode started

Grott.ini

[Generic]
verbose = False
[MQTT]
nomqtt = True
[extension]
extension = True
extname = gott_ha
extvar = {"ha_mqtt_host": "172.22.0.252", "ha_mqtt_port": "1883", "ha_mqtt_user": "XXXXX", "ha_mqtt_password": "XXXXX"}

Docker-Compose

services:
    grott:
        image: egguy/grott:latest
        container_name: grott
        restart: unless-stopped
        ports:
            - "5279:5279"
        volumes:
            - /opt/docker/grott/grott.ini:/app/grott.ini
        environment:
            TZ: Europe/Amsterdam 

The container is able to access and read the grott.ini file:

root@839503b3d1bf:/app# cat grott.ini
[Generic]
verbose = False
[MQTT]
nomqtt = True
[extension]
extension = True
extname = gott_ha
extvar = {"ha_mqtt_host": "172.22.0.252", "ha_mqtt_port": "1883", "ha_mqtt_user": "XXXX", "ha_mqtt_password": "XXXXX"}
Freekers commented 1 year ago

I managed to get it to work using environment variables in the docker-compose file instead of using the grott.ini config file. My compose file now looks as follows:

services:
    grott:
        image: egguy/grott:latest
        container_name: grott
        restart: unless-stopped
        ports:
            - "5279:5279"
        environment:
            gverbose: False
            gnomqtt: True
            gextension: True
            gextname: grott_ha
            gextvar: '{"ha_mqtt_host": "YOUR_IP", "ha_mqtt_port": "1883", "ha_mqtt_user": "XXXXXX", "ha_mqtt_password": "XXXXXX"}'

I have 2 more questions/remarks if you don't mind :)

egguy commented 1 year ago

For the influxdb dependency, I've imported from the original.

The dependencies are lazy loaded, so it could be removed. This image is a generic image for grott and people could use it fto push data in influxDB. From a look on pypi it weights less than 1MO for the sum of both lib.

For the base image, you are right, it works on 3.9-slim. This is a remain of the multi-archi grott/grottserver build I've tested. The grottserver require libscrc and to make an arm image you need to compile libscrc which only works on the non slim version of the image (I did some test, and you can perfectly replace by a python CRC implementation to remove this requirement).

If I start to generate CI build of image, I will probably consider this.

Freekers commented 1 year ago

Thanks for the elaborate answer :)

I will go ahead and close this issue, as my questions have been answered. For those of you who stumble upon this issue, the docker-compose file in my post above should get you going.

Many thanks to @egguy for creating this image, this was was exactly what I needed after Growatt started to ban API users.