Page 1 of 1

Using JSON in HTML to switch scenes

Posted: Sunday 27 December 2015 22:18
by sjdejong
Hi Guys,

First and foremost, i love Domoticz and i specially love the community around this epic system.

I have been lurking on the forums for a while, but never needed to register. But the time has come that a question rised:

I have created a custom html page that exactly fits the tablet that i have mounted to the wall. Within this HTML file, i would like to use the JSON URL's to toggle scenes on and off. Right now, i have created a page with two sections (for horizontal scrolling) that contain several buttons as well as the weather forecast and a block that shows the actual IP-cam footage to see who's at my door (jpeg that refreshes every 2 seconds).

screenshot:

Image

The issue i have is with the JSON toggles. They do work, but the problem is that the hyperlink takes me to the JSON output page. What i would like to see is that i just toggles the switch, and does not take me to the status page.

Can someone point me into the right direction? here's a section of my code snippet that shows the toggle button of one of the scenes:

Code: Select all

<div id="button">
    <a href="http://domotica.pb67.lan:8080/json.htm?type=command&param=switchscene&idx=1&switchcmd=on"><img src="eettafel.jpg"></img></a>
</div>

Cheers!
Sjoerd

Re: Using JSON in HTML to switch scenes

Posted: Sunday 27 December 2015 22:35
by Egregius
Try it with php. Take a look at the code of my floorplan, you'll have way more possibilities.

Re: Using JSON in HTML to switch scenes

Posted: Sunday 27 December 2015 23:27
by sjdejong
Allright, will have a look at it, thanks!

But is there a way to use the JSON API to call the toggle url, but not open the status page? Do i need to use a POST or PUT method? and how can this be done?


Best regards,
Sjoerd

Re: Using JSON in HTML to switch scenes

Posted: Monday 28 December 2015 1:07
by pvm

Re: Using JSON in HTML to switch scenes

Posted: Monday 28 December 2015 6:58
by Egregius
I don't think that the toggle url is the proper way to handle things. It's better to first ask the current status of the desired switches (use a roomplan for speed) and then show a on/off button depending on the state.

Re: Using JSON in HTML to switch scenes

Posted: Monday 28 December 2015 7:58
by pvm
Scenes do not have a on/off state right?

Re: Using JSON in HTML to switch scenes

Posted: Monday 28 December 2015 8:28
by Egregius
Yes they do: On/Mixed/Off
But, I overlooked the scene part. For scenes indeed maybe not nescessary to see the status.

Re: Using JSON in HTML to switch scenes

Posted: Monday 28 December 2015 9:00
by jannl
Scenes do not have an on off state. You set a scene and later you set another scene. Groups can be switched on and off.

What is the off state of a scene? All off? Previous setting? What if something was changed in between? Makes no sense to switch off a scene.

Re: Using JSON in HTML to switch scenes

Posted: Monday 28 December 2015 21:38
by sjdejong
vil1driver wrote:+1
scene = only On
group = on/mixed/off


Code: Select all

<script>
function SceneToggle()
{
         $.ajax({
				 url: 'http://domotica.pb67.lan:8080/json.htm?type=command&param=switchscene&idx=1&switchcmd=on&level=0',
				 success: function(){
					console.log('SUCCES');
					
				 },
				 error: function(){
					console.log('ERROR');
				 }
		});
}
</script>
<div id="button">
    <img src="eettafel.jpg" onclick="SceneToggle()"></img>
</div>
EPIC!

I just used your method, works like a charm! Thanks a lot!

This is my current controller (tablet on the wall):

Image

Planning on much more functions (watering the garden, more lightswitches, etc), so the unused buttons, and next page of unused buttons will be filled in the upcoming year.

Thanks again!

Re: Using JSON in HTML to switch scenes

Posted: Tuesday 29 December 2015 6:03
by Minglarn
Nice and clean!! Me like! :)
Are you using frames or tables?


Sent from space using an app.

Re: Using JSON in HTML to switch scenes

Posted: Tuesday 29 December 2015 7:05
by Egregius
jannl wrote:Scenes do not have an on off state. You set a scene and later you set another scene. Groups can be switched on and off.

What is the off state of a scene? All off? Previous setting? What if something was changed in between? Makes no sense to switch off a scene.
You can't turn off a scene, then you need a group.
But, they do have a on/mixed/off status depending of the devices in the scene.

Image
Image
Image

Re: Using JSON in HTML to switch scenes

Posted: Wednesday 30 December 2015 7:34
by jannl
I know that, I even check that in my frontpage. But what is your point here?