Custom HS3 page for controlling lights with JSON

Homeseer Forum in het Nederlands (DUTCH forum)

Moderator: Ruud

Post Reply
Darwusch
Member
Member
Posts: 164
Joined: Sun Dec 21, 2008 10:25 pm
Location: Netherlands

Custom HS3 page for controlling lights with JSON

Post by Darwusch »

Hi,
I want to make a custom webpage in HS3 for controlling lights.
It seems JSON is the easiest method.
In the settings I enabled JSON control.
The url I was testing is:

Code: Select all

http://192.168.1.96:8082/JSON?request=controldevicebyvalue&ref=76&value=50
(HS3 runs at port 8082)

The lamp I tried had ref id 76 and I expected the lamp to switch on to 50%.
But it did not work.
All I get is the question if I want to download the file JSON.json (559 bytes).

What am I missing here?
User avatar
Phaeton
Advanced Member
Advanced Member
Posts: 573
Joined: Wed May 19, 2010 12:44 pm
Location: Wassenaar
Contact:

Re: Custom HS3 page for controlling lights with JSON

Post by Phaeton »

I open the page/link in a hidden div. Works great.

Verstuurd vanaf mijn M6752 met Tapatalk
groeten,
Harry
Darwusch
Member
Member
Posts: 164
Joined: Sun Dec 21, 2008 10:25 pm
Location: Netherlands

Re: Custom HS3 page for controlling lights with JSON

Post by Darwusch »

It did not work when I set it in an aspx page like this:

Code: Select all

hs.GetURL("http://192.168.1.96","/JSON?request=controldevicebyvalue&ref=76&value=50",true,8082)
Somehow this does not come trough.

The line after it however (which I put in as a test line) does work:

Code: Select all

hs.WriteLog("Test", "Button 1 from aspx")
Now I solved it with another command:

Code: Select all

hs.CAPIControlHandler(hs.CAPIGetSingleControl(76, false ,"50", false, true))
And this works :D
User avatar
Phaeton
Advanced Member
Advanced Member
Posts: 573
Joined: Wed May 19, 2010 12:44 pm
Location: Wassenaar
Contact:

Re: Custom HS3 page for controlling lights with JSON

Post by Phaeton »

Thats good to hear. Im curious what you interface looks like. If you want to, could you share screens? Could be a nice inspiration source

Verstuurd vanaf mijn M6752 met Tapatalk
groeten,
Harry
Darwusch
Member
Member
Posts: 164
Joined: Sun Dec 21, 2008 10:25 pm
Location: Netherlands

Re: Custom HS3 page for controlling lights with JSON

Post by Darwusch »

Ofcourse, but I don't have a nice screen yet.
I'm testing the functionallity first.

I use the code from the standard file "test.aspx" in the html directory.

Here is the code:

Code: Select all

<%@ Page Language="VB" %>
<script runat="server">

    ' Insert page code here
    '
    Dim hs As Scheduler.hsapplication
    Dim plugin As HomeSeerAPI.PluginAccess
    
    Sub Page_Load(Sender As Object, E As EventArgs)
        ' for use with the HS web server
        hs = Context.Items("Content")
        
        ' get a reference to the Z-Wave plugin
        plugin = New HomeSeerAPI.PluginAccess(hs, "Z-Wave", "")
        If plugin.Connected Then
            Label2.Text = "Connected to Z-Wave plugin, name=" & plugin.Name
        End If
        Label1.text = "HomeSeer Ver: " & hs.version
		
		Dim EN As Scheduler.Classes.clsDeviceEnumeration
		Dim dv As Scheduler.Classes.DeviceClass
        EN = hs.GetDeviceEnumerator
		Do
            dv = EN.GetNext
            If dv Is Nothing Then Continue Do
        Loop Until EN.Finished
    end sub
    
    Sub ButSpeak_Click(sender As Object, e As EventArgs)
        hs.speak(txtspeak.text,false,"")
		Dim EN As Scheduler.Classes.clsDeviceEnumeration
		Dim dv As Scheduler.Classes.DeviceClass
        EN = hs.GetDeviceEnumerator
		Do
            dv = EN.GetNext
            If dv Is Nothing Then Continue Do
		'	hs.WriteLog("SAMPLE", "Found device from aspx: " & dv.Name(Nothing))
        '    If dv.Interface(Nothing) IsNot Nothing Then
         '       If dv.Interface(Nothing).Trim = "Sample Plugin" Then
         '           hs.WriteLog("SAMPLE", "Found device from aspx: " & dv.Name(Nothing))
        '        End If
        '    End If
        Loop Until EN.Finished
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        'hs.ExecX10("L1", "on")
        'hs.GetURL("http://192.168.1.96","/JSON?request=controldevicebyvalue&ref=76&value=50",true,8082)
        hs.CAPIControlHandler(hs.CAPIGetSingleControl(76, true ,"off", false, true))
        hs.WriteLog("Test", "Button 1 from aspx")
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        'hs.ExecX10("L1", "off")
        'hs.GetURL("http://192.168.1.96:8082/JSON?request=controldevicebyvalue&ref=76&value=50","",true,8082)
        hs.CAPIControlHandler(hs.CAPIGetSingleControl(76, false ,"on", false, true))
        hs.WriteLog("Test", "Button 2 from aspx")
    End Sub
	
    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        'hs.ExecX10("L1", "off")
        'hs.GetURL("http://192.168.1.96:8082/JSON?request=controldevicebyvalue&ref=76&value=50","",true,8082)
        hs.CAPIControlHandler(hs.CAPIGetSingleControl(76, false ,"99", false, true))
        hs.WriteLog("Test", "Button 3 from aspx")
    End Sub
    
    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        'hs.ExecX10("L1", "off")
        'hs.GetURL("http://192.168.1.96:8082/JSON?request=controldevicebyvalue&ref=76&value=50","",true,8082)
        hs.CAPIControlHandler(hs.CAPIGetSingleControl(76, false ,"7", false, true))
        hs.WriteLog("Test", "Button 4 from aspx")
    End Sub    
    	
	Private Function GetHeadContent() As String
        Try
            Return hs.GetPageHeader("", "Test Page", "", "", False, False, True, False, False)
        Catch ex As Exception
        End Try
        Return ""
    End Function
	
	Private Function GetBodyContent() As String
        Try
            Return hs.GetPageHeader("", "Test Page", "", "", False, True, False, True, False)
        Catch ex As Exception
        End Try
        Return ""
    End Function
	
</script>
<html>
<head runat="server">
<!-- <%response.write(GetHeadContent())%> -->
</head>
<body>
<!-- <% response.write(GetBodyContent()) %> -->
    <form runat="server">
        <p>
            <asp:Label id="Label1" runat="server" width="210px">Label X</asp:Label>
        </p>
        <p>
            <asp:Label id="Label2" runat="server" width="400px">Label plugin</asp:Label>
        </p>
        <p>
        </p>
        <p>
            <asp:Button id="ButSpeak" onclick="ButSpeak_Click" runat="server" Text="Speak"></asp:Button>
            <asp:TextBox id="TxtSpeak" runat="server"></asp:TextBox>
        </p>
        <br><br><br>
        <p>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Light off" Width="300" Height="50" font-size="32px" />
        </p>
        <br><br>
        <p>
            <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Light last dim state" Width="300" Height="50" font-size="32px" />
        </p>
        <br><br>
        <p>
            <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Light 99%" Width="300" Height="50" font-size="32px" />
        </p>   
        <br><br>     
        <p>
            <asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="Light 7%" Width="300" Height="50" font-size="32px" />&nbsp;</p>
        
        <!-- Insert content here -->
    </form>
</body>
</html>

Darwusch
Member
Member
Posts: 164
Joined: Sun Dec 21, 2008 10:25 pm
Location: Netherlands

Re: Custom HS3 page for controlling lights with JSON

Post by Darwusch »

I still have a strange issue.

When I choose the "on" state, it Always turns on to the last dim state.
I can not set it to go on at 100%, that does nothing.
The only option I see is set it to 99% to come close to it.

Is there some option (in the booleans maybe) to use the "on" state for the 100% level?
raymonvdm
Senior Member
Senior Member
Posts: 1153
Joined: Sun Dec 18, 2011 1:23 am

Re: Custom HS3 page for controlling lights with JSON

Post by raymonvdm »

I`m using JSON for my NFC tag scanner (AutomateIT APP on Android) and i just call the url with a browser to fire the event

Code: Select all

http://username:password@192.168.1.240:8080/JSON?user=username&pass=password&request=runevent&group=Leven&name=Ik_Ga_Douchen_JSON
Running HS3PRO on PC with Z-Wave / OpenTherm / Plugwise / RFXcom / MQTT / XAP400 / Logitech Media Server and Squeezelite on PI`s
Post Reply

Return to “Homeseer algemeen Forum”