Hi Guys,
Newbie to HA here, so please be patient.
I have tried to connect my api to my HA but I didn’t had any success. Followed and tried different examples here from previous posts but got nothing in HA.
I’m posting bellow what I have added to my files, so if anyone can help me I would really be very happy.
configuration.yaml
sensor:
- platform: command_line
name: electricity
unit_of_measurement: ‘kWh’
scan_interval: 600
command: ‘sh /config/electricity.sh’
electricity.sh
STARTDATE=date -d @$(( $(date +"%s") - 86400)) +"%Y-%m-%dT00:00:00"
ENDDATE=date -d @$(( $(date +"%s") - 86400)) +"%Y-%m-%dT23:59:59"
STARTDATEPREV=date -d @$(( $(date +"%s") - 172800)) +"%Y-%m-%dT00:00:00"
ENDDATEPREV=date -d @$(( $(date +"%s") - 172800)) +"%Y-%m-%dT23:59:59"
COUNT=curl -H "Authorization: Basic my_API" "https://api.octopus.energy/v1/electricity-meter-points/yyyyyyyyy/meters/xxxxxxx/consumption/?period_from=$STARTDATE&period_to=$ENDDATE" | python -mjson.tool | grep -c "consumption"
if [[ “$COUNT” == 48 ]]
then
curl -H “Authorization: Basic my_API” “https://api.octopus.energy/v1/electricity-meter-points/yyyyyyyyy/meters/xxxxxxx/consumption/?period_from=$STARTDATE&period_to=$ENDDATE” | jq ‘[… | objects | .consumption] | add’ | awk ‘{printf “%0.2f\n”,$1}’
else
curl -H “Authorization: Basic my_API” “https://api.octopus.energy/v1/electricity-meter-points/yyyyyyyyy/meters/xxxxxxx/consumption/?period_from=$STARTDATEPREV&period_to=$ENDDATEPREV” | jq ‘[… | objects | .consumption] | add’ | awk ‘{printf “%0.2f\n”,$1}’
fi---------------------------------------------------------------------------------------------
I have no idea what am I doing wrong.
EDIT:
Note: I have tested the api with my key on “Talend API tester” in Chrome and I can get all values, from the consumed energy and from the tariff.
Thanks in advance
R