Page 1 of 1
How to get data from external scripts to Domoticz.
Posted: Monday 19 December 2016 9:29
by pavelbor
Hello all,
could you please explain step by step - how to get data from external scripts to Domoticz.
I have some sensors connected to my Raspberry Pi. Some of them are founded by Domoticz:
- I2C sensor BMP085/180 Temp+Baro
- I2C sensor HTU21D
- 1-wire sensors.
But some sensors are not listed.
- I2C BH1750 luminocity sensor. I have python script, which returns lux value. Example "python bh1750_once.py --> 264"
- PIR sensor connected to GPIO. Python script: "sudo python pir1_once.py -->1 or 0"
- PIR sensor connected to 1-wire DS2406. "cat /mnt/1wire/.address./sensed.B" --> 1 or 0."
My question - how to get sensors data into Domotics?
Re: How to get data from external scripts to Domoticz.
Posted: Monday 19 December 2016 10:02
by stlaha2007
depends on your programming skills
You seem to use commandline and python...
You need to create virtual devices (setup/hatdware new dummy) and create dummies for every not natively supported device.
Then extend/create scripts.
The cat can be done like:
Code: Select all
#!/bin/bash
pirvalue=$(echo $(cat /sys/w1/pir_status))
curl -s "http://localhost:8080/json.htm?type=command¶m=switch&idx=123&switchcommand=$(echo $pirvalue)"
Simular can be done with the python examples...
extend/replace the print with a variable and fill it.
Then create a json-push request.
Details how to construct the json are in the wiki Domoticz Json Api.
Also look at the scripting examples. Especially the python examples are great source which answers your questions in detail.
Try to read and explain them (most are well documented within) and you can copy/past it with little modification into your scripts.
Re: How to get data from external scripts to Domoticz.
Posted: Monday 19 December 2016 10:16
by pavelbor
Thank you for your answer,
now i have a virtual sensor with Idx and script provided by you.
Then where i have to copy this script, and how to link virtual sensor and script?
I just want to understand sensors creation logic.
Re: How to get data from external scripts to Domoticz.
Posted: Monday 19 December 2016 10:31
by stlaha2007
Was a quick reply out of my head. Check details please...
The logic behind it;
The virtual sensor has an idx.
The script has the same idx.
Thats the link between them.
Running the script asks the sensor for data and returns/pushes it into Domoticz.
The script can be placed (almost) anywhere on the filesystem you like. I like the path /home/pi/scripts so i have all my scripts in one place.
Also make it executable with eg. chmod +x filename.extension
The scripts (So you can test it first !!!) can be manually run just by /full/path/to/script/filename.extension
Or modify your scheduler eg. Cron by adding a line like:
Code: Select all
*/5 * * * * /full/path/to/script/filename.extension
Hope you get the idea now. Like mentioned already see wiki's for detailed explanation and samples...
Just copy/past/try/modify/try and you'll learn how it works and get the logic together.
Ps. Im on a phone, so cant reply with full details

Re: How to get data from external scripts to Domoticz.
Posted: Tuesday 20 December 2016 15:54
by lost
stlaha2007 wrote:
Just copy/past/try/modify/try and you'll learn how it works and get the logic together.
Just for trying while scripting, I use the navigator with json api url...
For instance, to get all switches in the system, see:
https://www.domoticz.com/wiki/Domoticz_ ... 2Fswitches
In Firefox, if host running domoticz is at 192.138.1.31 running on usual 8080 port, try this from your PC:
http://192.168.1.31:8080/json.htm?type= ... htswitches
You'll get a json answer with all switches info...
On domoticz hosting machine, that'll be the same in the scripts except 127.0.0.1 as localhost address
You can try to change one switch with the appropriate command from
https://www.domoticz.com/wiki/Domoticz_ ... Fswitch_on
If it doesn't work, take care not to have a password enforced also on your local subnet!
Re: How to get data from external scripts to Domoticz.
Posted: Tuesday 20 December 2016 16:38
by stlaha2007
@lost? Hmm, i tried to figure out why you quoted me.
As TP asked how to get data from script into domoticz.
And i pointed to the wiki's and examples... included one very basic to help.
I wrote several scripts already with the help from json-api/python/bash wiki's and examples at the wiki section on domoticz.com.
Re: How to get data from external scripts to Domoticz.
Posted: Thursday 22 December 2016 8:16
by lost
stlaha2007 wrote:@lost? Hmm, i tried to figure out why you quoted me.
As TP asked how to get data from script into domoticz.
And i pointed to the wiki's and examples... included one very basic to help.
I wrote several scripts already with the help from json-api/python/bash wiki's and examples at the wiki section on domoticz.com.
Well, a beginner may not think about trying the json api calls from a navigator, possibly from his PC... Just to figure out how it works!