home-assistant.io/source/_docs/mqtt/processing_json.markdown
Franck Nijhof 1833c32a2c Cleans up front matter (#9835)
* Sets front matter defaults

* Removes default front matter from section templates/pages

* Removes default front matter from addon pages

* Removes default front matter from integration pages

* Removes default front matter from posts

* Removes default front matter from docs pages

* Removes default front matter from other pages

* Fixes blog category pages
2019-07-11 14:35:08 -07:00

1.1 KiB

title description logo
Processing JSON Instructions on how to process the MQTT payload. mqtt.png

The MQTT switch and sensor platforms support processing JSON over MQTT messages and parsing them using JSONPath. JSONPath allows you to specify where in the JSON the value resides that you want to use. The following examples will always return the value 100.

JSONPath query JSON
somekey { 'somekey': 100 }
somekey[0] { 'somekey': [100] }
somekey[0].value { 'somekey': [ { value: 100 } ] }

To use this, add the following key to your configuration.yaml:

switch:
  platform: mqtt
  state_format: 'json:somekey[0].value'

It is also possible to extract JSON values by using a value template:

switch:
  platform: mqtt
  value_template: '{% raw %}{{ value_json.somekey[0].value }}{% endraw %}'

More information about the full JSONPath syntax can be found in their documentation.