Brilliant, 8 piped seds is quite something and spawning gets over the 10 second rule.dannybloe wrote:Btw, fetching extra device data from Domoticz like battery info only works on linux file systems. It requires bash, curl and sed and lots of pipes .
A little suggestion I think would be an improvment, is to make the request DomoticzData function into a normal time script, call it with the normal time mechanism, this would also allow users to attach it to a virtual switch and force an update by simply operating the switch.
The various json libraries are fairly efficient and in the past I had no problem doing dumb dumps even on a Raspberry Pi B as per @Westcott, the slow bit I found was file passing to the os.execute and back, which I overcame by using Lua http libaries.
Installation of the http, socket, ssl and json libraries I use for Raspberry Pi is described here - http://www.domoticz.com/wiki/Remote_Con ... _Libraries
I attach an example of doing the dump of all the json as Lua table script to devices.lua every minute - strangely having run it for an hour occassionally it would come up with the Lua 10 second warning - once again it could be spawned and run as a separate process doesn't need the direct connection to Domoticz as just uding the API.
Theoretically with the LuaRocks framework it should be possible to run this code anywhere LuaRocks is available - https://luarocks.org/.
The key bit of code is here, all the code with the large bit of stolen table to lua script dumping code is hidden below:
Code: Select all
commandArray = {}
DomoticzIP = "127.0.0.1"
DomoticzPort = "8080"
server_url = "http://"..DomoticzIP..":"..DomoticzPort
-- Retrieve all the device data
jresponse, status = http.request(server_url.."/json.htm?type=devices")
-- Decode the json to a Lua table
decoded_response = JSON:decode(jresponse)
print('About to have a go at dumping')
table.dump('device.lua',decoded_response,false,false)
print('Done the dumping')
return commandArray
- Spoiler: show