Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. Plotting graphs with plot.ly service with luup scene using REST API

Plotting graphs with plot.ly service with luup scene using REST API

Scheduled Pinned Locked Moved My Project
plot.lygraphluupplot
56 Posts 10 Posters 27.6k Views 2 Watching
  • 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.
  • NuubiN Nuubi

    Excellent, thanks! This is much needed.
    For some reason, can't get this to work...LUA error.
    I'm trying to send MySensors data to Plotly...
    Anyway, does e.g. <username> mean that you write username, or <username> to the script? (Oh yeah, username referring to the actual username :-) )

    S Offline
    S Offline
    samppa
    wrote on last edited by samppa
    #4

    @Nuubi
    Yes, the username and API key are shown on the plot.ly api settings page.

    Here is my code that works for 5 lines in one graph and appends data every 5 minutes:


    -- Get variables
    local BRHum = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1", "CurrentLevel", 83)
    local BRTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 84)
    local ACBoost = 100 * luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 106)
    local ACMech = 100 * luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 107)
    local ACEff = luup.variable_get("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", 88    )
    
    local ts = os.date("%Y-%m-%d %X")
    
    -- Send to plot
    local http = require("socket.http")
    http.TIMEOUT = 5
    result, status = http.request("https://plot.ly/clientresp",'un=<username>&key= <APIKey>&origin=plot&platform=lisp&args=[{"x":["'..ts..'"],"y":['..BRHum..'],"name":"Humidity"},{"x":["'..ts..'"],"y": ['..ACBoost..'],"name":"AC Boost"},{"x":["'..ts..'"],"y":['..BRTemp..'],"name":"Temperature"},{"x":["'..ts..'"],"y":['..ACMech..'],"name":"Mech Sensor"},{"x":["'..ts..'"],"y":['..ACEff..'],"name":"AC Efficiency"}]&kwargs={"filename":"BathroomHumidity","fileopt":"extend","style":{"type":"scatter"},"traces":[0,1,2,3,4],"layout":{"title":"Bathroom Humidity"},"world_readable":false}')
    

    I know the JSON syntax is cryptic in one line without pretty formatting..

    1 Reply Last reply
    0
    • korttomaK Offline
      korttomaK Offline
      korttoma
      Hero Member
      wrote on last edited by
      #5

      @samppa this is sweet :+1: . Thank you so much for sharing this!

      • Tomas
      1 Reply Last reply
      0
      • NuubiN Offline
        NuubiN Offline
        Nuubi
        wrote on last edited by
        #6

        Uh...oh...still.. do you need to initialize the graph or what? Still not getting this to work, sorry for being such a dummie :-E

        S 1 Reply Last reply
        0
        • korttomaK Offline
          korttomaK Offline
          korttoma
          Hero Member
          wrote on last edited by
          #7

          You should use username and not <username>. The same goes for the API key.

          In UI5 you can test your Lua in Vera from APPS -> Develop Apps -> Test Luup code

          Here is a few more examples of variable_get:
          local InAirHum = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1", "CurrentLevel", 347)
          local OutTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature", 229)
          local InAirTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature", 346)
          local InAirQ = luup.variable_get("urn:upnp-org:serviceId:VContainer1", "Variable1", 348)

          • Tomas
          1 Reply Last reply
          0
          • korttomaK Offline
            korttomaK Offline
            korttoma
            Hero Member
            wrote on last edited by
            #8

            I'm having trouble with one variable to. I would like to have the status of a qubino switch in the same graph.
            I tried this:
            local VentOn = 100 luup.variable_get("urn:upnp-org:serviceId:BinaryLight1", "Status", 356)

            It gives me the value 100 in the graph. Please let me know what this 100 in front of the luup.variable_get does. If I remove it the Luup code fails.

            • Tomas
            S 1 Reply Last reply
            0
            • korttomaK korttoma

              I'm having trouble with one variable to. I would like to have the status of a qubino switch in the same graph.
              I tried this:
              local VentOn = 100 luup.variable_get("urn:upnp-org:serviceId:BinaryLight1", "Status", 356)

              It gives me the value 100 in the graph. Please let me know what this 100 in front of the luup.variable_get does. If I remove it the Luup code fails.

              S Offline
              S Offline
              samppa
              wrote on last edited by samppa
              #9

              @korttoma said:

              I'm having trouble with one variable to. I would like to have the status of a qubino switch in the same graph.
              I tried this:
              local VentOn = 100 luup.variable_get("urn:upnp-org:serviceId:BinaryLight1", "Status", 356)

              It gives me the value 100 in the graph. Please let me know what this 100 in front of the luup.variable_get does. If I remove it the Luup code fails.

              Actually there should be asterisk character between 100 and the luup.variable_get and the (forum editor does not show that) since the returned value 1 or 0 is scaled to 100 so try:

              local VentOn = 100 * luup.variable_get("urn:upnp-org:serviceId:BinaryLight1", "Status", 356)
              

              Then you get 100 if binary light is on. Remove the 100 if you like it to be 1 or 0.

              korttomaK 1 Reply Last reply
              0
              • NuubiN Nuubi

                Uh...oh...still.. do you need to initialize the graph or what? Still not getting this to work, sorry for being such a dummie :-E

                S Offline
                S Offline
                samppa
                wrote on last edited by
                #10

                @Nuubi said:

                Uh...oh...still.. do you need to initialize the graph or what? Still not getting this to work, sorry for being such a dummie :-E

                You just send the data and the graph named with "filename":"xxxx" gets created if not yet existing.

                NuubiN 1 Reply Last reply
                0
                • S samppa

                  @korttoma said:

                  I'm having trouble with one variable to. I would like to have the status of a qubino switch in the same graph.
                  I tried this:
                  local VentOn = 100 luup.variable_get("urn:upnp-org:serviceId:BinaryLight1", "Status", 356)

                  It gives me the value 100 in the graph. Please let me know what this 100 in front of the luup.variable_get does. If I remove it the Luup code fails.

                  Actually there should be asterisk character between 100 and the luup.variable_get and the (forum editor does not show that) since the returned value 1 or 0 is scaled to 100 so try:

                  local VentOn = 100 * luup.variable_get("urn:upnp-org:serviceId:BinaryLight1", "Status", 356)
                  

                  Then you get 100 if binary light is on. Remove the 100 if you like it to be 1 or 0.

                  korttomaK Offline
                  korttomaK Offline
                  korttoma
                  Hero Member
                  wrote on last edited by
                  #11

                  @samppa said:

                  Actually there should be asterisk character between 100 and the luup.variable_get and the (forum editor does not show that) since the returned value 1 or 0 is scaled to 100 so try:

                  local VentOn = 100 * luup.variable_get("urn:upnp-org:serviceId:BinaryLight1", "Status", 356)
                  Then you get 100 if binary light is on. Remove the 100 if you like it to be 1 or 0.

                  I thought it was a multiplier of some kind. Anyhow the code fails allso if I add the asterisk so I thik it has a problem with:

                  luup.variable_get("urn:upnp-org:serviceId:BinaryLight1", "Status", 356)
                  

                  Any suggestions what I should try instead? Tried also this but no luck:

                  luup.variable_get("urn:micasaverde-com:serviceId:BinaryLight1", "Status", 356)
                  
                  • Tomas
                  1 Reply Last reply
                  0
                  • korttomaK Offline
                    korttomaK Offline
                    korttoma
                    Hero Member
                    wrote on last edited by
                    #12

                    Had a chat with @BulldogLowell and he taught me that you can hover the mouse on a variable to check the complete variable name so it turned out I had to use the following:

                    luup.variable_get("urn:micasaverde-com:serviceId:SwitchPower1", "Status", 356)
                    
                    • Tomas
                    1 Reply Last reply
                    0
                    • S samppa

                      @Nuubi said:

                      Uh...oh...still.. do you need to initialize the graph or what? Still not getting this to work, sorry for being such a dummie :-E

                      You just send the data and the graph named with "filename":"xxxx" gets created if not yet existing.

                      NuubiN Offline
                      NuubiN Offline
                      Nuubi
                      wrote on last edited by
                      #13

                      @samppa Yep, works now, thanks!
                      The problem turned out to be the actual value I wanted to send. Need to figure out how to read MySensors based values in LUA...

                      BulldogLowellB 1 Reply Last reply
                      0
                      • NuubiN Nuubi

                        @samppa Yep, works now, thanks!
                        The problem turned out to be the actual value I wanted to send. Need to figure out how to read MySensors based values in LUA...

                        BulldogLowellB Offline
                        BulldogLowellB Offline
                        BulldogLowell
                        Contest Winner
                        wrote on last edited by
                        #14

                        @Nuubi

                        have you tried luup.inet.wget( )

                        local brightness = luup.variable_get("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", 118)
                        luup.inet.wget("192.168.1.50//?brightLevel="..brightness.."&", 1)
                        
                        1 Reply Last reply
                        0
                        • korttomaK Offline
                          korttomaK Offline
                          korttoma
                          Hero Member
                          wrote on last edited by
                          #15

                          Anyone figured out a way to add another variable to an old graph without deleting the file from plot.ly? Seems like it does not include the new variable unless you delete and create a new file.

                          • Tomas
                          S 1 Reply Last reply
                          0
                          • korttomaK korttoma

                            Anyone figured out a way to add another variable to an old graph without deleting the file from plot.ly? Seems like it does not include the new variable unless you delete and create a new file.

                            S Offline
                            S Offline
                            samppa
                            wrote on last edited by
                            #16

                            @korttoma said:

                            Anyone figured out a way to add another variable to an old graph without deleting the file from plot.ly? Seems like it does not include the new variable unless you delete and create a new file.

                            I have noticed the same thing; If you want to add a trace you need to delete the file..
                            So perhaps it is wise to be prepared and add a few extra traces for some future use.

                            korttomaK 1 Reply Last reply
                            0
                            • S samppa

                              @korttoma said:

                              Anyone figured out a way to add another variable to an old graph without deleting the file from plot.ly? Seems like it does not include the new variable unless you delete and create a new file.

                              I have noticed the same thing; If you want to add a trace you need to delete the file..
                              So perhaps it is wise to be prepared and add a few extra traces for some future use.

                              korttomaK Offline
                              korttomaK Offline
                              korttoma
                              Hero Member
                              wrote on last edited by
                              #17

                              @samppa said:

                              perhaps it is wise to be prepared and add a few extra traces for some future use.

                              Good suggestion for a workaround but it does not seem to pick up name changes for the trace either. Tried also to edit one of the plots on the website but when I wanted to save I could not save the changes to the file used by "Vera". I had to save the file with a different name so no editing seems to be possible.

                              • Tomas
                              1 Reply Last reply
                              0
                              • korttomaK Offline
                                korttomaK Offline
                                korttoma
                                Hero Member
                                wrote on last edited by
                                #18

                                Since the nightly heal at 2 in the morning no data is transferred to plot.ly any more :( anyone else see this and know how to solv it?

                                • Tomas
                                DwaltD 1 Reply Last reply
                                0
                                • korttomaK korttoma

                                  Since the nightly heal at 2 in the morning no data is transferred to plot.ly any more :( anyone else see this and know how to solv it?

                                  DwaltD Offline
                                  DwaltD Offline
                                  Dwalt
                                  wrote on last edited by
                                  #19

                                  @korttoma

                                  My plots stopped last night as well, last data point transmitted was at 12:03am GMT, but not after a nightly heal.

                                  -Dwalt

                                  Veralite UI5 :: IBoard Ethernet GW :: MyS 1.5

                                  1 Reply Last reply
                                  0
                                  • korttomaK Offline
                                    korttomaK Offline
                                    korttoma
                                    Hero Member
                                    wrote on last edited by
                                    #20

                                    12 GMT is 2 in my timezone so I guess it was just a coincidence that it happened at the time of the heel. Maybe plot.ly blocked us for some reason.

                                    • Tomas
                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      samppa
                                      wrote on last edited by
                                      #21

                                      My graphs stopped as well. I have asked what is going on.. Let's see when it gets back up again..

                                      1 Reply Last reply
                                      0
                                      • korttomaK Offline
                                        korttomaK Offline
                                        korttoma
                                        Hero Member
                                        wrote on last edited by
                                        #22

                                        I sent them some feedback to but have not heard anything yet. Maybe we should try the "Streaming API" instead?

                                        • Tomas
                                        DwaltD S 2 Replies Last reply
                                        0
                                        • korttomaK korttoma

                                          I sent them some feedback to but have not heard anything yet. Maybe we should try the "Streaming API" instead?

                                          DwaltD Offline
                                          DwaltD Offline
                                          Dwalt
                                          wrote on last edited by Dwalt
                                          #23

                                          @korttoma

                                          I tried to set up a new graph using the REST API and could not get it to register with Plot.ly. Without any explanation from Plot.ly, I tried sending the same data streams to ThingSpeak.com and it set up with out any trouble. The API is slightly different but just as easy to use. I set up a scene to run every 15 minutes with the following code:

                                          -- Get Light Levels
                                          local LR_LIGHT_LEVEL = luup.variable_get("urn:micasaverde-com:serviceId:LightSensor1", "CurrentLevel", 47)
                                          local BR_LIGHT_LEVEL = luup.variable_get("urn:micasaverde-com:serviceId:LightSensor1", "CurrentLevel", 55)
                                          
                                          - - Get Temps
                                          local LR_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 46)
                                          local BR_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 54)
                                          local OUT_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 23)
                                          
                                          -- Send data to ThingSpeak.com
                                          local http = require("socket.http")
                                          http.TIMEOUT = 5
                                          result, status = http.request("http://api.thingspeak.com/update?key=Insert Your API Key here&field1="..LR_TEMP.."&field2="..BR_TEMP.."&field3="..OUT_TEMP.."&field4="..LR_LIGHT_LEVEL.."&field5="..BR_LIGHT_LEVEL.."", "run=run") ````
                                          
                                          The service has a limited functionality to manipulate your data but the base configuration is easy to tweak and can be made public or private.  See [here for my sample data](https://thingspeak.com/channels/25629).
                                          
                                          ...plus it is free to use.

                                          Veralite UI5 :: IBoard Ethernet GW :: MyS 1.5

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          19

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular