Page 1 of 1

JSON URL to update on/off action field of a switch

Posted: Tuesday 28 November 2017 10:30
by inzuno
Hello,

I want to know if there's a way to update on/off action field of a switch using JSON URL.
I had a look here but I didn't find anything: https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's

I need this because I'm using ESPeasy with esp8266 controlling a relay with a virtual device in Domoticz, and I want to automatically update IP in the on/off action (or the complete field).
I already automatically report IP in Domoticz using user variables and a text dummy, I can use it if necessary.

Thanks!

Re: JSON URL to update on/off action field of a switch

Posted: Tuesday 28 November 2017 19:05
by Amsterdam020
Https://www.domoticz.com/wiki/Domoticz_ ... Fswitch_on

Are you looking for this???

Turn a light/switch on
/json.htm?type=command&param=switchlight&idx=99&switchcmd=On

Turn a light/switch off
/json.htm?type=command&param=switchlight&idx=99&switchcmd=Off

idx = id of your device (in this example 99).
switchcmd = "On" or "Off" (case sensitive!)

Re: JSON URL to update on/off action field of a switch

Posted: Tuesday 28 November 2017 19:08
by Egregius
Can't you set a static ip on espeasy?

If not, use the developer view of your browser to find what's being sent while updating a device.

Re: JSON URL to update on/off action field of a switch

Posted: Tuesday 28 November 2017 20:00
by inzuno
@Amsterdam020 Thanks, but I know how to trigger the switch of domoticz :D
@Egregius Of course I could, but I don't want. This would be too easy and my ISP router is a mess and I don't want it to manage Static IPs. :geek:

I really want to dynamically update on/off action in domoticz with the IP provided by EPSeasy

Thanks

Re: JSON URL to update on/off action field of a switch

Posted: Tuesday 28 November 2017 21:17
by Westcott
I connect to my ESPeasy devices by IP NAME as set in Config -> Name

Re: JSON URL to update on/off action field of a switch

Posted: Tuesday 28 November 2017 21:38
by inzuno
Hello,

@Westcott
Unfortunately I never managed to make this work on my network. How do you make it work in domoticz?

Re: JSON URL to update on/off action field of a switch

Posted: Tuesday 28 November 2017 21:59
by Westcott
Hi Inzuno,
It just worked for me, I didn't have to do anything special.
My Espeasy version is 147.
Can you connect to any of your ESPs with a web browser and IP name?

Re: JSON URL to update on/off action field of a switch

Posted: Tuesday 28 November 2017 22:46
by Nautilus
As for the original question, did you check the network tab in the developer mode when updating? I get this:

Code: Select all

http://ip:port/json.htm?type=setused&idx=IDX&name=NAME&description=&strparam1=c2NyaXB0Oi8vL3Rlc3Q=&strparam2=&protected=false&switchtype=0&customimage=0&used=true&addjvalue=0&addjvalue2=0&options=
For you the interesting parts are strparam1 (On) and strparam2 (Off, I assume). In this example strparam1 = c2NyaXB0Oi8vL3Rlc3Q and when you decode that with base64 (https://www.base64decode.org/) you get script:///test which was my test "On action". So when updating on/off actions with json, first encode to base64 and then use it in strparam1/strparam2...

Re: JSON URL to update on/off action field of a switch

Posted: Wednesday 29 November 2017 10:07
by inzuno
@Nautilus Thanks a lot! This is working like a charm! I never used network tab before, I will use it more now!

I reduced parameters to the minimum for updating action fields:

Code: Select all

IP:PORT/json.htm?type=setused&idx=IDX&strparam1=aHR0cDovLzE5Mi4xNjguMS4yNDcvY29udHJvbD9jbWQ9R1BJTywwLDE=&strparam2=aHR0cDovLzE5Mi4xNjguMS4yNDcvY29udHJvbD9jbWQ9R1BJTywwLDA=&used=true
Now I need to dynamically convert action to base 64 and automatically build url... maybe with a lua script in domoticz?

@Westcott
Yes I tried directly in my web browser, and nothing... Will try to do with V147. Thanks!

I will let you know my progress in this post.

Thanks again guys! 8-)