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,