cURL sensor

I am trying to set up a cURL sensor.
I am attempting to bring in real-time power price information in Australia.
so far I have attempted a command line sensor but when I paste the working Curl into the command field, home assistant doesn’t like it.
(incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line at line 261, column 98:
… es/listprices \ -H ‘Content-Type: application/json’ \ -d '{ "p …
^).

I guess this is due to it being on multiple lines. It works perfectly in the Linux terminal.

excerpt from config.yaml:

  - platform: command_line
    name: Power Price
    command: curl -X POST \ https://api.amberelectric.com.au/prices/listprices \ -H 'Content-Type: application/json' \   -d '{ "postcode": "5555" }  '
    scan_interval: 30
    value_template: "{{ (data.staticPrices.E1.totalfixedKWHPrice + data.staticPrices.E1.lossFactor * data.variablePricesAndRenewables.[period].wholesaleKWHPrice) / 1.1 }}"

there is every chance the ‘value template’ is comedy too, first things first tho :open_mouth:

the original Curl is

curl -X POST
https://api.amberelectric.com.au/prices/listprices
-H ‘Content-Type: application/json’
-d '{ “postcode”: “5000” }

is a command-line sensor the correct vehicle for this data?
apologies I’m still pretty new to this.

1 Like

no idea if this will work but try, as a rest command… perhaps.

switch
   - platform: command_line
     name: Power Price
     resource: https://api.amberelectric.com.au/prices/listprices
     method: POST 
     headers: 
        'Content-Type: application/json'   
     payload: '{ "postcode": "5555" }' 
     scan_interval: 30
     value_template: "{{ (data.staticPrices.E1.totalfixedKWHPrice + data.staticPrices.E1.lossFactor * data.variablePricesAndRenewables.[period].wholesaleKWHPrice) / 1.1 }}"      

been playing quite a bit tonight trying lots of different layouts, got as far as

#Amber power price 
  - platform: command_line  
    command: 'curl -X POST \ https://api.amberelectric.com.au/prices/listprices \ -H "Content-Type: application/json" \ -d { "postcode": "5555" } '
    name: power_price
    unit_of_measurement: '$'
    json_attributes:
      - data.staticPrices.E1.totalfixedKWHPrice
      - data.staticPrices.E1.lossFactor
      - data.variablePricesAndRenewables.[period].wholesaleKWHPrice
    scan_interval: 20
    command_timeout: 30

i thought i’d try to just grab the values i need from the data and do the math in home assistant. not as clean but something i have a bit more of a clue how to do!
still can’t get the bugger working tho!

thanks for your switch code tho HasQT, it didn’t work but it gave me some great structure to work with. :slight_smile:

No probs, that was my intent, I didn’t think it would actually work.

I had tried playing round with your earlier curl to mimic your error, then moved onto the rest post style code.

1 Like

Price Surge!
Aussies getting paid over $10 a Kw for exported electricity! turn everything off, export like mad, Christmas bonus incoming!
I’ve got to get this automated, think Jon think… how hard can this be! :open_mouth:

Have you gotten to the point of getting a json response from the API yet?

have you looked at this yet? The last example in particular.

This link might be worth watchin too. Similar situation.

Thank you for your effort and input :slight_smile:
I will dig back into this eventually, Christmas is starting to get in the way!
Hopefully Santa will bring me some integration development skills :smiley:
enjoy the break everyone!

1 Like

Hi HasQT, hope you had a good break :slight_smile:
in answer to your question - there is no response in Home Assistant to the API.
I get a response if i bung the command into the linux terminal so i know it is correct.
I just need to find a way to bring the data into home assistant :open_mouth:
I checked out the restful sensor with no joy, I’ll have a crack at formatting the other link you sent.

1 Like

Do you use node red? You could try importing the data via nodered, then sending it to HA. If nothing else it might make debugging abit easier.

I’m not using node-red at the moment but i do need to take the dive. it looks pretty damn good for sure!
I’ve been given another route to try, all in imperative code rather than terminal commands.
not sure if this makes things harder or easier, it’s certainly another angle :open_mouth:

Hi John,
How are you going with the AMBER intergration? i have just been signed up with them, and i would also like to have live pricing shown on my hass.io.

If it is not to much to ask, could you though some pointers my way for getting it working? AMBER have sent me the API details etc.

Warm regards, Aiden

Hi Aiden,

It works :slight_smile: (no thanks to me tho :roll_eyes: )
The marvellous lewisbenge has built the integration for Amber.

Enjoy :slight_smile:

1 Like