Using JSON in HTML to switch scenes

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
sjdejong
Posts: 3
Joined: Sunday 27 December 2015 22:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Using JSON in HTML to switch scenes

Post 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
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Using JSON in HTML to switch scenes

Post by Egregius »

Try it with php. Take a look at the code of my floorplan, you'll have way more possibilities.
sjdejong
Posts: 3
Joined: Sunday 27 December 2015 22:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Using JSON in HTML to switch scenes

Post 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
pvm
Posts: 550
Joined: Tuesday 17 June 2014 22:14
Target OS: NAS (Synology & others)
Domoticz version: 4.10538
Location: NL
Contact:

Re: Using JSON in HTML to switch scenes

Post by pvm »

Synology NAS, slave PI3, ZWave (Fibaro), Xiaomi zigbee devices, BTLE plant sensor, DzVents, Dashticz on tablet, Logitech Media Server
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Using JSON in HTML to switch scenes

Post 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.
pvm
Posts: 550
Joined: Tuesday 17 June 2014 22:14
Target OS: NAS (Synology & others)
Domoticz version: 4.10538
Location: NL
Contact:

Re: Using JSON in HTML to switch scenes

Post by pvm »

Scenes do not have a on/off state right?
Synology NAS, slave PI3, ZWave (Fibaro), Xiaomi zigbee devices, BTLE plant sensor, DzVents, Dashticz on tablet, Logitech Media Server
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Using JSON in HTML to switch scenes

Post by Egregius »

Yes they do: On/Mixed/Off
But, I overlooked the scene part. For scenes indeed maybe not nescessary to see the status.
jannl
Posts: 675
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Using JSON in HTML to switch scenes

Post 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.
sjdejong
Posts: 3
Joined: Sunday 27 December 2015 22:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Using JSON in HTML to switch scenes

Post 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!
User avatar
Minglarn
Posts: 214
Joined: Friday 21 August 2015 19:27
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.8153
Location: Stockholm / Sweden
Contact:

Re: Using JSON in HTML to switch scenes

Post by Minglarn »

Nice and clean!! Me like! :)
Are you using frames or tables?


Sent from space using an app.
When you eliminate the impossible, whatever remains, however improbable, must be the truth.” -Spock in Star Trek VI
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Using JSON in HTML to switch scenes

Post 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
jannl
Posts: 675
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Using JSON in HTML to switch scenes

Post by jannl »

I know that, I even check that in my frontpage. But what is your point here?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest