Getting GivTCP running

11 comments started 2023-11-08 last 2023-11-10
Home Automation
R
#1 rivimey

To my embarrassment, I am struggling to get GivTCP running using manual docker setup and would appreciate some help. I have a Pi 4 running ubuntu but not the HA-OS because I wanted to use it for other things too, so HA is running as a docker. Consequently there is no Add-ons support 😞.

I have some instructions for running GivTCP in docker also, and have got it "running", but not connecting to the Mosquitto instance running on the host OS: from within the GivTCP container it keeps saying connection refused although I can't see why.

Any thoughts on how to resolve this? I'm running this command, having pulled the givtcp-ma image:

docker run --name GivTCP -d -p 6345:6345 -e INVERTOR_IP_1=givenergy.net.ivimey.org -e NUMBATTERIES_1=2 -e MQTT_ADDRESS=192.168.32.51 -e WEB_DASH=True -e MQTT_USERNAME=givtcp -e MQTT_PASSWORD="pw" britkat/giv_tcp-ma

Presuming I get it working, I am still unsure how to tell HA that GivTCP exists...

#2 PianSom

rivimey
OK, lots to unpack here!

1 What is the internal I address of your inverter? I doubt that givenergy.net.ivimey.org resolves to that internal address. When you have found it (probably by looking at your router) then you need to put that into INVERTOR_IP_1
2 Have you set up a MQTT broker at 192.168.32.51? Can you use a program like MQTT Explorer to connect to it successfully? Have you registered the username givtcp with the broker?

Once GivTCP is successfully publishing to the broker then HA will automatically see it (assuming that you have added the broker to HA as a MQTT integration!), provided the GivTCP env variables MQTT_OUTPUT and HA_AUTO_D are both true (don't recall if they are by default)

R
#3 rivimey

Hi, Thanks for the response.

I run my own DNS server with a number of internal domains, and it does resolve. I could also have set the '51 address to a hostname but in this case I wasn't sure whether in this case it was being resolved (rather than assuming it was an IP address already).

I have set up the broker on '51, with a listener on ::0 on the default port. I am not aware of the explorer... I know very little indeed of mqtt. Perhaps using mosquitto_pub would be quicker? In my mosquitto config I have for the moment enabled anonymous login and enabled logging of everything. I am now seeing lots of PINGREQ / PINGRESP in the log, all from the same Id.
I think that GivTCP is already in contact with the inverter, but I am not sure that HA is in contact with (my) mosquitto broker.

AUTO_D is indeed on by default, and MQTT_OUTPUT is also enabled.

#4 PianSom

rivimey
Ah, I stand corrected on the IP! 🙂

For sure my next step would be to download MQTT Explorer. Although you can go down the route of mosquitto_pub/sub, I think future you will be happy you chose to use Explorer - just a handy tool to have around.

Either way, the next step is to make sure that GivTCP is pubing to the broker, and the step after is to get HA to sub (and pub!)

#6 PianSom

geoffreycoan

Hey Geoffrey - he mentioned he is a HA Docker user. No add-ons possible for us!

G
#7 geoffreycoan

PianSom thanks, good point.

I use HASS in a VM so it’s simpler. Under the covers from what I see in the logs it looks like hass is running docker containers for the addons so you’d think these could be made available to docker direct installs?

There is a docker image for mqtt explorer https://hub.docker.com/r/ccll/mqtt-explorer that might be worth exploring

A
#8 anglefire

There is also a mqtt Explorer for windows which is dead easy to use.
I did run HA in a docker for a while but is a pain in the arse frankly so now run it on a mini pc which runs proxmox and HA is more running in a vm with several containers with portainer running on each to make installing the docker images easier.

R
#9 Ryggwelter

rivimey

I've recently gone through the same as you - Home Assistant core in manual docker with Mosquitto MQTT and GivTCP in separate containers, on a RPi 4. I'm glad I stuck with it rather than switching to HA OS.
I'd recommend Portainer if, like me, you're relatively new to this stuff. It makes it easy to restart the containers and view the logs. Definitely check the logs so you can see what HA and Mosquitto are doing. I'd also recommend using Docker compose. Again, for me, it makes it easier to check and edit the config.
I'm sure you'll soon have it cracked.

A
#10 Arg0t

rivimey

Here is my docker compose for HA, MQTT, GIVTCP, Zigbee2MQTT, appdaemon and Postgres.

services:
  postgres:

    container_name: "postgres"

    command:
      - "postgres"


    entrypoint:
      - "docker-entrypoint.sh"

    environment:
      - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/postgresql/15/bin"
      - "GOSU_VERSION=1.16"
      - "LANG=en_US.utf8"
      - "PG_MAJOR=15"
      - "PG_VERSION=15.2-1.pgdg110+1"
      - "PGDATA=/var/lib/postgresql/data"
      - "POSTGRES_PASSWORD=****"

    hostname: "postgres"

    image: "postgres:working"

    network_mode: "bridge"

    ports:
      - "5433:5432/tcp"

    restart: "always"

    volumes:
      - "/volume1/docker/homeassistant:/hass"
      - "/volume1/docker/postgres:/var/lib/postgresql/data"

  homeassistant:

    container_name: "homeassistant"

    entrypoint:
      - "/init"

    hostname: "homeassistant"

    image: "linuxserver/homeassistant:latest"

    network_mode: "host"

    restart: "always"

    volumes:
      - "/volume1/docker/homeassistant:/config"
      - homeassistant-tailscale:/var/lib/tailscale

    working_dir: "/config"

  mosquitto:

    container_name: "mosquitto"

    command:
      - "/usr/sbin/mosquitto"
      - "-c"
      - "/mosquitto-no-auth.conf"

    entrypoint:
      - "/docker-entrypoint.sh"

    hostname: "mosquitto"

    image: "eclipse-mosquitto:2.0"

    network_mode: "bridge"

    ports:
      - "1883:1883/tcp"

    restart: "unless-stopped"

    volumes:
      - "/volume1/docker/mosquitto:/mosquitto"
      - mosquitto-log:/mosquitto/log
      - mosquitto-data:/mosquitto/data

  GivTCP:
  
    container_name: "GivTCP"
    
    image: britkat/giv_tcp-ma:latest
    ports:
      - "1884:1883"                   # MQTT
      - "6345:6345"                   # REST (add increments for each inverter)
      - "3000:3000"                   # This should match the WEB_DASH_PORT ENV below
      - "6379:6379"                   # Redis port for job queueing
      - "9181:9181"                   # RQ Dashboard to view job scheduling

    volumes:
      - "/volume1/docker/givtcp:/config"
      
    environment:
## Critical to update
      - NUMINVERTORS=1                # Set this to the number of Inverters in your setup, then replicate the next two lines for each inverter (changing the last number of the ENV)
      - INVERTOR_IP_1=192.168.1.30    # Set this to the IP address of your Inverter on your local network
      - INVERTOR_AIO_1=False          # Set this to true if you have an AIO
      - INVERTOR_AC_1=False           # Set this to true if you have an AC on old firmware and don't have the new registers
      - NUMBATTERIES_1=2              # Number of battery modules installed and connected to the above inverter
      - MQTT_OUTPUT=True              # "True" if you want to publish your data to MQTT, "False" otherwise
      - MQTT_ADDRESS=10.0.0.25        # IP address of an existing MQTT broker, or leave as "127.0.0.1" to use the internal broker
      - MQTT_USERNAME=                # Username of your existing broker, if needed. Not required for internal broker
      - MQTT_PASSWORD=                # Password of your existing broker, if needed. Not required for internal broker
      - HOSTIP=10.0.0.25              # External IP address of the docker host (needed for web dashboard)
      - CACHELOCATION=/config/GivTCP  # Location of cache data, this folder can be mapped to a persistence storage outside the container
      - TZ=Europe/London              # Set to your Timezone
## Optional
      - MQTT_TOPIC=GivTCP            # Root topic to publish data to for Inverter 1. If left blank it will default to GivEnergy/<invertor_serial_number>
#      - MQTT_TOPIC_2=                 # Root topic to publish data to for Inverter 2. If left blank it will default to GivEnergy/<invertor_serial_number>
#      - MQTT_TOPIC_3=                 # Root topic to publish data to for Inverter 3. If left blank it will default to GivEnergy/<invertor_serial_number>
      - MQTT_PORT=1883                # Port of your existing broker, leave as "1883" for internal broker
      - LOG_LEVEL=Info               # Level of logs to be reported: "Error", "Info" or "Debug"
      - PRINT_RAW=True                # If True this will publish all inverter data unprocessed as well as standard data
      - SELF_RUN=True                 # If True the container will self-run and connect and publish data. If "False" the you will need to trigger externally via REST
      - SELF_RUN_LOOP_TIMER=5         # Wait time between every read command to the inverter
      - QUEUE_RETRIES=5               # The number of calls to the inverter when trying to set a register. A higher number improves the chance of inverter writes succeeding
      - INFLUX_OUTPUT=False           # "True" if you want to publish your data to InfluxDB, "False" otherwise
#      - INFLUX_URL=                   # URL of an external Influx instance
#      - INFLUX_TOKEN=                 # Access Token for your Influx instance
#      - INFLUX_BUCKET=                # Data Bucket of your Influx instance you want data sent to
#      - INFLUX_ORG=                   # Influx instance Organisation
      - HA_AUTO_D=True                # If True (and if MQTT_OUTPUT is True) this will publish Home Assistant Auto Discovery messages to the broker
#      - HADEVICEPREFIX=GivTCP         # Defines the prefix for all entities in Home Assistant for inverter 1
#      - HADEVICEPREFIX_2=GivTCP2      # Defines the prefix for all entities in Home Assistant for inverter 2
#      - HADEVICEPREFIX_3=GivTCP3      # Defines the prefix for all entities in Home Assistant for inverter 3
      - PYTHONPATH=/app
      - DYNAMICTARIFF=True           # When set to true DAYRATESTART and NIGHTRATESTART times are ignored and tariff rates are changed by a dedicated entity/function
#      - DAYRATE=0.3022                 # Price in £/$ for your daytime electricity per kWh
#      - NIGHTRATE=0.1812               # Price in £/$ for your night time electricity per kWh
#      - EXPORTRATE=0.33               # Price in £/$ for your export electricity per kWh
#      - DAYRATESTART=05:00            # Time in HH:MM when your day time\expensive tariff kicks in
#      - NIGHTRATESTART=02:00          # Time in HH:MM when your night time\cheap tariff kicks in
      - WEB_DASH=False                # Enable the web dashboard
      - WEB_DASH_PORT=3000            # Port to serve the web dashboard on. Should be the same as the private port (above), not the container port
#      - SMARTTARGET=False             # Enables the PALM capability, requires the three ENV below to be set
#      - GEAPI=                        # API Key for the GivEnergy Cloud
#      - SOLCASTAPI=                   # API key for Solcast
#      - SOLCASTSITEID=                # SiteID for Solcast site (first array)
#      - SOLCASTSITEID2=               # SiteID for Solcast site (second array)
      - DATASMOOTHER=medium           # Set the data smoothing to most aggressive setting (High, medium, low, none)
#      - PALM_WINTER=01,02,03,10,11,12 # Comma delimited list of the winter months (01=January, etc)
#      - PALM_SHOULDER=04,05,09        # Comma delimited list of months in which consumption can vary so SOC calculation should be more cautious
#      - PALM_MIN_SOC_TARGET=25        # Lower limit for state of charge (summertime)
#      - PALM_MAX_SOC_TARGET=45        # Lower limit for SoC limit in shoulder months
#      - PALM_BATT_RESERVE=4           # Battery reserve for power cuts (minimum of 4%)
#      - PALM_BATT_UTILISATION=0.85    # Usable proportion of battery (100% less reserve and any charge limit) on a scale of 0-1
#      - PALM_WEIGHT=35                # Weighting used for final target soc
#      - LOAD_HIST_WEIGHT=1            # Load History Weighting
    restart: always
    privileged: true

  zigbee2mqtt:

    command:
      - "/sbin/tini"
      - "--"
      - "node"
      - "index.js"

    container_name: "zigbee2mqtt"

    devices:
      - "/dev/ttyUSB0:/dev/ttyACM0"

    entrypoint:
      - "docker-entrypoint.sh"

    environment:
      - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
      - "NODE_ENV=production"
      - "TZ=Europe/London"

    hostname: "zigbee2mqtt"

    image: "koenkk/zigbee2mqtt:latest"

    network_mode: "bridge"

    ports:
      - "8020:8020/tcp"

    restart: "unless-stopped"

    security_opt:
      - "label=disable"

    volumes:
      - "/run/udev:/run/udev:ro"
      - "/volume1/docker/zigbee2mqtt:/app/data"

    working_dir: "/app"

  appdaemon:

    container_name: "appdaemon"

    entrypoint:
      - "./dockerStart.sh"

    environment:
      - "HA_URL=http://127.0.0.1:8123"
      - "TOKEN=***"

    hostname: "appdaemon"

    image: "acockburn/appdaemon:latest"

    network_mode: "host"

    ports:
      - "5050:5050/tcp"

    restart: "unless-stopped"

    volumes:
      - "/volume1/docker/homeassistant/appdaemon:/conf"
      - "/etc/localtime:/etc/localtime:ro"
      - appdaemon-certs:/certs

volumes:
  mosquitto-log:
  mosquitto-data:
  appdaemon-certs:

version: "3.9"
#11 PianSom

Since we now all seem to be sharing best practise ideas ... 🙂

For Docker users, I highly recommend Dozzle - excellent tool for log checking