Announcement

Collapse
No announcement yet.

json request device value

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

    json request device value

    what command to use to get the device value ?

    i try this one but it shows everything , i only want the device value , is it possible ?


    http://192.168.0.12/JSON?request=getstatus&ref=933


    or is there a way to change the text of a device status ?

    thanks in advance !
    Last edited by Malosa; August 14, 2015, 04:01 PM.
    Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
    Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




    HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

    #2
    Did you figure out this one? I just started playing with the json api but struggle like you do. I try to build a simple aspx page showing device values.

    Comment


      #3
      I have only used JSON for sending but I would assume that get would be similar. I'm pretty sure you can only get a value, not a status!

      Try get value.

      Steve Q
      HomeSeer Version: HS3 Pro Edition 3.0.0.368, Operating System: Microsoft Windows 10 - Home, Number of Devices: 373, Number of Events: 666, Enabled Plug-Ins
      2.0.83.0: BLRF, 2.0.10.0: BLUSBUIRT, 3.0.0.75: HSTouch Server, 3.0.0.58: mcsXap, 3.0.0.11: NetCAM, 3.0.0.36: X10, 3.0.1.25: Z-Wave,Alexa,HomeKit

      Comment


        #4
        Originally posted by Steve Q View Post
        I have only used JSON for sending but I would assume that get would be similar. I'm pretty sure you can only get a value, not a status!

        Try get value.

        Steve Q
        I figured it out by asking google :P So I'm up and running with a start now.

        Comment


          #5
          Can you please post an example?


          Sent from my iPad using Tapatalk
          HomeSeer Version: HS3 Pro Edition 3.0.0.368, Operating System: Microsoft Windows 10 - Home, Number of Devices: 373, Number of Events: 666, Enabled Plug-Ins
          2.0.83.0: BLRF, 2.0.10.0: BLUSBUIRT, 3.0.0.75: HSTouch Server, 3.0.0.58: mcsXap, 3.0.0.11: NetCAM, 3.0.0.36: X10, 3.0.1.25: Z-Wave,Alexa,HomeKit

          Comment


            #6
            Originally posted by Steve Q View Post
            Can you please post an example?


            Sent from my iPad using Tapatalk
            Here is an example.. This one has a gauge as well but it is the function getvalue() that gets the value of a device.

            Code:
            <title>Aqua Gauge - HTML5</title>
            <link rel="stylesheet" href="css/styles.css">
            <link rel="stylesheet" href="css/smoothness/jquery-ui-1.8.16.custom.css">
            <script src="js/jquery-1.6.2.min.js" type="text/javascript"></script>
            <script src="js/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
            <script src="js/AquaGauge.js" type="text/javascript"></script>
            <script src="js/helper.js" type="text/javascript"></script>
            
            <script language="javascript" type="text/javascript">
            var i = 7;
            var Status = 0.0;
            function showGauge(mottatt) 
            {
                var aGauge = new AquaGauge('gauge');
                aGauge.props.minValue = 0;
                aGauge.props.maxValue = 30;
                aGauge.refresh(mottatt);
            }
            function getvalue()
            {
                var DeviceID = 327;
            	var Navn = "";
                var aGauge = new AquaGauge('gauge');
                var xhr1 = new XMLHttpRequest();
                xhr1.open('GET', '/JSON?request=getstatus&ref=' + DeviceID, true); 
                xhr1.send(null);
                xhr1.onreadystatechange = function() 
            	{
                    if (xhr1.readyState == 4) 
            		{
                        Status=JSON.parse(xhr1.responseText).Devices[0].value;
            			Navn = JSON.parse(xhr1.responseText).Devices[0].name;
                    }
                }
            	showGauge(Status);
            	i++;
            }
            setInterval(getvalue, 500)
            	 
            
            </script>
            </head>
            <body  onload = "showGauge(); getvalue()">
            <div class="header">HTML5 Canvas - Gauge Control</div>
            <div style="text-align: center; width: 100%; padding: 10px;">
                <canvas id="gauge" width="300" height="300">Browser not supported.</canvas>
            </div>
            </body>
            </html>
            Maybe not straight forward understanding the code but just ask if you wonder.

            //Morten

            Comment


              #7
              Thanks, this is way above my skill level! I am just using some basic vbscript to move a HS3 device value from one computer to another.


              Sent from my iPad using Tapatalk
              HomeSeer Version: HS3 Pro Edition 3.0.0.368, Operating System: Microsoft Windows 10 - Home, Number of Devices: 373, Number of Events: 666, Enabled Plug-Ins
              2.0.83.0: BLRF, 2.0.10.0: BLUSBUIRT, 3.0.0.75: HSTouch Server, 3.0.0.58: mcsXap, 3.0.0.11: NetCAM, 3.0.0.36: X10, 3.0.1.25: Z-Wave,Alexa,HomeKit

              Comment


                #8
                Originally posted by Steve Q View Post
                Thanks, this is way above my skill level! I am just using some basic vbscript to move a HS3 device value from one computer to another.


                Sent from my iPad using Tapatalk
                Here it is really simplified. Just pulling the device name and value from a single device:

                Code:
                <!DOCTYPE html>
                <html>
                <head>
                <title>Test values</title>
                <script language="javascript" type="text/javascript">
                function getvalue()
                {
                    var DeviceID = 327; <!-- ID of the device to get data from. This is the id of the subdevice, in this case watts from my qubino dimmer. -->
                	var Navn = "";  <!-- Define variable for holding the device name -->
                	var Status = 0.0; <!-- Define variable for holding the device value -->
                    var xhr1 = new XMLHttpRequest();
                    xhr1.open('GET', '/JSON?request=getstatus&ref=' + DeviceID, true);  <!--Request devicedata. 
                    xhr1.send(null);
                    xhr1.onreadystatechange = function() 
                	{
                        if (xhr1.readyState == 4) 
                		{
                            Status=JSON.parse(xhr1.responseText).Devices[0].value; <!--Get the value of the device -->
                			Navn = JSON.parse(xhr1.responseText).Devices[0].name; <!-- Get the name of the device -->
                            var el = document.getElementById('retrieved');
                            el.innerHTML = 'the status of device : ' + Navn + ' is ' + Status; <!--Build string for showing. This is displayed in the div tag with id "retreived" -->        }
                    }
                }
                setInterval(getvalue, 500)
                </script>
                
                
                </head>
                <body onload="getvalue()">
                <div id='retrieved'></div>
                		
                		
                </body>
                </html>
                Tried to add some comments as well. If you just paste this into an aspx page and change the deviceid it should work. (If that device you change to has both name and value property). It is really not dificult.

                Comment


                  #9
                  I am learning as well on this... I am assuming this is created as a webpage you call? Like http://IISServer/json.html? And going to this page invokes the json?

                  Comment


                    #10
                    Originally posted by waynehead99 View Post
                    I am learning as well on this... I am assuming this is created as a webpage you call? Like http://IISServer/json.html? And going to this page invokes the json?
                    I have created a webpage called test.aspx and put it in the html folder.
                    The /json part is built in functionality in HS. If you add:
                    /JSON?request=getstatus&ref=349 after the address to your HS-server you can see what the query returns.

                    However I saw a couple of errors in my script. Here is a working one that I tested:

                    Code:
                    <!DOCTYPE html>
                    <html>
                    <head>
                    <title>Test values</title>
                    </head>
                    <body>
                    <div class='wrapper' style='text-align: center;'>
                      <h1>Instant value </h1> 
                      <FORM NAME='form1'>
                    	<INPUT TYPE='button' NAME='bouton' VALUE='Click-me for Request' onClick='getvalue()'>
                      </FORM>
                      <BR><BR>
                    
                    	<div id='retrieved'></div>
                    </div>
                    
                    <script language="javascript" type="text/javascript">
                    function getvalue()
                    {
                        var DeviceID = 327; 
                    	var Navn = "";  
                    	var Status = 0.0;
                        var xhr1 = new XMLHttpRequest();
                        xhr1.open('GET', '/JSON?request=getstatus&ref=' + DeviceID, true);
                        xhr1.send(null);
                        xhr1.onreadystatechange = function() 
                    	{
                            if (xhr1.readyState == 4) 
                    		{
                                Status=JSON.parse(xhr1.responseText).Devices[0].value; 
                    			Navn = JSON.parse(xhr1.responseText).Devices[0].name; 
                                var el = document.getElementById('retrieved');
                                el.innerHTML = 'the status of device : ' + Navn + ' is ' + Status; 
                    		}
                        }
                    }
                    setInterval(getvalue, 500)
                    
                    </script>		
                    </body>
                    </html>
                    In my case, HS runs at IP 192.168.1.26, so if I run:
                    http://192.168.1.26/JSON?request=getstatus&ref=327 I get the following in my browser:
                    Code:
                    {"Name":"HomeSeer Devices","Version":"1.0","Devices":[{"ref":327,"name":"Lysbryter - Spotter - Forbruk","location":"Midtstue","location2":"1. Etasje","value":13.3,"status":"13,300 Watts","device_type_string":"Z-Wave Watts","last_change":"\/Date(1454443390207)\/","relationship":4,"hide_from_view":false,"associated_devices":[323],"device_type":{"Device_API":256,"Device_API_Description":"Energy API","Device_Type":1,"Device_Type_Description":"Watts","Device_SubType":50,"Device_SubType_Description":""},"device_image":"","UserNote":"","UserAccess":"Any","status_image":"/images/HomeSeer/status/electricity.gif"}]}
                    Here are all the variables you can get from that device by using the code in the example. Getting the values are done by the codeline:
                    Code:
                    Status=JSON.parse(xhr1.responseText).Devices[0].value;
                    This one requests the value: and puts in this case 13.3 into the variable Status

                    Comment


                      #11
                      Thanks, this is very useful info. I tried the http://192.168.1.xx/JSON?request=getstatus&ref=xx And it returns lots of information. I assume your script is parsing this information and returning the value.

                      How would I put the returned value into another HS3 device?


                      Sent from my iPad using Tapatalk
                      HomeSeer Version: HS3 Pro Edition 3.0.0.368, Operating System: Microsoft Windows 10 - Home, Number of Devices: 373, Number of Events: 666, Enabled Plug-Ins
                      2.0.83.0: BLRF, 2.0.10.0: BLUSBUIRT, 3.0.0.75: HSTouch Server, 3.0.0.58: mcsXap, 3.0.0.11: NetCAM, 3.0.0.36: X10, 3.0.1.25: Z-Wave,Alexa,HomeKit

                      Comment


                        #12
                        Originally posted by Steve Q View Post

                        How would I put the returned value into another HS3 device?


                        Sent from my iPad using Tapatalk
                        This I haven't tried yet. But I bet there is something in the homeseer json documentation about this. I might look into it later today. This is a "learning-by-doing" project for me as I'm not good at programming

                        Comment


                          #13
                          Below is a simple vbnet script that uses JSON to get the value of an HS3 device. I am using to get the value of Device 360 on my test computer which is also running HS3. The device is a counter which is keeping track of the number of minutes my well has been ON.

                          The script parses the value from the JSON packet.

                          Below is also a screen photo of the log entry created by the script.

                          Perhaps you will find this useful.

                          ------------------------------------------------------------------------------------
                          'Test Script for HS3 using JSON to get the value of device 360 on the Acer computer
                          ' written by S Quinlan 2/5/2016
                          '
                          'working on 2/5/2016

                          Imports system.io
                          Imports Microsoft.VisualBasic.Compatibility.VB6

                          Sub Main(ByVal Parm As Object)

                          dim Val1,page
                          dim pos1,pos2 as string

                          '---------Get JSON page Contents--------------------------

                          page=hs.geturl("http://192.168.1.99:85/JSON?request=getstatus&ref=360","",true,80)
                          'hs.writelog("Device 360 Contains",page)

                          pos1=instr(page,"value")+7
                          pos2=instr(page,"status")-2
                          Val1=Mid(page,pos1,pos2-pos1)

                          hs.writelog("HS3 Acer-Device 360 Value",Val1)

                          end sub
                          ----------------------------------------------------------------------
                          Attached Files
                          HomeSeer Version: HS3 Pro Edition 3.0.0.368, Operating System: Microsoft Windows 10 - Home, Number of Devices: 373, Number of Events: 666, Enabled Plug-Ins
                          2.0.83.0: BLRF, 2.0.10.0: BLUSBUIRT, 3.0.0.75: HSTouch Server, 3.0.0.58: mcsXap, 3.0.0.11: NetCAM, 3.0.0.36: X10, 3.0.1.25: Z-Wave,Alexa,HomeKit

                          Comment

                          Working...
                          X