From 53c3ff3fdc80cd3bc52c3719f01110c0d20f327e Mon Sep 17 00:00:00 2001 From: Felix Fischer Date: Thu, 2 Feb 2017 09:25:08 +0100 Subject: [PATCH] explain value extraction via template (#1891) * explain value extraction via template Getting values from a JSON variable via `state_format` did not work for me, but using `value_template` worked. I added some explanation on how to use it. * wrap template with {% raw %}...{% endraw %} --- source/_components/mqtt.markdown | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/_components/mqtt.markdown b/source/_components/mqtt.markdown index e829e5da5fb..1a0e649b816 100644 --- a/source/_components/mqtt.markdown +++ b/source/_components/mqtt.markdown @@ -279,6 +279,13 @@ switch: platform: mqtt state_format: 'json:somekey[0].value' ``` +It is also possible to extract JSON values by using a value template: + +```yaml +switch: + platform: mqtt + value_template: '{% raw %}{{ value_json.somekey[0].value }}{% endraw %}' +``` More information about the full JSONPath syntax can be found [here][JSONPath syntax].