BlackZork
(Łukasz Michalski)
September 7, 2019, 8:18pm
1
I have an automation:
- alias: mqtt_ha_start
trigger:
platform: homeassistant
event: start
action:
service: mqtt.publish
data:
topic: homeassistant/scenes/test_room/list
retain: true
payload_template: "{{ state_attr('input_select.test_room','options') }}"
I would like to generate json data in payload_template. Is there any way to do it?
You could try the tojson
filter.
payload_template: "{{ state_attr('input_select.test_room','options')|tojson }}"
BlackZork
(Łukasz Michalski)
September 7, 2019, 8:23pm
3
Unfortunately tojson is not available. Tried in template Developer Tools:
Error rendering template: UndefinedError: ‘tojson’ is undefined
Try again. It’s a filter, not a function. I just tried it and it works fine.
Mutt
(Muttley)
September 7, 2019, 9:13pm
5
I just tried Phil’s template and though I had to adjust it for an input_select that exists on my system it worked as advertised, generating : - “[“Day”, “Evening”, “Night”]”
BlackZork
(Łukasz Michalski)
September 8, 2019, 8:53pm
6
Yes, it worked. I tried it as a function before. Many thanks!
1 Like