Script to send value from one domoticz to another one

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
tage
Posts: 14
Joined: Monday 14 May 2018 15:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Script to send value from one domoticz to another one

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
tage
Posts: 14
Joined: Monday 14 May 2018 15:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by tage »

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: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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&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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
u01pei

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

Post 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&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: 14
Joined: Monday 14 May 2018 15:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
tage
Posts: 14
Joined: Monday 14 May 2018 15:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post by waaren »

@tage

Sure, change

Code: Select all

tostring(trigger.temperature)
to

Code: Select all

tostring(dz.utils.round(trigger.temperature,1))
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest