Page 1 of 1
Script to send value from one domoticz to another one
Posted: Wednesday 16 May 2018 17:43
by tage
Is it possible to make a script to send a temp value or rain or wind etc to another domoticz on a easy way? I know it is possible to connect domoticz together but I just want to send a few values to a friends domoticz. An mqtt broker are also able to use if it makes it easier...
/ tage
Re: Script to send value from one domoticz to another one
Posted: Wednesday 16 May 2018 18:00
by waaren
Yes is possible:
My first option would be to use a JSON-API
Look here from a dzVents script using the domoticz.openURL() command
Re: Script to send value from one domoticz to another one
Posted: Wednesday 16 May 2018 18:16
by tage
Aah that sounds easy
/json.htm type=command¶m=udevice&idx=IDX&nvalue=0&svalue=TEMP
But how do I get my value in to that "temp" ?
Re: Script to send value from one domoticz to another one
Posted: Wednesday 16 May 2018 18:34
by waaren
In its most basic form (dzVents script)
- Spoiler: show
Code: Select all
--[[
jsontest.lua
]]--
return {
on = { devices = {'temp deviceName'}},
execute = function(dz,trigger)
local myURL = "http://xxx.xxx.xxx.xxx:yyy/json.htm?type=command¶m=udevice&idx=nnn&nvalue=0&svalue=" .. tostring(trigger.temperature)
dz.openURL({
url = myURL,
method = "GET",
callback = "only needed when you want to check the result" })
end
}
Re: Script to send value from one domoticz to another one
Posted: Wednesday 16 May 2018 19:02
by u01pei
You could do this in a bash script:
Code: Select all
Temp=$(curl -s "YOUR_DOMOTICZ_SERVER/json.htm?type=devices&rid=TEMPERATURE_DEVICE_IDX" | jq '.result[0].'Temp'' | tr -d '"')
it produces a clean temperature in format XX.X
then you can sent it to your friend:
Code: Select all
curl -s "YOUR_FRIENDS_DOMOTICZ_SERVER/json.htm?type=command¶m=udevice&idx=FRIENDS_DEVICE_IDX_HERE&nvalue=0&svalue=$Temp"
In short, retreive your value, sent it to your friends domoticz.
But why the hard way? you also would have to make a planning for say every five minutes sent an update (run the script), while this can all be done with the domoticz connection (make new user for your friend and limit his acces to the temp device you want to share).
Re: Script to send value from one domoticz to another one
Posted: Friday 18 May 2018 6:45
by tage
thx for helping me.. did a quick test and the dzvents script didnt work i got this error :
Code: Select all
2018-05-18 06:37:44.278 Error: EventSystem: in /home/pi/domoticz/scripts/dzVents/runtime/dzVents.lua: /home/pi/domoticz/scripts/dzVents/runtime/EventHelpers.lua:567: attempt to concatenate local 'vv' (a table value)
guessing it is for i dont use beta version ?
have not try the bash script but should not be to hard to try that
/ tage
Re: Script to send value from one domoticz to another one
Posted: Friday 18 May 2018 12:35
by waaren
More than likely. openURL is part of dzVents > 2.3.0
Would be moving to Beta an option for you ?
Moving is a relatively easy step and providing you have a backup (and tested the restore) without a big risk.
Re: Script to send value from one domoticz to another one
Posted: Saturday 19 May 2018 11:17
by tage
Upgraded to beta and it seems to work
And the script also working ! Thx.
Is it possible to lower the decimals of the value ?
Right now it is like this : 18.3212456
18.3 should be enough.
/ tage
Re: Script to send value from one domoticz to another one
Posted: Saturday 19 May 2018 11:23
by waaren
@tage
Sure, change
to
Code: Select all
tostring(dz.utils.round(trigger.temperature,1))