Skip to content

Transformation data

Jeff Albrecht edited this page May 14, 2017 · 2 revisions

mqttwarn can transform an incoming message before passing it to a plugin service. On each message, mqttwarn attempts to decode the incoming payload from JSON. If this is possible, a dict with transformation data is made available to the service plugins as item.data.

This transformation data is initially set up with some built-in values, in addition to those decoded from the incoming JSON payload. The following built-in variables are defined in item.data:

{
  'topic'         : topic name
  'payload'       : topic payload
  '_dtepoch'      : epoch time                  # 1392628581
  '_dtiso'        : ISO date (UTC)              # 2014-02-17T10:38:43.910691Z
  '_ltiso'        : ISO date (local)            # datetime.now().isoformat() 
  '_dthhmm'       : timestamp HH:MM (local)     # 10:16
  '_dthhmmss'     : timestamp HH:MM:SS (local)  # 10:16:21
}

Any of these values can be used in format to create custom outgoing messages.

format = I'll have a {fruit} if it costs {price} at {_dthhmm}
Clone this wiki locally