Trouble with CURL command in sensor

Im trying to set up a sensor to check on my heat pump using a curl command.

I have the following code example from the heat pump API:

Blockquote

curl --location 'https://platform.loggamera.se/Api/v1/HeatPump' \
--header 'Content-Type: application/json' \
--data '{
  "ApiKey":"2077D07CEA8C2F98370084D4C8A1435D",
  "DeviceId":9446,
  "DateTimeUtc":"2019-02-26T10:48:00Z"
}'

And have adapted it into my configuration.yaml like this (I’ve removed the API-key and deviceID):
For now I’m only trying to look at the name of the pump

Blockquote

command_line:
  - sensor:
      command: curl --location 'https://platform.loggamera.se/Api/v1/HeatPump' \  --header 'Content-Type:application/json' \  --data '{"ApiKey":"XXXXXXXXXXXXXXXXXX","DeviceId":XXXX}'
      scan_interval: 15
      name: pump_type
      value_template: >
       {{ value | regex_findall('"PumpType":"([a-zA-Z0-9 ]+)"') | first | default(none) }}

Im not getting any errors but the state is only returned as unknown? What am I doing wrong here?
I’ve tested the curl-command outside HA and I’m able to get info back so the key and deviceID are correct.
Any help greatly appreciated! :slight_smile:

That won’t work

image

What is api returning? Looks like json, so you won’t need regexp either

Ok! Tried removing the slashes but still nog go. This is the documentation for the API: https://documenter.getpostman.com/view/6665372/S11HtyXG

Response should be like this:

{
“Data”: {
“LogDateTimeUtc”: “2019-02-26T10:48:00Z”,
“PumpType”: “NibeF”,
“IndoorTemperature”: null,
“SetIndoorTemp”: 22,
“HotwaterTemp”: 47.3,
“HotWaterExtraEnabled”: false,
“SetReducedModeEnabled”: true,
“OutdoorTemp”: -8.3,
“PoolTemp”: null,
“Activity”: “OTHER”,
“FilterAlarmActive”: false,
“HeatCarrierIn”: 34.2,
“HeatCarrierOut”: 35.9,
“BrineIn”: 4.7,
“BrineOut”: -1.2,
“AlarmActive”: true,
“SetHolidayReductionDays”: null,
“AlarmInClearText”: “Filter alarm (code 22)”,
“SetFanState”: High
},
“Error”: null
}

If the curl command is working, you’ll get the value with

value_template: "{{ value_json.Data.PumpType }}"

The regexp won’t work as-is as there is a blank between the colon and the value

1 Like

Just FYI, the slashes in the documentation were there because the command was continued on the next line. That is why you don’t want them as you are doing a single line command.

As stated, output the json so you know what is really coming back to you. That might be over 255 characters. So, just output the first 250 so you don’t get an error. Then you can start working on parsing it.

1 Like

Thanks, that did it. I suspected it was something to do with the regex. I dont have a great grasp on how to use it :sweat_smile:

@jeffcrum Thanks for the explanation! I’ve run into that limit before, how would I go about limiting the output to 250 characters? For future troubleshooting that is :slight_smile:

Subscript it

[:250]

A string variable is one character per occurrence.