Integration method for particle.io?

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”