Skip to content

MQTT configuration

Gunnar Skjold edited this page Apr 20, 2024 · 27 revisions

This firmware is using 256dpi/arduino-mqtt which is currently implementing MQTT 3.1.1.

Configuration options

  • SSL - Tick this if your MQTT server is secured by SSL. Buttons to upload CA, Certificate and Private key will appear
  • Server - Hostname or IP for MQTT server. If you are using MQTT SSL, this needs to be the hostname reported by the SSL certificate
  • Port - Port for MQTT, normally 1883 for plain and 8883 for SSL
  • Username - If authentication is enabled on your MQTT server
  • Password - If authentication is enabled on your MQTT server
  • Client ID - A alphanumeric identitifier for your device. This needs to be unique between all clients connect to the MQTT server
  • Payload - How to output the data, valid choices are:
    • Raw (full) - Raw values sent to separate topics, see list of all topic further down
    • Raw (minimal) - Same as full, but only send value if it has changed
    • Domoticz - Specialized format used by Domoticz home automation, additional configuration is required
    • Home Assistant - Uses custom defined JSON data, but also sends information about sensors to HA for autodiscovery
    • JSON (classic) - A JSON containing all data from the meter
    • JSON (multi topic) - Same as classic, but where the different payloads are sent to separate topics
    • JSON (flat) - Same as classic, but where all the values exists on a single JSON level
    • HEX dump - Dumps the raw HEX formatted data as received from the meter
  • Publish topic - The topic we will publish data to
    • Required field, no data will be sent if this is blank
    • If Raw payload is used, this is the root topic for all values
    • In case of Home Assistant payload, this still needs to be set, but DO NOT use "homeassistant" as value
    • If you have multiple AMS readers sending to the same MQTT broker, the publish topic should be unique

All SSL files should be uploaded in DER format, usually .pem or .crt file extension. All the files need to be uploaded for SSL to work.

  • CA - The CA that your certificate and private key was signed with
  • Certificate - The client certificate file
  • Private key - The client private key file

WARNING ESP8266 may not have enough memory to perform MQTT with SSL. If you configure SSL and it does not work, a emergency factory reset will be necessary (or re-flash)

JSON mode

Sends all data on single topic in classic mode, or separate topics in multi topic mode. Depending on your meters data output, you can receive one or more of the following:

  • List 1 - Usually every 2.5s (Norway)
  • List 2 - Usually every 10s (Norway)
  • List 3 - Usually every hour (Norway)
  • List 4 - Most likely every 10s (Denmark)
  • System - Every 10s
  • Prices - On top of the hour when price of current hour changes, only if price API is enabled

Topics in raw mode

  • {publish topic}/id - MAC address (retain flag)
  • {publish topic}/uptime - Device uptime in seconds
  • {publish topic}/vcc - ESP Vcc in volts
  • {publish topic}/rssi - ESP WiFi RSSI
  • {publish topic}/temperature - Average temperature
  • {publish topic}/temperature/{address} - If you have multiple digital temperature sensors
  • {publish topic}/meter/id (retain flag)
  • {publish topic}/meter/type (retain flag)
  • {publish topic}/meter/clock
  • {publish topic}/meter/powerfactor
  • {publish topic}/meter/import/reactive/accumulated (retain flag)
  • {publish topic}/meter/import/active/accumulated (retain flag)
  • {publish topic}/meter/export/reactive/accumulated (retain flag)
  • {publish topic}/meter/export/active/accumulated (retain flag)
  • {publish topic}/meter/l1/current
  • {publish topic}/meter/l1/voltage
  • {publish topic}/meter/l1/powerfactor
  • {publish topic}/meter/l2/current
  • {publish topic}/meter/l2/voltage
  • {publish topic}/meter/l2/powerfactor
  • {publish topic}/meter/l3/current
  • {publish topic}/meter/l3/voltage
  • {publish topic}/meter/l3/powerfactor
  • {publish topic}/meter/export/reactive
  • {publish topic}/meter/export/active
  • {publish topic}/meter/import/reactive
  • {publish topic}/meter/import/active
  • {publish topic}/realtime/import/hour
  • {publish topic}/realtime/import/day
  • {publish topic}/realtime/import/peak/[1-5] (retain flag)
  • {publish topic}/realtime/import/threshold (retain flag)
  • {publish topic}/realtime/import/monthmax (retain flag)
  • {publish topic}/realtime/export/hour
  • {publish topic}/realtime/export/day

If ENTSO-E API is enabled, price data is also published. Only when price for current hour is changed on top of the hour:

  • {publish topic}/price/[0-34] - Price for current hour (0) and every known hour from now (1-34) (retain flag)
  • {publish topic}/price/min - The minimum known price within the next 24 hours (retain flag)
  • {publish topic}/price/max - The maximum known price within the next 24 hours (retain flag)
  • {publish topic}/price/cheapest/1hr - Timestamp when the cheapest 1hr period starts within the next 24 hours (retain flag)
  • {publish topic}/price/cheapest/3hr - Timestamp when the cheapest 3hr period starts within the next 24 hours (retain flag)
  • {publish topic}/price/cheapest/6hr - Timestamp when the cheapest 6hr period starts within the next 24 hours (retain flag)

Domoticz

Requires that a Domoticz MQTT-message-broker is setup. HOWTO: https://www.domoticz.com/wiki/MQTT.

Domoticz MQTT payloads will be published to MQTT topic "domoticz/in". The Domoticz MQTT client must therefor be configured to use "domoticz/in as "Topic In Prefix". See https://www.domoticz.com/wiki/MQTT.

The following virtual sensors can currently be used (see: https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's):

  • Electric (Instant+Counter) Note: Relies on Total energy import "tPI", will not start updating until value is read (once an hour)
  • Ampere (3 Phase)
  • Voltage (One per phase)

Create the sensors in Domoticz under Hardware > Dummy > Create virtual sensors, and use the IDX assigned to the sensor as input to the configuration here.

Home-Assistant

Enables Home-Assistant auto discovery, data is published as JSON that is tailored for the auto discovery configuration.

NOTE Auto discovery data is published to topic "homeassistant/sensor", DO NOT use this topic as Publish topic, please choose another topic (ex amsreader)

Configuration options:

  • Discovery topic prefix - Option to replace "homeassistant" with your own topic (publish sensors to yourtopic/sensor/ instead of homeassistant/sensor)
  • Hostname for URL - In case http://myhostname.local/ does not work for you, a custom hostname or IP can be configured here
  • Name tag - Appends a name tag at end of device name ("AMS reader (My name)") and in front of sensors ("[My name] sensor name")

Please note:

  • Some sensors may be zero if there is no data available
  • Not all meters report all of these values
  • All price and cost related values are only available if price API if configured and enabled in General configuration

Here is a list of available sensors.

  • Status - WiFi RSSI
  • Supply volt - The voltage of the devices power source
  • Temperature - The average temperature of all attached temperature sensors
  • Active import
  • L1 active import
  • L2 active import
  • L3 active import
  • Reactive import
  • Active export
  • L1 active export
  • L2 active export
  • L3 active export
  • Reactive export
  • L1 current
  • L2 current
  • L3 current
  • L1 voltage
  • L2 voltage
  • L3 voltage
  • Accumulated active import
  • Accumulated active export
  • Accumulated reactive import
  • Accumulated reactive export
  • Power factor
  • L1 power factor
  • L2 power factor
  • L3 power factor
  • Price (up to 36 sensors from current hour and into the future)
  • Minimum price ahead
  • Maximum price ahead
  • Cheapest 1hr period ahead
  • Cheapest 3hr period ahead
  • Cheapest 6hr period ahead
  • Month max - Peak maximum this month, based on your configuration in Threshold configuration
  • Tariff threshold - Current threshold based on the month max and your configuration in Threshold configuration
  • Current hour used - How many kWh used this hour
  • Current hour cost - How much did the kWh used this hour cost
  • Current hour produced - How many kWh was exported (If you have production)
  • Current hour income - How much income for produced kWh (If you have production)
  • Current day used
  • Current day cost
  • Current day produced
  • Current day income
  • Current month used
  • Current month cost
  • Current month produced
  • Current month income
  • Current month peak (1 through 5, depends on how many are configured on tariff settings)