Several sensor on same command_line

Hi,
I have a command_line sensor that gets value from a python script called pw3_temp.py. This script returns a json-formed value:
{“id”: 6513, “date”: “2019-02-10T17:00:00Z”, “source”: 1, …, “pw3_temp_in”: 220, “pw3_temp_out”: 228, “pw3_temp_delta”: 8}
I can get one value with this sensor configuration:

  • platform: command_line
    name: cl2
    command: “python3 /home/claude/.homeassistant/scripts/pw3_temp.py”
    value_template: ‘{{ value_json[“pw3_temp_in”]|multiply(0.1)|round(2)}}’

And then I try to get second value for another sensor from same command:

  • platform: template
    sensors:
    cl3:
    value_template: ‘{{ states.sensor.cl2.value_json[“pw3_temp_out”] }}’

But when I restart hass, it does not work, error is:
[homeassistant.components.sensor.template] Could not render template cl3: UndefinedError: ‘homeassistant.core.State object’ has no attribute ‘value_json’

I have tried several others thing:

  • If I put states.sensor.cl3.state for cl3, value is same as cl2
  • If I put *states.sensor.cl3.states for cl3, value is nothing
  • If I put no value_template to cl2, it claims that response is too long (more than 255), and nothing show up for cl3
  • value_template: “{{ state_attr(‘states.sensor.cl2’, ‘pw3_temp_out’) }}” for cl3 gives None as value

I really don’t understand syntax of templating.
Could anyone help me ?
Thanks,

Ok, I am going to reply to myself:
everything was fine with my configuration.yaml, except that I miss

  json_atributes:
    - pw3_temp_out

under command_line sensor definition
It seems that I don’t need it for “master” sensor (command_line sensor), but it is necessary for template sensors.

In the modern configuration, this works for me:

command_line:
  - sensor:
      unique_id: "temp_oben_json"
      command: "curl http://192.168.178.20/sensor/sensor1_getjs.php -s"
      name: "Temp oben json"
      unit_of_measurement: '°C'
      device_class: temperature
      value_template: '{{ value_json.temp }}'
      json_attributes:
        - temp
        - humi
        - vbat

template:
  - sensor:
      unique_id: "humi_oben_json"
      name: "Humi oben json"
      state: '{{ state_attr("sensor.temp_oben_json","humi") }}'
  - sensor:
      unique_id: "vbat_oben_json"
      name: "VBat oben json"
      state: '{{ state_attr("sensor.temp_oben_json","vbat") }}'

The json string is:

{ "temp":21.5, "humi":66.0, "vbat":4.85 }