Hi all,
After spending hours trying to get this working, I have caved in and decided to ask the experts! I’ve tried searching, but nothing I have found works, and so I am not sure if it is me, or just not possible.
I have a command line sensor, which runs a Python script, and returns a JSON payload.
I want to then template that JSON payload out into two new sensors.
JSON payload is:
{"A": "Connected", "B": "Not Connected"}
In the template sensor, I use:
value_template: '{{ value_json.A }}'
I’ve tried upper case, lower case, .a.value, .[“A”] etc etc (all from various searches on here).
I always get “unknown” for sensor.box_a_status:
but I see the JSON listed correctly under sensor.device_status, so I know the python is working well.
And in the error log, I get:
Could not render template Box A Status: UndefinedError: 'value_json' is undefined
12:32 PM components/template/sensor.py (ERROR)
Could not render template Box B Status: UndefinedError: 'value_json' is undefined
12:32 PM components/template/sensor.py (ERROR)
I’m starting to think value_json is not supported for the template sensor, but it suggests it is, in the docs (unless I am reading it completely wrong).
Any help would be appreciated.
- platform: command_line
name: Device Status
command: 'ssh pi@xxxxxxxxxxxx blah blah"'
- platform: template
sensors:
box_a_status:
friendly_name: Box A Status
entity_id: sensor.device_status
value_template: '{{ value_json.A }}'