Multiple command line sensors into one

Hi Community,

I have the following sensor that only provides me with a state of “unknown.” I want to consolidate 12 individual command line sensors into one sensor with all attributes. In this example, each individual sensor provides the correct value, but when I attempt to add them as attributes, they don’t show up as attributes, and the sensors remain in the “unknown” state. Why is this happening, and how can I fix the issue? I’ve discovered that running separate sensors is quite performance-intensive.

I have tried to see if anyone else is experiencing the same issue, but the solutions don’t seem to fit this specific example.

Looking forward hearing from you, Rasmus.

command_line:
  - sensor:
      name: Solutronic inverter
      command: "python3 /config/solutronic.py"
      scan_interval: 10
      json_attributes:
          - 'PAC'
          - 'PACL1'
          - 'PACL2'
          - 'PACL3'
          - 'UDC1'
          - 'UDC2'
          - 'UDC3'
          - 'IDC1'
      value_template: >
          {% if value == "unavailable" %}
          {{ 'off' }}
          {% else %}
          {{ 'on' }}
          {% endif %}

  - sensor:
      name: Solutronic Leistung AC
      command: "python3 /config/solutronic.py"
      unit_of_measurement: "V"
      device_class: voltage
      state_class: measurement
      icon: mdi:current-ac
      json_attributes: true
      value_template: "{{ value_json.PAC }}"
      scan_interval: 120

  - sensor:
      name: Solutronic Power L1
      command: "python3 /config/solutronic.py"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      icon: mdi:solar-panel
      json_attributes: true
      value_template: "{{ value_json.PACL1 }}"
      scan_interval: 30

  - sensor:
      name: Solutronic Power L2
      command: "python3 /config/solutronic.py"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      icon: mdi:solar-panel
      json_attributes: true
      value_template: "{{ value_json.PACL2 }}"
      scan_interval: 30

Hello @Rasser, have you found a solution to your problem? I’m in a similar use case as you!

Hi @Niv1900.
I have found a temporary solution in the Python script, which forwards all data points into a JSON string. I can then use them as attributes in my sensor like this:

command_line:
  - sensor:
      name: Solutronic
      command: "python3 /config/solutronic.py"
      unit_of_measurement: 'kWh'
      device_class: energy
      state_class: total_increasing
      icon: mdi:solar-power
      value_template: "{{ value_json.ET }}"
      scan_interval: 5
      json_attributes:
        - PACL1
        - PACL2
        - PACL3
        - PAC
        - UDC1
        - UDC2
        - UDC3
        - IDC1
        - IDC2
        - IDC3
        - EG
        - ETA
1 Like

Oh shoot I missed that! That looks extremely awesome! Thanks for the reply!