the configuration segment below calls a python script to extract multiple values from a device and package them into a single json…is there a way to call the command: ‘/home/homeassistant/.homeassistant/rainwise.py’ once and extract all the values vs running the command multiple times?
i’ve tried this method: however the value_json.xxx gives and error
sensor:
- platform: command_line
name: getdata
command: "python3 /path/to/script/getdata.py"
- platform: template
sensors:
firstvalue:
value_template: "{% set list = states.sensor.getdata.state.split(':') %} {{ list[0] }}"
friendly_name: 'First'
secondvalue:
value_template: "{% set list = states.sensor.getdata.state.split(':') %} {{ list[1] }}"
friendly_name: 'Second'
--------------------------- configuration.yaml -------------
# Rainwise MK-III
- platform: command_line
name: Air Temperature
command: ‘/home/homeassistant/.homeassistant/rainwise.py’
value_template: ‘{{ value_json.air_temperature }}’
unit_of_measurement: “F”
- platform: command_line
name: Rainfall
command: ‘/home/homeassistant/.homeassistant/rainwise.py’
value_template: ‘{{ value_json.rainfall }}’
- platform: command_line
name: Relative Humidity
command: ‘/home/homeassistant/.homeassistant/rainwise.py’
value_template: ‘{{ value_json.relative_humidity }}’
- platform: command_line
name: Barometric Pressure
command: ‘/home/homeassistant/.homeassistant/rainwise.py’
value_template: ‘{{ value_json.barometric_pressure }}’
- platform: command_line
name: Wind
command: ‘/home/homeassistant/.homeassistant/rainwise.py’
value_template: ‘{{ value_json.wind }}’
- platform: command_line
name: Station Battery
command: ‘/home/homeassistant/.homeassistant/rainwise.py’
value_template: ‘{{ value_json.station_battery }}’