API/JSON URL to set options for a Counter Sensor

Moderator: leecollings

Post Reply
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

API/JSON URL to set options for a Counter Sensor

Post by BakSeeDaa »

Hi there.

I can create a counter device using the following URL:

Code: Select all

json.htm?type=createvirtualsensor&idx=999999&sensorname=MyCounter&sensortype=113
Then I can set further properties for that device using the following URL:

Code: Select all

json.htm?type=setused&idx=421&name=MyCounter&description=Some description&switchtype=3&addjvalue=0&used=true&options=VmFsdWVRdWFudGl0eSUzQUNvdW50JTNCVmFsdWVVbml0cyUzQSUzQg==
But I have no idea what that string is following "&options=" and how I can construct one. I'd like to set the values for "Value Quantity (e.g. Weight)" to "Time "and "Value Units (e.g. Kg)" to "h" by using a script.

If You think You can help me, I'd appreciate it a lot. Thanks :)
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: API/JSON URL to set options for a Counter Sensor

Post by stlaha2007 »

I'm wandering; where did you get that info from? Just looked at the wiki JSON-API at counter, however i dont see other values being specified... It looks interresting. Have some devices which i also want to get into and updated in Domoticz by scripts.

Sent from my K00C using Tapatalk
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: API/JSON URL to set options for a Counter Sensor

Post by BakSeeDaa »

stlaha2007 wrote:I'm wandering; where did you get that info from? Just looked at the wiki JSON-API at counter, however i dont see other values being specified... It looks interresting. Have some devices which i also want to get into and updated in Domoticz by scripts.

Sent from my K00C using Tapatalk
While performing the task You like to find the JSON command for in the browser, use the "Inspect element' feature of your browser (right mouse click an area), choose the "Network" tab. Doing that, You may find out which Json command is being sent.
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: API/JSON URL to set options for a Counter Sensor

Post by stlaha2007 »

Using FireFox mostly and getting used to the Inspect option.
The way you figured out does me think of tryin to create the counter from hardware or even better the custom sensor and fill in some 'know parameters' like electricity/gas/temp(-hum-baro). Perhaps thats what gonna explain in more detail how these have to look like...

I kind of hoped that Gizmocuz replied already with some details. As i can imagine that it needs some formatting-logic behind the scenes.

Sent from my K00C using Tapatalk
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: API/JSON URL to set options for a Counter Sensor

Post by BakSeeDaa »

stlaha2007 wrote:Using FireFox mostly and getting used to the Inspect option.
The way you figured out does me think of tryin to create the counter from hardware or even better the custom sensor and fill in some 'know parameters' like electricity/gas/temp(-hum-baro). Perhaps thats what gonna explain in more detail how these have to look like...

I kind of hoped that Gizmocuz replied already with some details. As i can imagine that it needs some formatting-logic behind the scenes.

Sent from my K00C using Tapatalk
I guess I might have a look in the source code trying to figure out what the VmFsdWVRdWFudGl0eSUzQUNvdW50JTNCVmFsdWVVbml0cyUzQSUzQg== string is.
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: API/JSON URL to set options for a Counter Sensor

Post by BakSeeDaa »

The answer to my question was in the source code.

Code: Select all

'&options=' + btoa(encodeURIComponent(devOptionsParam.join('')))
It's a ASCII string that has been URL encoded and Base64 encoded

VmFsdWVRdWFudGl0eSUzQUNvdW50JTNCVmFsdWVVbml0cyUzQSUzQg== decodes as (using ASCII character set)

Code: Select all

ValueQuantity%3ATime%3BValueUnits%3Ah%3B
which can be url decoded and read as:

Code: Select all

ValueQuantity:Time;ValueUnits:h;

Cheers!
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: API/JSON URL to set options for a Counter Sensor

Post by stlaha2007 »

Nice decoding... Kinda solved by yourself...
This makes me curious what kind of sensor your trying to build... Does it have todo with your previous question about which sensor to choose?

Sent from my K00C using Tapatalk
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: API/JSON URL to set options for a Counter Sensor

Post by BakSeeDaa »

stlaha2007 wrote:Nice decoding... Kinda solved by yourself...
This makes me curious what kind of sensor your trying to build... Does it have todo with your previous question about which sensor to choose?

Sent from my K00C using Tapatalk
Yes it does. It's for my project Domoticz RPC for NIBE Uplink ;)
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: RE: Re: API/JSON URL to set options for a Counter Sensor

Post by stlaha2007 »

BakSeeDaa wrote:
stlaha2007 wrote: Does it have todo with your previous question about which sensor to choose?
Yes it does. It's for my project Domoticz RPC for NIBE Uplink ;)
Very Nice !!!

Sent from my K00C using Tapatalk
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest