How to get data from external scripts to Domoticz.

Post Reply
pavelbor
Posts: 38
Joined: Sunday 18 December 2016 13:18
Target OS: Raspberry Pi
Domoticz version: LastBeta
Location: Tallinn / Estonia
Contact:

How to get data from external scripts to Domoticz.

Post by pavelbor » Monday 19 December 2016 10:29

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?

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

Re: How to get data from external scripts to Domoticz.

Post by stlaha2007 » Monday 19 December 2016 11:02

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&param=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.

pavelbor
Posts: 38
Joined: Sunday 18 December 2016 13:18
Target OS: Raspberry Pi
Domoticz version: LastBeta
Location: Tallinn / Estonia
Contact:

Re: How to get data from external scripts to Domoticz.

Post by pavelbor » Monday 19 December 2016 11:16

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.

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

Re: How to get data from external scripts to Domoticz.

Post by stlaha2007 » Monday 19 December 2016 11:31

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 ;-)

lost
Posts: 196
Joined: Thursday 10 November 2016 10:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: How to get data from external scripts to Domoticz.

Post by lost » Tuesday 20 December 2016 16:54

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!

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

Re: How to get data from external scripts to Domoticz.

Post by stlaha2007 » Tuesday 20 December 2016 17:38

@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.

lost
Posts: 196
Joined: Thursday 10 November 2016 10:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: How to get data from external scripts to Domoticz.

Post by lost » Thursday 22 December 2016 9:16

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!

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests