Passing arguments to particle function (as JSON, using Home Assistant)

Hi All,

Working with home assistant right now and having a heck of a time passing arguments to a function.

In home assistant I have my switch set up as the following. Which does access the function but fails to pass the argument.

switch 2:
  - platform: rest
    name: 'Particle Devices'
    resource: https://api.particle.io/v1/devices/1e0026001247343339383037/WARM_STRIP/?access_token=SECRET
    method: POST
    body_on: "{'args':'1,100,10'}"

I have also tried things like:
’{“args”:"%221%2C100%2C10%22"}’
’{“args”:1,100,1}
’{args:“1,100,10”}’
’{“args”:“1,100,10”}’
“args=1,100,10”

I am able to get this to work in cURL, postman, and python (python example below):

import requests

url = "https://api.particle.io/v1/devices/1e0026001247343339383037/WARM_STRIP/"

payload = "access_token=SECRET&args=%221%2C0%2C10%22"
headers = {
    'content-type': "application/x-www-form-urlencoded",
    'cache-control': "no-cache",
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

Has anyone else tried to post to a particle using Home assistant? How about with JSON format for the arguments?

Hi All, giving this a little bump as I’m still totally stuck.

Little bumpy bump - just in case. Still totally stuck.

Maybe you didn't get any quicker response since your question does somehow create the feeling you didn't look too hard in the docs
https://docs.particle.io/reference/firmware/photon/#particle-function-

For a POST request you need to pass the access_token the same way as your args

But you seem to mix and match POST and GET parameter passing in here

How you would make Home Assistant create a proper POST request (as shown with the cURL sample) isn't actually in the scope of this forum (although others might still be able to help you out with that).

1 Like