Script to send value from one domoticz to another one

Easy to use, 100% Lua-based event scripting framework.
Post Reply
tage
Posts: 11
Joined: Monday 14 May 2018 15:56
Target OS: Raspberry Pi
Domoticz version:
Contact:

Script to send value from one domoticz to another one

Post by tage » Wednesday 16 May 2018 17:43

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

User avatar
waaren
Posts: 807
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script to send value from one domoticz to another one

Post by waaren » Wednesday 16 May 2018 18:00

Yes is possible:

My first option would be to use a JSON-API Look here from a dzVents script using the domoticz.openURL() command
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

tage
Posts: 11
Joined: Monday 14 May 2018 15:56
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Script to send value from one domoticz to another one

Post by tage » Wednesday 16 May 2018 18:16

Aah that sounds easy

/json.htm type=command&param=udevice&idx=IDX&nvalue=0&svalue=TEMP

But how do I get my value in to that "temp" ?

User avatar
waaren
Posts: 807
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script to send value from one domoticz to another one

Post by waaren » Wednesday 16 May 2018 18:34

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&param=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
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

u01pei
Posts: 51
Joined: Sunday 04 January 2015 17:17
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Script to send value from one domoticz to another one

Post by u01pei » Wednesday 16 May 2018 19:02

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

tage
Posts: 11
Joined: Monday 14 May 2018 15:56
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Script to send value from one domoticz to another one

Post by tage » Friday 18 May 2018 6:45

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

User avatar
waaren
Posts: 807
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script to send value from one domoticz to another one

Post by waaren » Friday 18 May 2018 12:35

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.
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

tage
Posts: 11
Joined: Monday 14 May 2018 15:56
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Script to send value from one domoticz to another one

Post by tage » Saturday 19 May 2018 11:17

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

User avatar
waaren
Posts: 807
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script to send value from one domoticz to another one

Post by waaren » Saturday 19 May 2018 11:23

@tage

Sure, change

Code: Select all

tostring(trigger.temperature)
to

Code: Select all

tostring(dz.utils.round(trigger.temperature,1))
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests