Page 1 of 1

get last JSON values

Posted: Wednesday 15 November 2017 14:37
by devros
hi all,
im playing with ESP32(with battery and oled) & Micropython that will display (and refresh) some actual data from domoticz. Works good so far. I can display energy saved today extracted from JSON.
I would like to get actual power from json, but i can use only day range a json file is quite huge for my ESP memory

Code: Select all

/json.htm?type=graph&sensor=counter&idx=IDX&range=day 
I want last value in json file anyway :).

Any idea how to get only last entry in JSON from domoticz (something like &range=actual) where will be only last entry....
Could be possible to make some dirty python script, but would be great to get that directly from domoticz.

Any idea, how to solve this ?

Re: get last JSON values

Posted: Wednesday 15 November 2017 15:24
by htilburgs
devros wrote: Wednesday 15 November 2017 14:37 hi all,
im playing with ESP32(with battery and oled) & Micropython that will display (and refresh) some actual data from domoticz. Works good so far. I can display energy saved today extracted from JSON.
I would like to get actual power from json, but i can use only day range a json file is quite huge for my ESP memory

Code: Select all

/json.htm?type=graph&sensor=counter&idx=IDX&range=day 
I want last value in json file anyway :).

Any idea how to get only last entry in JSON from domoticz (something like &range=actual) where will be only last entry....
Could be possible to make some dirty python script, but would be great to get that directly from domoticz.

Any idea, how to solve this ?
Can this work? Where rid is the IDX of the device.

Code: Select all

json.htm?type=devices&rid=4
In the results you get "Data: " with the last result, see my example for the RPi Temperature.
This you can extract and you get your last result.
Spoiler: show

Code: Select all

"ActTime" : 1510755671,
   "ServerTime" : "2017-11-15 15:21:11",
   "Sunrise" : "07:57",
   "Sunset" : "16:48",
   "result" : [
      {
         "AddjMulti" : 1.0,
         "AddjMulti2" : 1.0,
         "AddjValue" : 0.0,
         "AddjValue2" : 0.0,
         "BatteryLevel" : 255,
         "CustomImage" : 0,
         "Data" : "35.8 C",
         "Description" : "",
         "Favorite" : 1,
         "HardwareID" : 3,
         "HardwareName" : "Moederbord Sensoren",
         "HardwareType" : "Motherboard sensors",
         "HardwareTypeVal" : 23,
         "HaveTimeout" : false,
         "ID" : "0001",
         "LastUpdate" : "2017-11-15 15:20:12",
         "Name" : "Raspberry PI Temperatuur",
         "Notifications" : "false",
         "PlanID" : "2",
         "PlanIDs" : [ 2, 2 ],
         "Protected" : false,
         "ShowNotifications" : true,
         "SignalLevel" : "-",
         "SubType" : "LaCrosse TX3",
         "Temp" : 35.799999999999997,
         "Timers" : "false",
         "Type" : "Temp",
         "TypeImg" : "temperature",
         "Unit" : 1,
         "Used" : 1,
         "XOffset" : "0",
         "YOffset" : "0",
         "idx" : "4"
      }
   ],
   "status" : "OK",
   "title" : "Devices"
}

Re: get last JSON values

Posted: Wednesday 15 November 2017 15:35
by SweetPants
If you use MQTT and subscribe to topic domoticz/out, every time domoticz receives the last power value, it is published on this topic too in a JSON like:
{
"Battery" : 255,
"RSSI" : 12,
"description" : "idx: 60\nESP_022A24",
"dtype" : "General",
"id" : "00082059",
"idx" : 60,
"meterType" : "Energy",
"name" : "CV_Pomp Energie",
"nvalue" : 0,
"stype" : "kWh",
"svalue1" : "3.500",
"svalue2" : "21967.500",
"unit" : 1
}

Re: get last JSON values

Posted: Wednesday 15 November 2017 15:44
by devros
htilburgs wrote: Wednesday 15 November 2017 15:24
devros wrote: Wednesday 15 November 2017 14:37 hi all,
im playing with ESP32(with battery and oled) & Micropython that will display (and refresh) some actual data from domoticz. Works good so far. I can display energy saved today extracted from JSON.
I would like to get actual power from json, but i can use only day range a json file is quite huge for my ESP memory

Code: Select all

/json.htm?type=graph&sensor=counter&idx=IDX&range=day 
I want last value in json file anyway :).

Any idea how to get only last entry in JSON from domoticz (something like &range=actual) where will be only last entry....
Could be possible to make some dirty python script, but would be great to get that directly from domoticz.

Any idea, how to solve this ?
Can this work? Where rid is the IDX of the device.

Code: Select all

json.htm?type=devices&rid=4
In the results you get "Data: " with the last result, see my example for the RPi Temperature.
This you can extract and you get your last result.
Yay, I was blind, how can i miss this :)
thanks a lot

Re: get last JSON values

Posted: Wednesday 15 November 2017 15:47
by devros
SweetPants wrote: Wednesday 15 November 2017 15:35 If you use MQTT and subscribe to topic domoticz/out, every time domoticz receives the last power value, it is published on this topic too in a JSON like:
{
"Battery" : 255,
"RSSI" : 12,
"description" : "idx: 60\nESP_022A24",
"dtype" : "General",
"id" : "00082059",
"idx" : 60,
"meterType" : "Energy",
"name" : "CV_Pomp Energie",
"nvalue" : 0,
"stype" : "kWh",
"svalue1" : "3.500",
"svalue2" : "21967.500",
"unit" : 1
}
Thanks but for this i need MQTT client, dunno if this can ESP32 can handle, want to keep my code simple anyway