MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    SmartThings

    Scheduled Pinned Locked Moved General Discussion
    28 Posts 5 Posters 11.7k Views 6 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • buzzkcB Offline
      buzzkc
      last edited by

      I’m finally starting to make some progress on this. I’ve been doing development in a docker instance and found editing files while the container is running corrupts files. :-)

      So I have it connecting and bringing back device information at this point. I still need to parse that info. I’m working through the steps get all the info in the correct order to model it (get device ids>>get device components>>get device capabilities>>statuses etc.)

      I do have two hubs and found that it brings back devices for all hubs, so I’ll need to get the hub info too.

      Darren

      My Build: https://forum.magicmirror.builders/topic/11153/new-non-mirror

      1 Reply Last reply Reply Quote 1
      • cowboysdudeC Offline
        cowboysdude Module Developer
        last edited by

        This is something that I want to seriously look at this winter. Time right now is very hard for me to do anything…but I am keeping an eye on this and I appreciate ALL the input!!!

        I am trying first to get my thermostat to work via the mirror… module form. I can do it other ways but I want to learn how to use this IDE. But it gets to be too much… but you both have excellent ideas that I will be picking your brains soon!!! :)

        Keep posting please!!

        1 Reply Last reply Reply Quote 0
        • buzzkcB Offline
          buzzkc
          last edited by

          I’ve made a little more progress on this, but nothing to display the device info yet. I found the node-smarthings library uses promises to return results, which I’ve not worked with specifically, so been struggling with tying the device information to the device capability status results. I think I’ve finally worked passed it, but still have some testing to do.

          I’ve been trying to pass the device object from the first call to the call back function for the capability status, but not figured out how to do that. All of the status results were tied to the last device processed from the device callback. I did finally move the looping of devices to where only one device was sent to the socket notification that calls the capability status and seems to be working that way.

          Darren

          My Build: https://forum.magicmirror.builders/topic/11153/new-non-mirror

          S 1 Reply Last reply Reply Quote 0
          • S Do not disturb
            sdetweil @buzzkc
            last edited by sdetweil

            @buzzkc so, with promises, you have a ‘then’, with a ‘resolve’ and an ‘error’ callback, and the resolve and reject methods of the promise can provide data to the resolve and error routines…

            just a reminder, the return new Promise() returns IMMEDIATELY… the function inside the promise is called async sometime (milliseconds) later

               function_name: function(parm1_in, parm2_in) {
                 return new Promise( function (resolve,reject){
                         if( all_good) {
                             resolve(data_item)
                         }
                        else {
                            reject(error_data) 
                        }
                 }
                 )
            
            

            then the method CALLING this function

                function_name(parm1, parm2).then( 
                         resolve_func(data_item){ },
                         error_func(error_data){}
                )
            

            a working example , using the arrow function (parm) => {
            the arrow function insures that the data context of the outside caller is maintained,
            where as function(parm) { does not (u had to use the ‘self =this’ thing

            let promise = new Promise(function(resolve, reject) {
             if(!setTimeout(() => resolve("done!"), 1000)){
                 reject("settimeout_failed")
             }
            });
            
            // resolve runs the first function in .then, reject runs the second function
            promise.then(     // this will block until the function inside the promise call resolve or reject
              result => alert(result), // shows "done!" after 1 second
              error => alert(error) // doesn't run .. this will never occurr as settimeout never fails. 
            );
            

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            1 Reply Last reply Reply Quote 2
            • buzzkcB Offline
              buzzkc
              last edited by

              Thanks Sam, That does help explain things. The grandkids are visiting, so will be a day or so before I get back to this, unless I just can’t sleep tonight. ;-)

              Darren

              My Build: https://forum.magicmirror.builders/topic/11153/new-non-mirror

              S 1 Reply Last reply Reply Quote 0
              • S Do not disturb
                sdetweil @buzzkc
                last edited by sdetweil

                @buzzkc no problem… i’ll be around

                also, the function in the promise can also be arrow

                return new Promise(  (resolve,reject) =>{
                            if( all_good) {
                                 resolve(data_item)
                             }
                            else {
                                reject(error_data) 
                            }
                         })
                

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                1 Reply Last reply Reply Quote 1
                • S Do not disturb
                  sdetweil
                  last edited by sdetweil

                  and you can nest calls to functions that return Promises.

                     call_function_a(parm1, parm2).then( resolve_function(resolve_parm){ 
                                   ... processing
                                    call function_b(resolve_parm).then(resolve_function(some_otherdata){
                                    ....     processing
                                    })
                     })
                  
                  

                  the 1st call_function_a routine will return a Promise object immediately
                  and when the function inside the promise resolves, then ‘.then (resolve’ function will be called.

                  the ‘.then’ waits

                  you can also split it up and wait later

                    var p =   call_function_a(parm1, parm2)
                       processing
                       processing
                    Promise(p).then (... etc)
                  

                  i have a piece of code that loads a list of images from multiple difference sources, and knowing these take a ‘long time’ I wrapped them in promises… and start multiple at the same time…

                  now I have a list (array) of promises… but need to wait for all of them to complete (to have the complete list of images)

                  Promise.all(list).then(() => { sort full list of images, note that resolve() can't send back the list as its not complete }
                  

                  you can also wait for one

                  Promise.race(list).then( ... etc)
                  

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  1 Reply Last reply Reply Quote 0
                  • buzzkcB Offline
                    buzzkc
                    last edited by

                    Still working on getting things to refresh, but here is a teaser…
                    alt text

                    Let me know if the pic isn’t showing or disappears, using google photos

                    Darren

                    My Build: https://forum.magicmirror.builders/topic/11153/new-non-mirror

                    S 1 Reply Last reply Reply Quote 1
                    • S Do not disturb
                      sdetweil @buzzkc
                      last edited by

                      @buzzkc looks good

                      Sam

                      How to add modules

                      learning how to use browser developers window for css changes

                      1 Reply Last reply Reply Quote 0
                      • buzzkcB Offline
                        buzzkc
                        last edited by buzzkc

                        I’ll start a new thread for this, but if anyone wants to try it out or PR it, keep in mind, it’s my first module. ;-)
                        https://github.com/buzzkc/MMM-Smartthings

                        Currently I’m only supporting a subset of device capabilities. I can only run one instance of the module also since everything is returned to a global array. More than one instance all the devices from each module instances get put into the array and the full list of devices displays on all instances rather than what was specified for that instance.

                        For multiple capabilities in the list, the display is sorted by device name, then by capability alphabetically.

                        It also displays devices for all locations, I’ll see if I can make this selective in the future, but fits my needs as it is.

                        Darren

                        My Build: https://forum.magicmirror.builders/topic/11153/new-non-mirror

                        1 Reply Last reply Reply Quote 0
                        • cowboysdudeC Offline
                          cowboysdude Module Developer
                          last edited by

                          Just stopping in and I wanted to say Thank you guys for working on this! I am still hammered as all get out with work and crawl home most nights… I’m running 3 months behind right now. But I wanted to check in and wow… this is amazing!! Thank you guys so much!

                          1 Reply Last reply Reply Quote 0
                          • buzzkcB Offline
                            buzzkc
                            last edited by buzzkc

                            Well, looks like it’s duplicating some of the items in the array. I’ll get a patch uploaded for it soon.

                            Edit: Found this was due to having more than one browser open, each instance was updating the global array. Working on a fix.

                            Darren

                            My Build: https://forum.magicmirror.builders/topic/11153/new-non-mirror

                            1 Reply Last reply Reply Quote 0
                            • buzzkcB Offline
                              buzzkc
                              last edited by

                              I’ve fixed the duplication, added an excluded device name list, fixed some timing issues, and cleaned it up.

                              I’m not entirely happy with the way I’m getting all the data, but I haven’t quite figured out a good way to wait for all the promises returned from the smartthings-node library. I have to loop the capabilities, make a request to get devices by capability, wait for that promise, then loop devices to get the statuses for each, once those promises return I need to pair up the status with its device.

                              So the ugly of it is that I’m just pushing all the data via sockets for each status request into an array that gets updated, then it gets fed to the getDom(). Not pretty, but it’s working.

                              Darren

                              My Build: https://forum.magicmirror.builders/topic/11153/new-non-mirror

                              1 Reply Last reply Reply Quote 1
                              • buzzkcB Offline
                                buzzkc
                                last edited by

                                Ok, I think I’ve gotten things to where it’s ready to share, I posted it up on the modules forum…Thanks again for all the feedback.

                                https://forum.magicmirror.builders/topic/11270/mmm-smartthings

                                Darren

                                My Build: https://forum.magicmirror.builders/topic/11153/new-non-mirror

                                1 Reply Last reply Reply Quote 1
                                • cowboysdudeC Offline
                                  cowboysdude Module Developer
                                  last edited by

                                  Someone please close this topic … It has moved here:

                                  https://forum.magicmirror.builders/topic/11270/mmm-smartthings

                                  Thank you all!! :)

                                  1 Reply Last reply Reply Quote 0

                                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                  With your input, this post could be even better 💗

                                  Register Login
                                  • 1
                                  • 2
                                  • 2 / 2
                                  • First post
                                    Last post
                                  Enjoying MagicMirror? Please consider a donation!
                                  MagicMirror created by Michael Teeuw.
                                  Forum managed by Sam, technical setup by Karsten.
                                  This forum is using NodeBB as its core | Contributors
                                  Contact | Privacy Policy