Integration - MQTT

Introduction

SolarAssistant provides an MQTT based API. MQTT is used by technical users to integrate and extend the functionality of SolarAssistant into their projects. It provides access to SolarAssistant monitoring data and inverter settings changes can also be performed.

Enable MQTT output

Navigate to the "Configuration" tab and start MQTT:

Enable MQTT output in SolarAssistant

Determine SolarAssistant local network IP

Also on the "Configuration" tab, determine what it's wlan0 (WiFi) or eth0 (LAN) IP is.

Finding your SolarAssistant local IP

The IP is allocated by your network router and can usually be configured to be static in your router configuration. If your router supports mDNS then SolarAssistant will register the hostname below:

solar-assistant.local

Connect to MQTT

We suggest using MQTT explorer or mosquitto_sub to read MQTT messages. In the example below, we use the mosquitto_sub:

mosquitto_sub -h 10.0.0.100 -p 1883 -v -t '#'

The result will be a continous stream of MQTT messages. To exit, press ctrl-c.

Running log of SolarAssistant MQTT messages

MQTT Bridge

If you already have an MQTT broker where you would like to consume SolarAssistant messages then you need to set up an MQTT bridge. Using a bridge is considered best practice for reliability and latency as message delivery, network disconnects, etc. is handled by the MQTT brokers. For Home Assistant users please see our Home Assistant broker with bridge setup guide.

The example mosquitto configuration file below is used in your existing MQTT broker to pull messages from SolarAssistant. Note:

  • address should be the IP address of your SolarAssistant device instead of 10.0.0.100.
  • remote_username and remote_password should be uncommented if you configured MQTT authentication in SolarAssistant.
  • topic in is to pull all messages from SolarAssistant
  • topic out is to push solar setting change messages from your existing broker to SolarAsssistant.

/etc/mosquitto/conf.d/solar-assistant.conf

connection SolarAssistant
#remote_username solar-assistant
#remote_password solar123
address 10.0.0.100
topic # in
topic solar_assistant/# out

Adjusting solar settings

See the example below for how to set the output source priority of an inverter via MQTT.

mosquitto_pub -h 10.0.0.100 -t 'solar_assistant/inverter_1/output_source_priority/set' -m 'Utility first'

SolarAssistant will post a response back on topic solar_assistant/set/response_message/state. You can view these messages with the command below:

mosquitto_sub -h 10.0.0.100 -v -t '#' | grep response_message

If you want to know which settings you can change via MQTT, please enable HomeAssistant discovery and then use the command below:

mosquitto_sub -h 10.0.0.100 -v -t '#' | grep command_topic

Adjusting solar settings - Examples with Voltronic inverter

Set charger source priority to solar and utility simultaneously:

mosquitto_pub -h 10.0.0.100 -t 'solar_assistant/inverter_1/charger_source_priority/set' -m 'Solar and utility simultaneously'

Set maximum AC charge current to 10A:

mosquitto_pub -h 10.0.0.100 -t 'solar_assistant/inverter_1/max_grid_charge_current/set' -m '10'

Set shutdown battery voltage 47V:

mosquitto_pub -h 10.0.0.100 -t 'solar_assistant/inverter_1/shutdown_battery_voltage/set' -m '47.0'

Adjusting solar settings - Examples with Deye inverter

Set the maximum AC charge current to 20A:

mosquitto_pub -h 10.0.0.100 -t 'solar_assistant/inverter_1/max_grid_charge_current/set' -m '20'

Set the work mode capacity point 1 to 15%:

mosquitto_pub -h 10.0.0.100 -t 'solar_assistant/inverter_1/capacity_point_1/set' -m '15'

Using MQTT values in scripts

An easy way to get an MQTT value in a bash script is to subscribe to a specific topic and exit after one message is received. In the example below we connect to localhost as the script runs on the SolarAssistant unit. See SSH access for more detail.

#!/bin/bash
LOAD_POWER=$(mosquitto_sub -h localhost -t 'solar_assistant/inverter_1/load_power' -C 1)
echo "Load power is: $LOAD_POWER"