arosequist / node-owlet

Node wrapper for the Owlet API
GNU General Public License v3.0
24 stars 6 forks source link

running this #3

Open justinhulin opened 6 years ago

justinhulin commented 6 years ago

hey can you explain to me how to run this? Im on a Mac and have node modules that I use for other things like home assistant and smart devices but I do not know how to run this on my Mac. do I use terminal? if so how? any help would be much appreciated. thanks

justinhulin commented 6 years ago

please help with this. I just need you to point me in the right direction of what to use to run it. I normally can figure out with a little guidance. do I need to create a .js file? what should I use

arosequist commented 6 years ago

The Usage section of the README pretty much covers the entire API. Is that helpful? Yes, it would live inside of a .js file, and you could run with node your_file.js.

justinhulin commented 6 years ago

So node file.js should spit out those numbers in terminal? Thanks for the help. Just want to make sure I was doing this right which I was i it always gives me the error about the line “import {connect} “ I’ll try to figure it out. Thanks again

-Justin

On Jan 21, 2018, at 9:09 PM, Anthony Rosequist notifications@github.com wrote:

The Usage section of the README pretty much covers the entire API. Is that helpful? Yes, it would live inside of a .js file, and you could run with node your_file.js.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

arosequist commented 6 years ago

Depending on what version of node you're running (and what flags you have on), you might not have support for certain things. You might try something like this (completely untested):

var connect = require('@arosequist/owlet').connect;

var owlet;
var deviceId;

connect('my@email.com', 'my-owlet-password')
    .then(function (owletResult) {
        owlet = owletResult;
        return owlet.getDevices();
    })
    .then(function (devices) {
        deviceId = devices[0].id;
        return owlet.getProperties(deviceId);
    })
    .then(function (props) {
        console.log({ props: props });
        return owlet.turnBaseStationOn(deviceId);
    })
    .then(function () {
        console.log('Turned on');
    })
    .catch(function (err) {
        console.log(err);
    });

If you do have async/await support, it can be much cleaner.

justinhulin commented 6 years ago

To be completely honest I am self taught when it comes to coding and I learn via books and google as I need something. I’ve used arduino and raspberry pi’s to make my own home automated devices in my house like thermostat and stuff like that. I’ve used Home bridge and home assistant to pull every thing together for siri control and an iPad dashboard. When I come across something in Home Assistant or Home bridge that doesn’t work I’ll just figure out how the code works and then change it to make it work. This is all hobby for me as I’m a medical student who loves to mess with stuff like that. It has its down falls becasue due to my type A personality I always like to complete what I started and unfortunately sometimes I can spend countless hours when I can’t figure out how or why something is not working like with the case of your code and not knowing what .ts files are and so forth.

What I do know is that with Home Assistant uses async cause ive seen it when changing some of the code for different components. So maybe you can answer me these questions so I can get it working well, cause I do eventually want to have this in my home assistant panel.

For a general understanding, this is made to run in terminal or console correct? Is there a way to download the async/await support? Currently I have a node_modules folder that was created when I downloaded node when I was setting up homebride which allow to integrate other devices into apples home app. Is this where the @arosequist folder should be placed, this is where all my other “nodes” are. However for whatever reason when I download yours it went to my main user folder into another node_modules folder. Also it seems it downloaded axios as well, should this also be placed in my node_module folder where my other nodes are. Also the code you emailed me, does that go into an index.js file, and if so where do I place the index.js file, I am assuming it does not matter. Do I have to do anything special like turn the base station on or off or does your code just use my login and password that I place in the ‘my@email.com’, ‘my-owlet-password’ section to login and get all the info it needs like my device id etc... I believe once I can get it working in terminal I can find a way to figure out a way to use python to import it into home assistant like I am wanting Thanks again for all this help I really do appreciate it, I know it can be frustrating for you to help someone who doesnt do this stuff a lot, but it is very much appreciated.

-Justin

On Jan 22, 2018, at 8:37 PM, Anthony Rosequist <notifications@github.com mailto:notifications@github.com> wrote:

Depending on what version of node you're running (and what flags you have on), you might not have support for certain things. You might try something like this (completely untested):

var connect = require('@arosequist/owlet').connect;

var owlet; var deviceId;

connect('my@email.com mailto:my@email.com', 'my-owlet-password') .then(function (owletResult) { owlet = owletResult; return owlet.getDevices(); }) .then(function (devices) { deviceId = devices[0].id; return owlet.getProperties(deviceId); }) .then(function (props) { console.log({ props: props }); // etc...

    return owlet.turnBaseStationOn(deviceId);
})
.then(function () {
    console.log("Turned on");
})
.catch(function (err) {
    console.log(err);
});

If you do have async/await support, it can be much cleaner.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/arosequist/node-owlet/issues/3#issuecomment-359654591, or mute the thread https://github.com/notifications/unsubscribe-auth/ANmyduiqT8E5Exr8O1MqQcbI3Ro5k_btks5tNUXbgaJpZM4RlQq5.

arosequist commented 6 years ago

@justinhulin

For a general understanding, this is made to run in terminal or console correct?

Yup!

Is there a way to download the async/await support?

Generally, that will be determined by the version of node you have (it's possible to "use" it in older versions that don't support it, but it takes more work). If you've got other code running with async/await, then you should be good.

Currently I have a node_modules folder that was created when I downloaded node when I was setting up homebride which allow to integrate other devices into apples home app. Is this where the @arosequist folder should be placed, this is where all my other “nodes” are. However for whatever reason when I download yours it went to my main user folder into another node_modules folder.

You shouldn't need to manually download these files. If you are in a folder and run npm install --save @arosequist/owlet, it should install it into that node_modules folder.

Also it seems it downloaded axios as well, should this also be placed in my node_module folder where my other nodes are.

Yes, but it should download it automatically when you run the npm install command from above.

Also the code you emailed me, does that go into an index.js file, and if so where do I place the index.js file, I am assuming it does not matter.

It can go into whatever file you want. If you put it in index.js, then you can run it with node index.js.

Do I have to do anything special like turn the base station on or off or does your code just use my login and password that I place in the ‘my@email.com’, ‘my-owlet-password’ section to login and get all the info it needs like my device id etc...

You shouldn't need to do anything special, just plug in your email and password.

I believe once I can get it working in terminal I can find a way to figure out a way to use python to import it into home assistant like I am wanting Thanks again for all this help I really do appreciate it, I know it can be frustrating for you to help someone who doesnt do this stuff a lot, but it is very much appreciated.

Not frustrating at all, let me know what other questions you have. Apologies for the long delay.

angel12 commented 6 years ago

@justinhulin did you ever get this working with HomeAssistant? Our baby is on the way, and I am looking at doing the same thing with HASS integration.

justinhulin commented 6 years ago

No I sure didn’t. I’m a medical student and when I had looked into it I was in break but I haven’t had a break since so I just use the app.

On Aug 27, 2018, at 11:24 AM, angel12 notifications@github.com wrote:

@justinhulin did you ever get this working with HomeAssistant? Our baby is on the way, and I am looking at doing the same thing with HASS integration.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

craigjmidwinter commented 6 years ago

@angel12 are you still interested in working on a HASS integration? Our baby is due in Jan and I picked up an owlet secondhand and I'd be interested in collaborating if you are

justinhulin commented 6 years ago

Honestly man I’m not a coder, I just do it for fun when I have time. I’m a Medical student and ever since starting medical school I really don’t have time for any fun anymore.

On Oct 5, 2018, at 8:22 PM, Craig J. Midwinter notifications@github.com wrote:

@angel12 are you still interested in working on a HASS integration? Our baby is due in Jan and I picked up an owlet secondhand and I'd be interested in collaborating if you are

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

angel12 commented 5 years ago

@craigjmidwinter

I forked another project that was already in python, https://github.com/angel12/python-owlet

I will try to get started on the HASS component soon, but this currently is working by running: python owlet_stats.py (email) (password)

craigjmidwinter commented 5 years ago

Interesting! This looks like a promising place to start. I was hoping there would be some sort of binary attribute to reflect a sleeping vs awake state. Maybe that's something that can be loosely determined based on movement? My wife isn't due for another few weeks, so I don't have a test-baby yet!

Edit-- if we want to continue discussion, I guess we should probably move to an issue on your repo