Page 1 of 1

Disable switch via JSON

Posted: Monday 06 March 2017 12:11
by nfaber
I was wondering whether it is possible to temporarily disable a switch through scripting.

Here's my situation:
- I have a window that has a roller shutter mounted on the outside, which can be operated through Domoticz and also has a fixed timer to close at night.
- My window can be opened, in this case the shutter should never operate (else the roller shutter will get damaged, this already happened once).
- My window has a magnetic sensor that can detect whether the window is open or closed.

Ideally i would like to use JSON scripting to set a property for the shutter switch that blocks all operations (manual control, macros and timers) when the window is opened.

I know that it is possible to disable the execution of timers, but this is only a partial solution for me (doesn't affect manual control or macros).
Also i could include a virtual switch that first checks the sensor status and then operates the shutter device, but I consider this a dirty solution.
I already tried using an 'On action' for the shutter that quickly opens it again when the window sensor is triggered, but this was unreliable.

Any suggestions?

Re: Disable switch via JSON

Posted: Monday 06 March 2017 13:37
by RayAmsterdam
Why do you consider the virtual switch solution as dirty? I think, in combination with a script or blocky, that's the way to go.

Re: Disable switch via JSON

Posted: Monday 06 March 2017 13:50
by Egregius
I would have guessed these commands:

Code: Select all

http://192.168.2.10:8084/json.htm?type=setused&idx=329&used=true
http://192.168.2.10:8084/json.htm?type=setused&idx=329&used=false
Unfortunaly there's a bug, the second command doesn't disable the device, it removes the device entirely! Wish I tested with a unused device, now I have to exclude/include again...

Anyway, when u use the developer view of a good browser you should be able to find the commands.
A bit more fiddling gave me these:

Code: Select all

http://192.168.2.10:8084/json.htm?type=setused&idx=328&protected=false&used=true
http://192.168.2.10:8084/json.htm?type=setused&idx=328&protected=true&used=true
When the switch is 'protected' you can't switch it anymore. Don't know how LUA/blockly responds to this, the JSON api requires the pincode to switch.

Re: Disable switch via JSON

Posted: Monday 06 March 2017 18:33
by nfaber
Egregius wrote: Anyway, when u use the developer view of a good browser you should be able to find the commands.
A bit more fiddling gave me these:

Code: Select all

http://192.168.2.10:8084/json.htm?type=setused&idx=328&protected=false&used=true
http://192.168.2.10:8084/json.htm?type=setused&idx=328&protected=true&used=true
When the switch is 'protected' you can't switch it anymore. Don't know how LUA/blockly responds to this, the JSON api requires the pincode to switch.
You're a life-saver!
This set of commands works excellent for disabling/enabling operation of the switch.
I found out that the timers are still fired with protected=true, therefor i added a command to temporarily disable all timers of the device as well.
This was exactly what i was looking for, problem fixed!

Re: Disable switch via JSON

Posted: Wednesday 23 August 2017 16:16
by zaphodus
You can set device unused, with this command:

http://192.168.2.10:8084/json.htm?type=setunused&idx=6

Re: Disable switch via JSON

Posted: Wednesday 11 December 2019 17:01
by jellex87
Dear all,

I know this is an old topic, but i'm planning to do the exact same thing as TS.

Plan is to block scripts and switches for closing blinds in Domoticz when the windows are open. I allready had a damaged blind when my little daughter get the hand at a switch ;) . Idea is to use 433mhz windowsensors from China.
I'm not a programmer, but learning Blockly a little bid. JSON is completely new for me and I have no idea how to use this.

Can someone explain what the best (easiest?) way is to implement this in my situation?
I'm using Domoticz on a Synology 213 and a RFXCOM.

Re: Disable switch via JSON

Posted: Friday 22 May 2020 21:36
by jellex87
Ordered a KERUI sensor, but still looking for a way to program this. What do you guys think is best?

Re: Disable switch via JSON

Posted: Sunday 23 August 2020 15:11
by jellex87
nfaber wrote: Monday 06 March 2017 18:33
Egregius wrote: Anyway, when u use the developer view of a good browser you should be able to find the commands.
A bit more fiddling gave me these:

Code: Select all

http://192.168.2.10:8084/json.htm?type=setused&idx=328&protected=false&used=true
http://192.168.2.10:8084/json.htm?type=setused&idx=328&protected=true&used=true
When the switch is 'protected' you can't switch it anymore. Don't know how LUA/blockly responds to this, the JSON api requires the pincode to switch.
You're a life-saver!
This set of commands works excellent for disabling/enabling operation of the switch.
I found out that the timers are still fired with protected=true, therefor i added a command to temporarily disable all timers of the device as well.
This was exactly what i was looking for, problem fixed!
I did the same thing and the individual switch of the blind is disabled the right way. So far so good. But the groups with the same switch (blind) in it keeps working, so that is a problem. What is the best solution to disable the switch AND the group. Or better: only disable the blind of the window in the group which is open at that moment.

Anyone who can put me in the right direction?

Re: Disable switch via JSON

Posted: Sunday 23 August 2020 23:54
by waaren
jellex87 wrote: Sunday 23 August 2020 15:11 Anyone who can put me in the right direction?
Don''t think the best solution for this is to set a device to unused but if you cannot prevent the triggering of the device in another way:

API for setting a device to unused:

Code: Select all

http://<domoticzIP:domoticzPort>/json.htm?idx=<IDX>&param=setunused&type=command
And to set a device back to used:

Code: Select all

http://<domoticzIP:domoticzPort>/json.htm?idx=<IDX>&name=<newName>&type=setused&used=true
or

Code: Select all

http://<domoticzIP:domoticzPort>/json.htm?idx=<IDX>&type=setused&used=true

Re: Disable switch via JSON

Posted: Monday 24 August 2020 13:11
by jellex87
waaren wrote: Sunday 23 August 2020 23:54
jellex87 wrote: Sunday 23 August 2020 15:11 Anyone who can put me in the right direction?
Don''t think the best solution for this is to set a device to unused but if you cannot prevent the triggering of the device in another way:

API for setting a device to unused:

Code: Select all

http://<domoticzIP:domoticzPort>/json.htm?idx=<IDX>&param=setunused&type=command
And to set a device back to used:

Code: Select all

http://<domoticzIP:domoticzPort>/json.htm?idx=<IDX>&name=<newName>&type=setused&used=true
or

Code: Select all

http://<domoticzIP:domoticzPort>/json.htm?idx=<IDX>&type=setused&used=true

Thanks for your reply. I allrady managed to set the blinds (switches) to unused via the 'on action' off a dummy. The problem is that the switch keeps active in groups. So when I activate a group, the blind which is set to unused or protected still moves.
Is there a better way to program this?

Re: Disable switch via JSON

Posted: Monday 24 August 2020 13:41
by waaren
jellex87 wrote: Monday 24 August 2020 13:11 Is there a better way to program this?
My approach would be to control the blinds via dzVents.

in pseudo code:

-- for single blind: create a dummy blind1Control switch
if blind1Control == On then
if window1Contact == Closed then blind1.close else alert 'Window1 still open' end
else
blind1.Open
end


-- For set of blinds: Create an empty blindsControl group


if blindsControlGroup == On then
if window1Contact == Closed then blind1.close else alert 'window 1 still open' end
if window2Contact == Closed then blind2.close else alert 'window 2 still open' end
else
blind1.Open
blind2.Open
end

Re: Disable switch via JSON

Posted: Monday 24 August 2020 15:33
by jellex87
waaren wrote: Monday 24 August 2020 13:41
jellex87 wrote: Monday 24 August 2020 13:11 Is there a better way to program this?
My approach would be to control the blinds via dzVents.
Ok. Seems like I have to dig into dzVents. I'm not a programmer at all and everything is new for me. Is it doable for a noob? :ugeek:

Re: Disable switch via JSON

Posted: Monday 24 August 2020 17:29
by waaren
jellex87 wrote: Monday 24 August 2020 15:33 Ok. Seems like I have to dig into dzVents. I'm not a programmer at all and everything is new for me. Is it doable for a noob? :ugeek:
Only one way to find out. :)
I suggest you start with some virtual devices on dummy hardware and ask for help here if your script does not work as expected in that set-up. If everything works as expected rename to the real blinds and contacts.

Re: Disable switch via JSON

Posted: Sunday 20 September 2020 14:21
by jellex87
Well, I tried a lot but can't get Dzvents to work. Nothing happens. I already did the following things:
- Checked settings. (see screenshots)
- Tried the 'testscript' from the Quickstart wiki.
- Tried with a regular switch and a dummy.

Result is nothing in de logs. Only the confirmation of the saving of the script is written.
What am I overlooking?
please help this noob ;)

Re: Disable switch via JSON

Posted: Monday 21 September 2020 12:44
by waaren
jellex87 wrote: Sunday 20 September 2020 14:21 Result is nothing in de logs. Only the confirmation of the saving of the script is written.
What am I overlooking?
You are on a very old version of domoticz. Can you upgrade?
If not try to switch the 'niet actief' selections. I think I remember that something was not translated properly in this version but don't know for sure, which one (or both)

Re: Disable switch via JSON

Posted: Monday 21 September 2020 13:51
by jellex87
I'm using a Synology 213 NAS and I remember reading this is not supported anymore. Do you know what's the latest version I can use with my hardware?
Everything else works perfect...

I will try to switch the checkboxes of 'niet actief', but the Wiki says they have to be unchecked, so I did.
All other settings are good?

Re: Disable switch via JSON

Posted: Monday 21 September 2020 14:17
by waaren
jellex87 wrote: Monday 21 September 2020 13:51 I'm using a Synology 213 NAS and I remember reading this is not supported anymore. Do you know what's the latest version I can use with my hardware?
Everything else works perfect...
Sorry you will have to ask @jadahl
I will try to switch the checkboxes of 'niet actief', but the Wiki says they have to be unchecked, so I did.
All other settings are good?
Yes

Re: Disable switch via JSON

Posted: Saturday 17 October 2020 17:21
by jellex87
Finally I managed to got it working. I completely deleted the package and reinstalled the latest package available for my CPU.
I ran the test script from the Wiki and the logs let me know that it works.
Now going to learn some scripting... :shock: