Parse Command Line Sensor that returns Json

I’ve searched searched the community for hours trying to find a solution to my issue.

Issue is I have a command line sensor…

senor:
  - platform: command_line
    command: 'cat json_data.json'
{% set key = '[email protected]' %}
{% set json = states('sensor.command_sensor') %}

{{ json }}


Result type: dict
{
  "[email protected]": {
    "id": "1234",
    "sms": "1112223333"
  },
  "[email protected]": {
    "id": "2222",
    "sms": "1112223333"
  }
}

When I do {{ json[key] }} it returns an empty string???

If I copy and paste the json from the file into the template editor… it works.

My goal is to parse it in an automation with a key passed as an input_text (ie: [email protected])

Would someone mind pointing me in the right direction, please?

Tyr this:

sensor:
  - platform: command_line
    command: 'cat json_data.json'
    value_template: >
      {% set key = '[email protected]' %}
      {{ value_json[key] }}

I tried that too. Didn’t think about adding it to the post. It returns ‘unknown’.

So, I’ve been thinking about alternative ways to do this, while also having some additional functionality that I want.

My newest thought (attempt) is to use the shell_command, which calls a python script to CRUD the file. The script would return the status of the script after finishing.

I added the below to configuration.yaml…

system_log:
  fire_event: true

logger:
  default: warning
  logs:
    homeassistant.components.shell_command: debug

Output from the python script is showing in the log.

Problem now is the fire_event only works with WARNING or CRITICAL entries. :upside_down_face: Glanced over that part at first.

Is it possible to add DEBUG entries to trigger an fire_event?

Maybe there is a better solution that I’m not thinking of?