Hello, I’m trying to get home assistant sensors working from an API for solar panel optimisers. I’m running on a Raspberry Pi 4B and have tried using a bash script and a command line sensor (as in REST sensor and comma delimited data - #7 by mehstg), but I get an error where the sensor won’t show up in developer tools > states:
2024-02-23 14:53:03.938 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up command_line platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 344, in _async_setup_platform
await asyncio.shield(task)
File "/usr/src/homeassistant/homeassistant/components/command_line/sensor.py", line 66, in async_setup_platform
name: str = sensor_config[CONF_NAME]
~~~~~~~~~~~~~^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable
which is apparently a Python error and from what I can gather, the syntax has now changed since that post?
The bash script, which works perfectly when executed manually in terminal:
#!/bin/bash
curl --location --request GET "https://api2.tigoenergy.com/api/v3/data/aggregate?system_id=<redacted>&start=$(date +"%Y-%m-%dT00:00:01")&end=$(date +"%Y-%m-%dT%H:%M:%S")&level=min&header=key" --header "Authorization: Bearer <REDACTED>" --silent | tail -1 | cut -d',' -f2-
That curl command returns a list of my 19 panel wattages, for example “8,4,8,4,8,4,8,8,7,7,9,9,9,9,7,7,9,9,9”. If there isn’t sufficient sunlight, some or all may return as blank (for example “8,4,8,4,8,7,7,7,7,9,9”) and I don’t know if that’s hurting my ability to get the sensors working?
My configuration.yaml:
# Pull in granular panel wattage from Tigo API
sensor:
- platform: command_line
command: "bash /homeassistant/tigo/powerPerPanelMin.sh"
name: "Solar Panels"
scan_interval: 120
I also tried instead of referring to the bash script, actually putting the curl command in the command line sensor, but apparently there’s an issue with how the date format is formatted and this is affecting the parsing of the command. I tried messing with this, but it prevents the Tigo API from returning correct data:.
sensor:
- platform: command_line
name: "Solar Panels"
command: >-
bash -c "curl --location --request GET "https://api2.tigoenergy.com/api/v3/data/aggregate?system_id=<redacted>&start=$(date +"%Y-%m-%dT00:00:01")&end=$(date +"%Y-%m-%dT%H:%M:%S")&level=min&header=key" --header "Authorization: Bearer <redacted>" --silent | tail -1 | cut -d',' -f2-"
scan_interval: 120
So I tried to setup a REST sensor, but the API is returning so much data that it exceeds the maximum length for a state, but I’m not knowledgable enough to fix it. I tried to add a template to just get the last minute of data, but again failed.
sensor:
- platform: rest
name: Solar Panels
resource_template: >
https://api2.tigoenergy.com/api/v3/data/aggregate?system_id=<redacted>&start={{ now().strftime('%Y-%m-%dT00:00:01') }}&end={{ now().strftime('%Y-%m-%dT%H:%M:%S') }}&level=min&header=key
method: GET
headers:
Authorization: "Bearer <redacted>"
value_template: "{{ value.split(',')[1:] | join(',') }}"
scan_interval: 60
I’ve tried using chatGPT over the last couple of days, but I don’t think it’s helping a lot, haha.
Apologies for the long post, but I feel like I’m really close to getting it sorted.
Thanks very much for anyones help,
Matthew.