Integration method for particle.io?

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

I’m going to try to write a 3rd party Add-in for Patriot (https://github.com/rlisle/Patriot). This should simplify adding Photon DIY devices to Home Assistant. I’m just starting on this, so I’m very much on the steep part of the learning curve. Does anyone have any suggestions for how to get ramped up quickly on creating Add-Ins?

Just wanted to update this thread as it is the first one that comes up on Google when you search for photon and home assistant integration:

I ended up using a webhook integration between particle.io and Home Assistant and it was perfect (and simple!!).

I used an HTTP Sensor as the end point!

3 Likes

It would be great if you could elaborate on this a bit, perhaps with an example?

First of all you need to have your Home Assistant available from the Internet. (I wont elaborate on this as there are plenty of docs on the subject)

Next you need to create a long-lived access token in your Home Assistant user profile, click on your user at the very top left of your HA ui (yourhomeassistant.url/profile)

After that in your particle.io console go to the integrations page, and create a new Webhook:

Event Name: The name of the particle.io event you want to send to HA
Full URL: https://yourhomeassistant.url/api/states/sensor.nameofthesensorthatwillbecreated
Request Type: POST
Request Format: JSON
Device: pick the particle.io device that is sending that event
JSON:
{
“state”: “{{PARTICLE_EVENT_VALUE}}”,
“attributes”: {
“friendly_name”: “Friendly name of the sensor created in HA”
}
}

Headers:
{
“Content-Type”: “application/json”,
“Accept”: “application/json”,
“Authorization”: “Bearer INSERTTHELONGLIVEDTOKENYOUCREATEDEARLIER”
}

Enforce SSL: Yes

That’s it, you create one integration per metric you want to have from your particle sensor and you get a sensor in HA for each of them!

1 Like

Update: My particle.io Photons are all running my Patriot code which supports MQTT now. So it was very easy to use the HA MQTT component to send messages to the Photons. Currently all my Photons are only performing control actions (lights, curtains, fans) so that makes it easier. All my inputs are coming in from Smartthings sensors, so I had been using the smartthings-mqtt-bridge, but with the newer HA code I don’t need that. I’ve been away from HA for awhile, and it’s really great to see how far its come.

Here is the configuration that allowed me to call two functions in a Particle Photon.
First function does not have parameters and the second has.

rest_command:
  gongreset:
    url: https://api.particle.io/v1/devices/3XXXXXXXXXXX031/gongreset
    method: POST
    headers:
      authorization: Bearer e1792367e5XXXXXXXXXXXXXXXXXXXa82f
      accept: 'application/json, text/html'
      user-agent: 'Mozilla/5.0 {{ useragent }}'
    payload: ''
    content_type:  'application/x-www-form-urlencoded'
    verify_ssl: true
  gongto:
    url: https://api.particle.io/v1/devices/310032XXXXXXXXXX31/gongto
    method: POST
    headers:
      authorization: Bearer e179XXXXXXXXXXXXXXXXXXa82fasd
      accept: 'application/json, text/html'
      user-agent: 'Mozilla/5.0 {{ useragent }}'
    payload: 'arg={{val}}'
    content_type:  'application/x-www-form-urlencoded'
    verify_ssl: true

And then I was able to go to Developer Tools > Services and Call

  • First function does not have parameters:
rest_command.gongreset
  • Second function call and passing parameters:
rest_command.gongto

And the parameters:

Service Data: {  "val":13}

Same command via curl (to test things)

curl https://api.particle.io/v1/devices/310XXXXXXXXXXX031/gongto \
       -d arg="125" \
       -d access_token=e179XXXXXXXXXXXXXXXXXXa82fasd
1 Like

So i spent roughly 6 hours trying to get this working for my garden sprinklers that are controlled using a Partcile.io shield.

This is the combination that finally worked for me.

rest_command:
  sprinkler1_on:
    url: https://api.particle.io/v1/devices/REDACTED/relayOn
    method: POST
    headers:
      authorization: Bearer REDACTED
    payload: 'arg=2'
    content_type: 'application/x-www-form-urlencoded'
    verify_ssl: true

replace REDACTED with the ID of your node, and your token after the word “Bearer”