Announcement

Collapse
No announcement yet.

Seneye API - Aquarium monitor

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Seneye API - Aquarium monitor

    Seneye (http://www.seneye.com/)is an aquarium monitor that tests water quality, temperature, PH etc. They have a nice dashboard type website to see the results. They also have an API that I'd like to use to get the data into HS.

    Trouble is I simply don't know where to start Ideally I'd like to pull the data from the API and store it as a device value.

    http://www.api.seneye.com/


    https://api.seneye.com/api/resources/view/q/device_exps

    Any pointers ?

    #2
    Does not look overly difficult (famous last words) using a few HS commands.

    Using the command hs.urlaction you should (providing the secure HTTP does not throw up a problem) be able to return the data into a string if you perform a GET on the URL. I would personally look at returning the data in XML format as .net can perform XML commands easier than JSON (I think the JSON libraries were only in later .net versions?). If you returned it as a string you could then load it straight into an XMLdocument. You would need to learn some basic XPath commands to get the bit of data you are after and could do it easily from a script.

    Comment


      #3
      I've had a little play and have managed to get the data into a text file using hs.GetURLex. The data looks like this:

      {"temperature":{"trend":"1","critical_in":"-1","avg":"24.9","status":"0","curr":"25.2","advises":[]},"ph":{"trend":"1","critical_in":"-1","avg":"8.16","status":"1","curr":"8.27","advises":[]},"nh3":{"trend":"1","critical_in":"-1","avg":"0.020","status":"1","curr":"0.109","advises":[]},"nh4":{"trend":"-1","critical_in":"-1","avg":"34.83","status":"0","curr":"10.48","advises":[]},"o2":{"trend":"0","critical_in":"-1","avg":"8.2","status":"0","curr":"8.2","advises":[]},"lux":{"status":null,"curr":"22","advises":[]},"par":{"curr":"0.5","advises":[]},"kelvin":{"curr":"10590","advises":[]}}
      Part 1 accomplished - I've got the data So now I need to parse the data and use it to set device values (so i can use it in Mainlobby). I understand how to set the device values but how do I go about parsing the data ? For example, how would I pull current temperature ?

      Comment


        #4
        That's a JSON reply, you can either try and load it into a JSON parser (whether something like a .net library or a function) or if you want to try something easier you can try some string manipulation like some carefully crafted string.split arrays but its going to be fiddly.

        An XML reply would be easier, it looked like you could ask for one in the headers.

        Pity companies don't put sample devices like this online to work with else I would write something myself, when I get my reef back online I'll buy one.

        Comment


          #5
          On their sites, it says

          <TABLE><TBODY><TR class=odd><TD>GET</TD><TD><CODE>https://api.seneye.com/v1/devices?user=***&pwd=***</CODE>
          </TD></TR><TR><TD colSpan=2>

          Get devices list of demo account in XML format, usign Http Header "Accept: application/xml"


          It lists the response formats as JSON, XML and PHP.


          </TD></TR></TBODY></TABLE>
          --
          Jeff Farmer
          HS 3, HSPhone
          My HS3 Plugins: CFHSExtras, Random, Restart, Tracker, WeatherXML, PanaBluRay
          Other Plugins In Use: APCUPSD, BLOnkyo, Device History, EasyTrigger, HSTouch Server, PHLocation2, Pushover, RFXCom, UltraGCIR3, UltraMon3, UltraPioneerAVR3, X10, Z-Wave

          Hardware: GoControl Irrigation Controler, Schlage Lever Lock, Schlage Deadbolt, Way2Call Hi-Phone, RFXCom RFXrec433 Receiver, WGL 800, TI-103, Z-Net, Pioneer 1120, Pioneer 1021, Pioneer LX302, Panasonic BDT-110, Panasonic BDT-210 x2

          Comment


            #6
            Neat, if this works out.... I'd buy an aquarium and fish as well just for the sake of using something like this... (and yeah maybe it would be great for my little guy)

            Comment


              #7
              Get devices list of demo account in XML format, usign Http Header "Accept: application/xml"


              It lists the response formats as JSON, XML and PHP.
              OK, So where/how do we set the http header ? What would the syntax look like ?
              Happy to provide my own login details if it helps - my tank is new and I'm currently doing a fishless cycle which explains the high Ammonia etc.

              Thanks
              Kevin

              Comment


                #8
                Originally posted by kw1816 View Post
                OK, So where/how do we set the http header ? What would the syntax look like ?
                Happy to provide my own login details if it helps - my tank is new and I'm currently doing a fishless cycle which explains the high Ammonia etc.

                Thanks
                Kevin
                If you wanna drop us an email via the board I am happy to try it

                Comment


                  #9
                  Email sent

                  Comment


                    #10
                    Originally posted by kw1816 View Post
                    Email sent
                    I've replied, reply email same as login? Don't get your address when emails sent through the board.

                    Comment


                      #11
                      Here is the simple script, it is written quickly and easily vs. for efficiency. This is for the Seneye Reef device.

                      1) Ensure that the System.XML namespace is referenced in your settings.ini file
                      2) Change your username/password/device ID at the top of the script
                      3) Change the start house code and unit number to a suitable value
                      4) Run the script from a recurring event (informed data only updates at 30min intervals in any case)

                      Should update the devices and you can use them for events etc.

                      Code:
                      Imports System.Net
                      Imports System.XML
                      
                      Const UNa As String = "username"
                      Const PWd As String = "password"
                      Const DId As String = "deviceID"
                      Const HC As Char = "Y"
                      Dim DC As Integer = 1
                      Dim ImgStr As String = "<img src='/images/clown_fish.png'> "
                      
                      Sub Main(ByVal Parms As Object)
                      
                      Dim BuildURL As String = Nothing
                      Dim NetReply As String = Nothing
                      Dim webClient As New System.Net.WebClient
                      Dim XMLSen As New XmlDocument
                      
                      BuildURL = "https://api.seneye.com/v1/devices/" & DId & "/exps?user=" & UNa & "&pwd=" & PWd
                      
                      webClient.Headers.Add("Accept","application/xml")
                      
                      Dim result As String = webClient.DownloadString(BuildURL)
                      
                      If result.Length > 1 Then
                      
                      Try
                      
                      XMLSen.LoadXML(result)
                      
                      'XMLSen.Save(hs.getapppath & "\data\latest.xml")
                      
                      'now start to put some of the values in devices
                      
                      If hs.deviceexists(HC & DC) <> -1 Then
                      
                      hs.setdevicestring(HC & DC, ImgStr & DateTime.Now.ToString("dd/MM/yyyy HH:mm"), True)
                      
                      '##Temperature##
                      
                      hs.setdevicestring(HC & (DC+1), ImgStr & XMLSen.SelectSingleNode("/response/temperature/curr").InnerText & " °C", True)
                      hs.setdevicevalue(HC & (DC+1), Convert.ToInt32(XMLSen.SelectSingleNode("/response/temperature/curr").InnerText * 10))
                      
                      hs.setdevicestring(HC & (DC+2), ImgStr & XMLSen.SelectSingleNode("/response/temperature/avg").InnerText & " °C", True)
                      hs.setdevicevalue(HC & (DC+2), Convert.ToInt32(XMLSen.SelectSingleNode("/response/temperature/avg").InnerText * 10))
                      
                      '?? Status/Trend ??
                      
                      Select Case XMLSen.SelectSingleNode("/response/temperature/trend").InnerText
                      
                      Case "0"
                      hs.setdevicestring(HC & (DC+3), ImgStr & "Stable", True)
                      hs.setdevicevalue(HC & (DC+3), 0)
                      Case "1"
                      hs.setdevicestring(HC & (DC+3), ImgStr & "Rising", True)
                      hs.setdevicevalue(HC & (DC+3), 1)
                      Case "-1"
                      hs.setdevicestring(HC & (DC+3), ImgStr & "Falling", True)
                      hs.setdevicevalue(HC & (DC+3), -1)
                      
                      End Select
                      
                      Select Case XMLSen.SelectSingleNode("/response/temperature/status").InnerText
                      
                      Case "0"
                      hs.setdevicestring(HC & (DC+4), ImgStr & "OK", True)
                      hs.setdevicevalue(HC & (DC+4), 0)
                      Case "1"
                      hs.setdevicestring(HC & (DC+4), ImgStr & "Warning", True)
                      hs.setdevicevalue(HC & (DC+4), 1)
                      Case Else
                      hs.setdevicestring(HC & (DC+4), ImgStr & "Unknown/Error", True)
                      hs.setdevicevalue(HC & (DC+4), -1)
                      
                      End Select
                      
                      '##pH##
                      
                      hs.setdevicestring(HC & (DC+5), ImgStr & XMLSen.SelectSingleNode("/response/ph/curr").InnerText, True)
                      hs.setdevicevalue(HC & (DC+5), Convert.ToInt32(XMLSen.SelectSingleNode("/response/ph/curr").InnerText * 10))
                      
                      hs.setdevicestring(HC & (DC+6), ImgStr & XMLSen.SelectSingleNode("/response/ph/avg").InnerText, True)
                      hs.setdevicevalue(HC & (DC+6), Convert.ToInt32(XMLSen.SelectSingleNode("/response/ph/avg").InnerText * 10))
                      
                      '?? Status/Trend ??
                      
                      Select Case XMLSen.SelectSingleNode("/response/ph/trend").InnerText
                      
                      Case "0"
                      hs.setdevicestring(HC & (DC+7), ImgStr & "Stable", True)
                      hs.setdevicevalue(HC & (DC+7), 0)
                      Case "1"
                      hs.setdevicestring(HC & (DC+7), ImgStr & "Rising", True)
                      hs.setdevicevalue(HC & (DC+7), 1)
                      Case "-1"
                      hs.setdevicestring(HC & (DC+7), ImgStr & "Falling", True)
                      hs.setdevicevalue(HC & (DC+7), -1)
                      
                      End Select
                      
                      Select Case XMLSen.SelectSingleNode("/response/ph/status").InnerText
                      
                      Case "0"
                      hs.setdevicestring(HC & (DC+8), ImgStr & "OK", True)
                      hs.setdevicevalue(HC & (DC+8), 0)
                      Case "1"
                      hs.setdevicestring(HC & (DC+8), ImgStr & "Warning", True)
                      hs.setdevicevalue(HC & (DC+8), 1)
                      Case Else
                      hs.setdevicestring(HC & (DC+8), ImgStr & "Unknown/Error", True)
                      hs.setdevicevalue(HC & (DC+8), -1)
                      
                      End Select
                      
                      '##NH3##
                      
                      hs.setdevicestring(HC & (DC+9), ImgStr & XMLSen.SelectSingleNode("/response/nh3/curr").InnerText & " ppm", True)
                      hs.setdevicevalue(HC & (DC+9), Convert.ToInt32(XMLSen.SelectSingleNode("/response/nh3/curr").InnerText * 1000))
                      
                      hs.setdevicestring(HC & (DC+10), ImgStr & XMLSen.SelectSingleNode("/response/nh3/avg").InnerText & " ppm", True)
                      hs.setdevicevalue(HC & (DC+10), Convert.ToInt32(XMLSen.SelectSingleNode("/response/nh3/avg").InnerText * 1000))
                      
                      '?? Status/Trend ??
                      
                      Select Case XMLSen.SelectSingleNode("/response/nh3/trend").InnerText
                      
                      Case "0"
                      hs.setdevicestring(HC & (DC+11), ImgStr & "Stable", True)
                      hs.setdevicevalue(HC & (DC+11), 0)
                      Case "1"
                      hs.setdevicestring(HC & (DC+11), ImgStr & "Rising", True)
                      hs.setdevicevalue(HC & (DC+11), 1)
                      Case "-1"
                      hs.setdevicestring(HC & (DC+11), ImgStr & "Falling", True)
                      hs.setdevicevalue(HC & (DC+11), -1)
                      
                      End Select
                      
                      Select Case XMLSen.SelectSingleNode("/response/nh3/status").InnerText
                      
                      Case "0"
                      hs.setdevicestring(HC & (DC+12), ImgStr & "OK", True)
                      hs.setdevicevalue(HC & (DC+12), 0)
                      Case "1"
                      hs.setdevicestring(HC & (DC+12), ImgStr & "Warning", True)
                      hs.setdevicevalue(HC & (DC+12), 1)
                      Case Else
                      hs.setdevicestring(HC & (DC+12), ImgStr & "Unknown/Error", True)
                      hs.setdevicevalue(HC & (DC+12), -1)
                      
                      End Select
                      
                      '##NH4##
                      
                      hs.setdevicestring(HC & (DC+13), ImgStr & XMLSen.SelectSingleNode("/response/nh4/curr").InnerText & " ppm", True)
                      hs.setdevicevalue(HC & (DC+13), Convert.ToInt32(XMLSen.SelectSingleNode("/response/nh4/curr").InnerText * 10))
                      
                      hs.setdevicestring(HC & (DC+14), ImgStr & XMLSen.SelectSingleNode("/response/nh4/avg").InnerText & " ppm", True)
                      hs.setdevicevalue(HC & (DC+14), Convert.ToInt32(XMLSen.SelectSingleNode("/response/nh4/avg").InnerText * 10))
                      
                      '?? Status/Trend ??
                      
                      Select Case XMLSen.SelectSingleNode("/response/nh4/trend").InnerText
                      
                      Case "0"
                      hs.setdevicestring(HC & (DC+15), ImgStr & "Stable", True)
                      hs.setdevicevalue(HC & (DC+15), 0)
                      Case "1"
                      hs.setdevicestring(HC & (DC+15), ImgStr & "Rising", True)
                      hs.setdevicevalue(HC & (DC+15), 1)
                      Case "-1"
                      hs.setdevicestring(HC & (DC+15), ImgStr & "Falling", True)
                      hs.setdevicevalue(HC & (DC+15), -1)
                      
                      End Select
                      
                      Select Case XMLSen.SelectSingleNode("/response/nh4/status").InnerText
                      
                      Case "0"
                      hs.setdevicestring(HC & (DC+16), ImgStr & "OK", True)
                      hs.setdevicevalue(HC & (DC+16), 0)
                      Case "1"
                      hs.setdevicestring(HC & (DC+16), ImgStr & "Warning", True)
                      hs.setdevicevalue(HC & (DC+16), 1)
                      Case Else
                      hs.setdevicestring(HC & (DC+16), ImgStr & "Unknown/Error", True)
                      hs.setdevicevalue(HC & (DC+16), -1)
                      
                      End Select
                      
                      '##O2##
                      
                      hs.setdevicestring(HC & (DC+17), ImgStr & XMLSen.SelectSingleNode("/response/o2/curr").InnerText, True)
                      hs.setdevicevalue(HC & (DC+17), Convert.ToInt32(XMLSen.SelectSingleNode("/response/o2/curr").InnerText * 10))
                      
                      hs.setdevicestring(HC & (DC+18), ImgStr & XMLSen.SelectSingleNode("/response/o2/avg").InnerText, True)
                      hs.setdevicevalue(HC & (DC+18), Convert.ToInt32(XMLSen.SelectSingleNode("/response/o2/avg").InnerText * 10))
                      
                      '?? Status/Trend ??
                      
                      Select Case XMLSen.SelectSingleNode("/response/o2/trend").InnerText
                      
                      Case "0"
                      hs.setdevicestring(HC & (DC+19), ImgStr & "Stable", True)
                      hs.setdevicevalue(HC & (DC+19), 0)
                      Case "1"
                      hs.setdevicestring(HC & (DC+19), ImgStr & "Rising", True)
                      hs.setdevicevalue(HC & (DC+19), 1)
                      Case "-1"
                      hs.setdevicestring(HC & (DC+19), ImgStr & "Falling", True)
                      hs.setdevicevalue(HC & (DC+19), -1)
                      
                      End Select
                      
                      Select Case XMLSen.SelectSingleNode("/response/o2/status").InnerText
                      
                      Case "0"
                      hs.setdevicestring(HC & (DC+20), ImgStr & "OK", True)
                      hs.setdevicevalue(HC & (DC+20), 0)
                      Case "1"
                      hs.setdevicestring(HC & (DC+20), ImgStr & "Warning", True)
                      hs.setdevicevalue(HC & (DC+16), 1)
                      Case Else
                      hs.setdevicestring(HC & (DC+20), ImgStr & "Unknown/Error", True)
                      hs.setdevicevalue(HC & (DC+20), -1)
                      
                      End Select
                      
                      
                      '##Misc
                      
                      hs.setdevicestring(HC & (DC+21), ImgStr & XMLSen.SelectSingleNode("/response/lux/curr").InnerText & " Lux", True)
                      hs.setdevicevalue(HC & (DC+21), Convert.ToInt32(XMLSen.SelectSingleNode("/response/lux/curr").InnerText * 10))
                      
                      hs.setdevicestring(HC & (DC+22), ImgStr & XMLSen.SelectSingleNode("/response/par/curr").InnerText & " PAR", True)
                      hs.setdevicevalue(HC & (DC+22), Convert.ToInt32(XMLSen.SelectSingleNode("/response/par/curr").InnerText * 10))
                      
                      hs.setdevicestring(HC & (DC+23), ImgStr & XMLSen.SelectSingleNode("/response/kelvin/curr").InnerText & " K", True)
                      hs.setdevicevalue(HC & (DC+23), Convert.ToInt32(XMLSen.SelectSingleNode("/response/kelvin/curr").InnerText))
                      
                      Else
                      
                      Call CDevices("")
                      
                      End If
                      
                      
                      Catch ex As Exception
                      
                      Log("Error: " & ex.Message)
                      
                      End Try
                      
                      Else
                      
                      Log("Error - downloaded file empty")
                      
                      End If
                      
                      End Sub
                      
                      Sub Log(ByVal Parms As String)
                      
                      hs.writelog("Seneye", Parms)
                      
                      End Sub
                      
                      Sub CDevices(ByVal Parms As Object)
                      
                      Dim objDevice As Object
                      Dim TN As String = "Seneye"
                      
                      Dim max_devices As Byte = 24             ' Set to non-zero to create more devices
                      
                      For i As Integer = 1 To max_devices
                      
                      	If hs.deviceexists(HC & DC) <> - 1 Then
                      		Log("Trying to create device but already exists")
                      	Else
                      
                      	Select Case i
                      
                      		Case 1
                      			objDevice = hs.NewDeviceEx(TN & " Last Update")
                      			objDevice.interface = "Seneye Status Device"
                      		Case 2
                      			objDevice = hs.NewDeviceEx(TN & " Current Temperature")
                      			objDevice.interface = "Seneye Temperature Device"
                      		Case 3
                      			objDevice = hs.NewDeviceEx(TN & " Average Temperature")
                      			objDevice.interface = "Seneye Temperature Device"
                      		Case 4
                      			objDevice = hs.NewDeviceEx(TN & " Temperature Trend")
                      			objDevice.interface = "Seneye Temperature Device"
                      		Case 5
                      			objDevice = hs.NewDeviceEx(TN & " Temperature Status")
                      			objDevice.interface = "Seneye Temperature Device"
                      		Case 6
                      			objDevice = hs.NewDeviceEx(TN & " Current pH")
                      			objDevice.interface = "Seneye pH Device"
                      		Case 7
                      			objDevice = hs.NewDeviceEx(TN & " Average pH")
                      			objDevice.interface = "Seneye pH Device"
                      		Case 8
                      			objDevice = hs.NewDeviceEx(TN & " pH Trend")
                      			objDevice.interface = "Seneye pH Device"
                      		Case 9
                      			objDevice = hs.NewDeviceEx(TN & " pH Status")
                      			objDevice.interface = "Seneye pH Device"
                      		Case 10
                      			objDevice = hs.NewDeviceEx(TN & " Current NH3")
                      			objDevice.interface = "Seneye NH3 Device"
                      		Case 11
                      			objDevice = hs.NewDeviceEx(TN & " Average NH3")
                      			objDevice.interface = "Seneye NH3 Device"
                      		Case 12
                      			objDevice = hs.NewDeviceEx(TN & " NH3 Trend")
                      			objDevice.interface = "Seneye NH3 Device"
                      		Case 13
                      			objDevice = hs.NewDeviceEx(TN & " NH3 Status")
                      			objDevice.interface = "Seneye NH3 Device"
                      		Case 14
                      			objDevice = hs.NewDeviceEx(TN & " Current NH4")
                      			objDevice.interface = "Seneye NH4 Device"
                      		Case 15
                      			objDevice = hs.NewDeviceEx(TN & " Average NH4")
                      			objDevice.interface = "Seneye NH4 Device"
                      		Case 16
                      			objDevice = hs.NewDeviceEx(TN & " NH4 Trend")
                      			objDevice.interface = "Seneye NH4 Device"
                      		Case 17
                      			objDevice = hs.NewDeviceEx(TN & " NH4 Status")
                      			objDevice.interface = "Seneye NH4 Device"
                      		Case 18
                      			objDevice = hs.NewDeviceEx(TN & " Current O2")
                      			objDevice.interface = "Seneye O2 Device"
                      		Case 19
                      			objDevice = hs.NewDeviceEx(TN & " Average O2")
                      			objDevice.interface = "Seneye O2 Device"
                      		Case 20
                      			objDevice = hs.NewDeviceEx(TN & " O2 Trend")
                      			objDevice.interface = "Seneye O2 Device"
                      		Case 21
                      			objDevice = hs.NewDeviceEx(TN & " O2 Status")
                      			objDevice.interface = "Seneye O2 Device"
                      		Case 22
                      			objDevice = hs.NewDeviceEx(TN & " Current Lux")
                      			objDevice.interface = "Seneye Misc Device"
                      		Case 23
                      			objDevice = hs.NewDeviceEx(TN & " Current PAR")
                      			objDevice.interface = "Seneye Misc Device"
                      		Case 24
                      			objDevice = hs.NewDeviceEx(TN & " Current Kelvin")
                      			objDevice.interface = "Seneye Misc Device"
                      
                      	End Select
                      
                              objDevice.location = "Seneye Reef"
                              objDevice.hc = HC
                              objDevice.dc = Trim(Str(DC))
                              
                              objDevice.misc = &H10
                      
                      	objDevice.dev_type_string = "Seneye Parameter"
                      	
                      	hs.SetDeviceString(objDevice.hc & objDevice.dc, "New Seneye Device, awaiting data")
                              
                      	Log("Creating Device: " & HC & DC)
                      
                      	End If
                      
                      	DC += 1
                      Next
                      
                      End Sub

                      Comment


                        #12
                        It's working very nicely for me

                        Thanks again !

                        Comment


                          #13
                          Adding Tweet facility to Seneye

                          Hi All,
                          I am a newbie here & very very impressed by the postings on the thread.

                          I have a Seneye reef. Using Seneye API & Google scripts how do I create a Seneye Auto twitter bot which will tweet my aquarium parameters?

                          Any pointers?

                          Comment


                            #14
                            Seneye integration

                            Hi, I'm very new to Homeseer and need some help setting up the Seneye scripts / devices. I've cut/pasted the script (using notepad) into a file named System.XML and saved it in the scripts folder. Ive changed the login user/password and device ID to match my Seneye account.

                            I don't understand exactly what I need to add to the settings.ini or whether the devices are created by the script or if I need to create them manually.

                            Any help will be very appreciated.

                            Comment


                              #15
                              Originally posted by Baten View Post
                              Hi, I'm very new to Homeseer and need some help setting up the Seneye scripts / devices. I've cut/pasted the script (using notepad) into a file named System.XML and saved it in the scripts folder. Ive changed the login user/password and device ID to match my Seneye account.

                              I don't understand exactly what I need to add to the settings.ini or whether the devices are created by the script or if I need to create them manually.

                              Any help will be very appreciated.
                              I'd advise looking at Jon00's webpage http://www.jon00.me.uk/index.shtml, I believe he has a solution for Seneye on HomeSeer HS3, when this was written it was for HS2 which is why it might work in a fashion but is not ideal and a solution for HS3 is better.

                              Comment

                              Working...
                              X