jdetmold
(Jeff)
March 18, 2016, 2:57am
1
This is my first DTH and my first thing made for ST.
I’ll start by saying I am not a programer so the code I’m sure is rough.
I would like to figure out how to get the particle cloud to “push” data to ST but so far I cant even figure out how to create (or at least find the url) of a rest endpoint in a ST DTH, so for now I just have ST delaying then automatically refreshing the device instead of waiting for an update to be “pushed” from the device.
I used a power supply from an external hd to provide 5v to the Particle Photon and 12v to the valve
The ST code:
/**
* wifi-water-valve
*
* Copyright 2016 Jeff Detmold
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
preferences {
input("deviceId", "text", title: "Device ID")
input("token", "text", title: "Access Token")
}
This file has been truncated. show original
The Particle code:
/* A Spark function to parse the commands */
int ValveControl(String command);
// We name OpenValve & CloseValve pins
int OpenValve = D2;
int CloseValve = D3;
int ValveInputOpen = D4;
int ValveInputClosed = D5;
int ValveStateClosed = 0;
int ValveStateOpen = 0;
int ValveCurrentState = 3;
// This routine runs only once upon reset
void setup()
{
//Register Spark function
Particle.function("ValveAction", ValveControl);
Particle.variable("ValveState", ValveCurrentState);
This file has been truncated. show original
now I just have to seal it all up in a project box and install it.
jjhtpc
(Justin Wurth)
March 18, 2016, 5:51pm
2
I figured out how to have two way communication with particle using variables and get statements. You can take a look here
Hello,
So I worked on this pretty extensively over the last week. I took my code back to the original code because I felt it stayed closer to what I wanted. Feel free to modify to your hearts content as axyr did above.
The main bonus of this code is two way communication. I figured out the particle API commands for an httpGet to grab a variable set on particle.
So head on over to github and get the original branch:
@a6pack @keithcroshaw @hawesg @Pete
I know this was something you will be looking for.
The main advantage of this is that now polling and refresh will show status if an outside smart app opens the blinds or if the slider is used… (which is working again)!
Enjoy!
Justin
Oh and on a side note I think this opens the possibility of having a general Spark device type …
You could set up a polling app to refresh every so many minutes.
jdetmold
(Jeff)
March 18, 2016, 6:20pm
3
this DTH has two way communication working (opens and closes the valve & gets current valve state) I would just prefer (especially for my other two projects) to have the communication be initiated on the particle end not the st end then no polling necessary.
I did see that project and am just waiting on my shaft coupler to play with blinds!
jjhtpc
(Justin Wurth)
March 18, 2016, 9:12pm
4
I think this is what you are looking for.
This should provide the ability to post a json to smartthings.