Hello,
I’m struggling to work out how to create multiple sensors from the command line integration. I have successfully set up a command to run an API call to a server to return JSON values which works fine. This returns multiple values within one sensor if I specify json attributes.
However I would like to create a sensor in HA for each of these values, but can’t seem to get it to work. I can’t get the behaviour of templating within the command line integration to work as I would expect it to. I’m sure it’s very simple for someone with half a brain, but clearly not for me…
Here is the YAML for the sensor which returns all the JSON values within one sensor as multiple values. How could I adapt this please? Is there a way of doing it from the command line, or would it involve using REST ?
# OVMS for MG ZS EV
- platform: command_line
name: MG OVMS Estimated Time Until Full
unique_id: mg_ovms_est_time_full
scan_interval: 60
json_attributes:
- charge_etr_full
- soc
command: |-
username='xx'; password='xx'; vehicleid='xx'; ip='https://ovms.dexters-web.de:6869';\
c=$(curl -X GET -sc - "$ip/api/cookie?username=$username&password=$password" -o /dev/null);\
echo "${c}" | curl -X GET -sb - "$ip/api/vehicle/$vehicleid" -o /dev/null;\
echo "${c}" | curl -X GET -sb - "$ip/api/charge/$vehicleid"
value_template: >-
Estimated Time Until Full: {{ (value_json.charge_etr_full | float // 60) | round(0) }} hours and {{ (value_json.charge_etr_full | float % 60) | round(0) }} minutes
SoC: {{ (value_json.soc }}