Domoticz HTTP/HTTPS poller and JSON

Adding a sensor of a remote host to Domoticz is easy, just not very well documented.

I have a DS1820 one-wire sensor plugged on a Linux machine that polls the temperature every minute then stores it in a CSV. Since I recently installed Domoticz on a Raspberry PI, I wanted to show the values there as well. I’ll show what you need to do this.

Open the Setup menu and choose the Hardware option. Enter a name you like and select the HTTP/HTTPS poller type, you should see the following:

HTTP/HTTPS poller to handle JSON in Domoticz
HTTP/HTTPS poller to handle JSON in Domoticz

Data Timeout: leave it Disabled

ContentType: the type of received data, application/json

URL: the full URL including scheme, host name and path where you will have the JSON file with the latest data.

Command: this is a filename (with extension) for a script that will handle the downloaded JSON, which Domoticz will search at …/domoticz/scripts/lua_parsers/<command>
Tehre’s a basic example called example_json.lua, for a this setup it will be fine.

Refresh: refresh interval in seconds.

After adding you should see it immediately in the list:

HTTP/HTTPS poller added in Domoticz
HTTP/HTTPS poller added in Domoticz

Click on Create Virtual Sensors button to add a sensor, give it a custom name, select the type of data you want to log and select OK. It should appear in your devices list:

A temperature sensor using Domoticz's HTTP/HTTPS poller
A temperature sensor using Domoticz’s HTTP/HTTPS poller

Note the Idx of the sensor (not the ID nor Unit, the first number) which is 15 in my case. You will need to put this in the JSON file on remoteserver in a field named id – yes, this is inconsistent.

The JSON file you need to provide on remoteserver can be as simple as this:

{ "id": 15, "temperature": 12.3 }

Tip: you can output this with any script, you can consider it a string, just replace the value with the latest measurement. You also need to update it periodically.

As soon as you added the poller, Domoticz starts to poll the URL you supplied and passes the result to the script you supplied.

If in the next few minutes you start to see the data in Domoticz, congratulations, you have it working. If not, check the Troubleshooting section below.

Note 1: Domoticz executes the script one time for every HTTP/HTTPS poller “hardware” and you can have multiple sensors configured for one poller. In this case you need to supply multiple id/idx values and multiple values for measurements and need a custom script updating each sensor.

Note 2: In the example script the id is read from the JSON and blindly supplied to Domoticz which will update the sensor having that as idx. This may overwrite the data of any other sensor if configured improperly.

Unfortunately Domoticz is only supplying the hardware idx as hwdId variable but not the idx of the sensor(s) on that poller, so if you want to prevent it you need to hardcode the idx of the sensor(s) in your script, e.g. you can create remote_1_json.lua with the content:

local idx = 15
local temperature = domoticz_applyJsonPath(request['content'], '.temperature')
domoticz_updateDevice(idx, '' , temperature)

Then you can entirely skip the id field in JSON:

{ "temperature": 12.3 }

Just make sure you update the script’s name on the web interface.

Note 3: you might need to add the following header on the remote host to your response:

Content-Type: application/json

Troubleshooting

Error: CLuaHandler (updateDevice from LUA) : Incorrect parameters type 

One of the field received in JSON is invalid. The id should be an integer, temperature should be a float.

Error: CLuaHandler: cannot open /home/.../domoticz/scripts/lua_parsers/example_json: No such file or directory 

You need to provide a full file name with extension in the Command field of the Setup > Hardware page. Also, make sure the script exists.

CLuaHandler (updateDevice from LUA) : idx=15 nvalue= svalue=12.3 invalue=0 signallevel=12 batterylevel=255 

This is normal, the script parsed the JSON and issued an update for the sensor. If you can’t see the update on the interface, double check the idx or id parameter you have in the JSON file.

VoCore: A coin-sized Linux computer with Wi-Fi for USD 20

In early July I’ve found an Indiegogo project of a miniature Linux powered computer called VoCore.

It is a RaLink RT5350 (360 MHz MIPS24KEc) based board with 8 MB SPI Flash (although Vonger, the creator of the project upgraded to a 16 MB Flash for the Indiegogo batch just because he’s a nice guy) with two 10/100 Mbps Ethernet interfaces, one USB 2.0 interface, a bunch of serial interfaces (UART, I2C, I2S, PCM, JTAG) and over 20 GPIOs. All these broken out to standard 1.27 mm connectors while keeping the size at 25×25 mm!

There is a dock to provide some connectors: an Ethernet, a USB, a micro USB (for the power) and a micro SD card slot – this measues 25×25 mm as well, of course.

VoCore is running the OpenWRT firmware. It acts as an access point by default, running a network called “VoCore” (this is unfortunately an open network (i.e. no encryption set up) so changing security settings as soon as possible is recommended).

Vonger, the creator of the project is running a blog at vonger.cn, he was constantly updating it with the latest status of the VoCore development and production, both bad and good news. Thanks to this it seemed that we were witnessing all the little details, it felt like we (the backers) were parts of the whole process :)

The VoCore can be ordered from vocore.io/store. If you would like to have the VoCore main board only (with all the I/O breakouts but no connectors at all) it is USD 20, but if you’d like to have the Dock as well, plus a USB to TTL converter (note: this is missing from my pictures below!) to re-flash the firmware it is just USD 45.

I believe that the VoCore has a lot of potential thanks to its small size (25×25 mm) its low power consumption (0.6-1.2 Watts) its flexibility (20+ GPIOs and the whole bunch of connector break outs) and low cost.

I think this is a must have board for any geeks out there who have thought about hacking some hardware once in a while.

Oh, and one more thing: VoCore is open source, both software and hardware. All the schematics, circuits, firmware, 3D model for the shell/case, everything is available to download from the VoCore’s site.