Command line JSON to sensor

Hi,
so I’m trying to add several sensors that I’m pulling out with a command.

so far I’m trying to add a sensor in the configuration.yaml file like this:

sensor:
  - platform: command_line
    command: "ssh [email protected] 'python /root/bacnet.py'"
    scan_interval: 300
    name: regulux

Here’s my result from the command:

{
    "a001allgemein_f01uberspannungsschutz": {
        "id": "Lamp_16845036",
        "name": "F01 u\u0308berspannungsschutz",
        "type": "O",
        "unit": "",
        "value": "2"
    },
    "a001allgemein_intiwgemessenetaupunktt": {
        "id": "16845098",
        "name": "INT IW gemessene Taupunkt T\u00b0",
        "type": "P",
        "unit": "\u00b0C",
        "value": "28.5"
    },
    "a001allgemein_quittierenaktiv": {
        "id": "Lamp_16844948",
        "name": "Quittieren aktiv",
        "type": "O",
        "unit": "",
        "value": "0"
    },
    "hk01nord_west_wand_b01iwvorlauft": {
        "id": "16846027",
        "name": "B01 IW Vorlauf T\u00b0",
        "type": "P",
        "unit": "\u00b0C",
        "value": "22.2"
    }
}

Is there a way to add all those sensors at once without having to add them one by one?

thanks for any help
Lars

You can add them all at once as attributes using json_attributes.

But for individual sensors you have to define each one.

Here’s my suggestion which relies on the use of MQTT:

You have control of bacnet.py so modify its python code so that when it runs it publishes JSON sensor data as messages to four MQTT topics, one topic per sensor. For example, publish this message:

{
  "id": "Lamp_16844948",
  "name": "Quittieren aktiv",
  "type": "O",
  "unit": "",
  "value": "0"
}

to this topic:

sensor/quittierenaktiv

Use cron to schedule bacnet.py to run every 300 seconds.

In Home Assistant, define four MQTT Sensors, each subscribed to its specific MQTT topic. For example:

  - platform: mqtt
    name: quittierenaktiv
    state_topic: sensor/quittierenaktiv
    value_template: "{{value_json['value']}}"