Integration method for particle.io?

Hi all,

Very new to home assistant.

I have some devices that I control using a particle.io photon and spark. This is a device like arduino; however, it is WiFi capable and has a complementary rest service provided by particle.

What integration approach would you recommend? I will be using it mostly to dim lights - set lights to wake me up in the morning - turn fans on and off - water plants - check humidity and temperature.

Best,
Rob

Maybe MQTT?

Thanks, there is already a restful api available that I am hoping to use.

Are there some good examples of http post and get with HASS that I could try out? I’ve searched but may need some more detailed documentation.

Specifically I need to POST with arguments and an access token, but the syntax eludes me.

For the get, check Tutorial adding HUE Motion sensor (Lux,Temp and Motion)

Thanks, here’s an example of my post in python:

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)

I’m struggling to convert this to HASS format

Made a start on this, check out https://home-assistant.io/components/rest_command/
Not sure what the headers are for, but you could stick those in with the payload, which is just a string.

Thanks! Still trying to work out the Syntax for the payload. I have an access token as well as an argument (presented as a string of comma separated values. How would multiple parameters be passed in the payload? The rough stab below is probably not right, but aims to present what I’m trying to do. New to HA and what I assume is Jinja?

  - platform: rest
    resource: https://api.particle.io/v1/devices/1e0026001247343339383037/WARM_STRIP/
    method: POST
    name: Particle Devices
    payload: '{ "access_token: SECRET, args: "1,100,30"" }'

For examples, have you checked https://home-assistant.io/cookbook/#example-configurationyaml ?

Thanks, I searched through all of the git repositories and only found one example of a post to a restful api, which looks a lot different from the documentation provided.

    - platform: rest
  scan_interval: 3600
  resource: !secret gas_buddy_resource
  method: POST
  name: Gas Price
  value_template: '{{value_json.trend.Today}}'
  unit_of_measurement: '$'
1 Like

Re the MQTT approach checkout https://community.particle.io/t/submission-mqtt-library-and-sample/2111/6

And https://www.hackster.io/anasdalintakam/mqtt-publish-subscribe-using-rpi-esp-and-photon-864fe9

Thanks, MQTT does seem to have much more documentation for home assistant. I’m still hoping that I can use my existing restful infrastructure and avoid complicating what I have going on. Seems that I’m really close, I just need a clue on how I should be passing 2 arguments (token + args) using the rest implementation.

Best,
Rob

Any progress? I am going down the MQTT route.
Currently reading temp/humidity with a DHT11 on my particle photon. Following this guide for ESP now, just not sure how to adapt PubSubClient client(espClient); for the Particle…

So - sort of. I was able to get a restful switch to hit the photon (and auth), but am unable to pass the arguments correctly.

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'}"

The switch above does send a post to the device, however, the arguments are not being passed correctly. the format is typically something like args=“1,100,10” where args are passed as a string.

I have also tried “args=1,100,10” and “1,100,10” without luck. In a cURL request the arguments are in quotes and passed as a string args=“1%2C0%2C10”’

Any idea for how the body on param could be passed so that it is interpreted as args=“1,100,10” ? Right now, it’s just passing args as a null value.

Try args :
body_on: {‘args’: ‘1’,‘100’,‘10’}
Or
body_on: {‘args’: 1, 100, 10}

I don’t think you need the surrounding double quotes.

Yeah… no dice… Tried every combination

body_on: ‘{“args”=“1,100,10”}’
body_on: ‘{args = “1,100,10”}’
body_on: ‘{“args”:“1,100,10”}’
body_on: ‘{args : “1,100,10”}’
body_on: ‘{“args=1,100,10”}’
body_on: ‘{“args”=“1”,“100”,“10”}’ (the 1,100,10 need to be passed as a single string).

Also tried reversing the double quotes and quotes. Without quotes around the brackets it does not compile.

Any error messages? Try with the postman chrome extention. That’s good at capturing errors

No errors and no problem using postman. I’m able to pass args (key) and “1,100,10” (value) as a key value pair parameter. I have no idea what the syntax is for key value pairs in HAss =/

Use this to validate that it’s valid JSON https://jsonformatter.curiousconcept.com
If the JSON is valid then somethings wrong with the device or the commands.

Well: {“args”: “1,100,10”} is valid JSON hrmm… Also tried ‘{“args”:“1,100,30”}’

After a few dead ends, I think I have the MQTT approach figured out, here posting sensor data… https://community.particle.io/t/ubidots-mqtt-crashing/30008/2

1 Like