Transfer sensordata from Domoticz to domoticz using dzvents

Moderator: leecollings

Post Reply
hairman63
Posts: 5
Joined: Friday 20 July 2018 16:23
Target OS: Windows
Domoticz version: 2020.2
Location: Netherlands
Contact:

Transfer sensordata from Domoticz to domoticz using dzvents

Post by hairman63 »

Hi all,

new here ... i trying to transfer sensordata from my second domoticz device to the first using dzvents scripting.
So far i have a start, but i can't get it up and runing ...

Code: Select all

local server = ('http://192.168.xxx.xxx:xxxx')
local callbackString = ('RemoteDataPush_callback')

return {
	on = {
		--devices = {},
		timer = {
			'every minute',
		},
		--variables = {},
		--scenes = {},
		--groups = {},
		--security = {},
		httpResponses = {
		    callbackString,
		},
		--customEvents = {},
		--system = {},
	},
    logging = {
    -- level = domoticz.LOG_ERROR, marker = "ERROR Logging ",
    -- level = domoticz.LOG_DEBUG, marker = "DEBUG Logging ",
    level = domoticz.LOG_INFO, marker = "INFO Logging ",
    marker = "Tempz",
    },
	execute = function(domoticz, item, info)

        local T_Woonk = domoticz.devices('Woonkamer')       --94    THP
        local T_Kantoor = domoticz.devices('Kantoor')       --13    TP
        local T_Slaapk = domoticz.devices('Slaapkamer')     --95    THP
        local T_Keuken = domoticz.devices('Keuken')         --96    THP
        local T_Slaapk = domoticz.devices('Balkon')         --80    TH
        local T_Keuken = domoticz.devices('Hal')            --98    THP
        
        if (item.isTimer) then
            domoticz.openURL({url = server .. '/json.htm?type=command&param=udevice&idx=' .. 94 ..'&nvalue=0&svalue=' .. T_Woonk.temperature .. ";" .. T_Woonk.humidity .. ";" .. T_Woonk.humidityStatus .. ";" .. T_Woonk.pressure .. ";" .. forecast, callback = callbackString})
        elseif (item.isHTTPResponse) then
            if (item.json.status == 'OK') then
                domoticz.log('Updated the remote device succesfully.')
                domoticz.log(item.json)
            else
                domoticz.log('Something went wrong updating the remote device', domoticz.LOG_ERROR)
                domoticz.log(item.json, domoticz.LOG_ERROR)
            end
        else
            domoticz.log('Unknown script trigger.', domoticz.LOG_ERROR)
        end        
        
	end
}
As you can see i only got it for just one sensor, but taht ain't working either ... dunno what's wrong so far ... :roll:

Harry
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Post by waaren »

hairman63 wrote: Tuesday 16 June 2020 22:22 So far i have a start, but i can't get it up and runing ...
Please check the wiki for the right names of the attributes.

In it's most basic form..

Code: Select all

local remoteServer = 'http://192.168.xxx.xxx:xxxx'
local callbackString = 'RemoteDataPush_callback'

return
{
    on =
    {

        timer =
        {
            'every minute',
        },

        httpResponses =
        {
            callbackString,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = "Tempz",
    },

    execute = function(dz, item)

        local T_Woonk = domoticz.devices('Woonkamer')       --94    THP
        T_Woonk.remote = 94

        if item.isTimer or item.isDevice then
            url =     remoteServer ..
                    '/json.htm?type=command&param=udevice&idx=' ..
                    T_Woonk.remote ..
                    '&nvalue=0&svalue=' ..
                    dz.utils.round(T_Woonk.temperature,2) .. ";" ..
                    T_Woonk.humidity .. ";" ..
                    T_Woonk.humidityStatusValue .. ";" ..
                    T_Woonk.barometer .. ";" ..
                    T_Woonk.forecast

            dz.log(url,dz.LOG_DEBUG)
            dz.openURL(
                {    url = url,
                    callback = callbackString,
                })
        elseif item.isHTTPResponse then
            if item.ok then
                dz.log('Updated the remote device succesfully.')
                dz.log(item.json)
            else
                dz.log('Something went wrong updating the remote device', dz.LOG_ERROR)
                dz.log(item, dz.LOG_ERROR)
            end
        else
            dz.log('Unknown script trigger.', dz.LOG_ERROR)
        end

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Post by EddyG »

Why not use the 'slave' function of Domoticz?
physiker123
Posts: 37
Joined: Wednesday 25 November 2015 18:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Germany / France
Contact:

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Post by physiker123 »

I have the same problem, domoticz cannot transfer the data (I suspect the spaces in the text device...).

The slave function did not work for me, because it only transferred the switches, not the text devices (both rpi with latest beta)

Now I cut the string of the text devices, and transfer every part individually... Not an elegant solution, but it works...

Jens
hairman63
Posts: 5
Joined: Friday 20 July 2018 16:23
Target OS: Windows
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Post by hairman63 »

waaren wrote: Tuesday 16 June 2020 23:33
hairman63 wrote: Tuesday 16 June 2020 22:22 So far i have a start, but i can't get it up and runing ...
Please check the wiki for the right names of the attributes.

In it's most basic form..

Code: Select all

local remoteServer = 'http://192.168.xxx.xxx:xxxx'
local callbackString = 'RemoteDataPush_callback'

return
{
    on =
    {

        timer =
        {
            'every minute',
        },

        httpResponses =
        {
            callbackString,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = "Tempz",
    },

    execute = function(dz, item)

        local T_Woonk = domoticz.devices('Woonkamer')       --94    THP
        T_Woonk.remote = 94

        if item.isTimer or item.isDevice then
            url =     remoteServer ..
                    '/json.htm?type=command&param=udevice&idx=' ..
                    T_Woonk.remote ..
                    '&nvalue=0&svalue=' ..
                    dz.utils.round(T_Woonk.temperature,2) .. ";" ..
                    T_Woonk.humidity .. ";" ..
                    T_Woonk.humidityStatusValue .. ";" ..
                    T_Woonk.barometer .. ";" ..
                    T_Woonk.forecast

            dz.log(url,dz.LOG_DEBUG)
            dz.openURL(
                {    url = url,
                    callback = callbackString,
                })
        elseif item.isHTTPResponse then
            if item.ok then
                dz.log('Updated the remote device succesfully.')
                dz.log(item.json)
            else
                dz.log('Something went wrong updating the remote device', dz.LOG_ERROR)
                dz.log(item, dz.LOG_ERROR)
            end
        else
            dz.log('Unknown script trigger.', dz.LOG_ERROR)
        end

    end
}
Thanks for your reply ... i will try this tonight ...
hairman63
Posts: 5
Joined: Friday 20 July 2018 16:23
Target OS: Windows
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Post by hairman63 »

EddyG wrote: Wednesday 17 June 2020 7:20 Why not use the 'slave' function of Domoticz?
Can you explain how to use 'slave' ..? I'm not familiar with that ...
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Post by EddyG »

Ofcource. Setup -> About -> Manual -> page 28
https://www.domoticz.com/wiki/Setting_up_Device_sharing

And several other places, search function does wonders. ;)
xury
Posts: 48
Joined: Monday 10 December 2018 23:32
Target OS: Linux
Domoticz version:
Location: Poland
Contact:

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Post by xury »

I had problems with master - slave communication between Domoticz instances so I made workaround using MQTT and Node-Red . Example flow with my solution is released on node red flow named Domoticz to Domoticz.
hairman63
Posts: 5
Joined: Friday 20 July 2018 16:23
Target OS: Windows
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Post by hairman63 »

EddyG wrote: Wednesday 17 June 2020 12:39 Ofcource. Setup -> About -> Manual -> page 28
https://www.domoticz.com/wiki/Setting_up_Device_sharing

And several other places, search function does wonders. ;)
Thanks .... i didn't know ...
Looks very interesting ...
ronaldbro
Posts: 327
Joined: Thursday 15 November 2018 21:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Post by ronaldbro »

I had the same problem. I have master-slave running, but it doesn't work for all devices. Don't know exactly what work and doesn't work, but from my experience the master-slave doesn't work for devices created by python plugins.

I made a dzVents scripts to push the data to an other domoticz, see https://www.domoticz.com/forum/viewtopi ... 72&t=31618
Hope this helps.
hairman63
Posts: 5
Joined: Friday 20 July 2018 16:23
Target OS: Windows
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Post by hairman63 »

waaren wrote: Tuesday 16 June 2020 23:33
hairman63 wrote: Tuesday 16 June 2020 22:22 So far i have a start, but i can't get it up and runing ...
Please check the wiki for the right names of the attributes.

In it's most basic form..
Thanks ... but i got it running with basicaly my first script. My problem wasn't the code after all ... it had something to do with rights on the PC ...
It's now running with this code below ...

Code: Select all

local remoteServer = 'http://192.168.xxx.xxx:xx/json.htm?type=command&param=udevice&idx='
local callbackString = ('RemoteDataPush_callback')

return {
	on = {
		timer = {
			'every minute',
		},
		httpResponses = {
		    callbackString,
		},
	},
    logging = {
    -- level = domoticz.LOG_ERROR, marker = "ERROR Logging ",
    -- level = domoticz.LOG_DEBUG, marker = "DEBUG Logging ",
    level = domoticz.LOG_INFO, marker = "INFO Logging ",
    marker = "Tempz",
    },
	execute = function(domoticz, item, info)

        local T_Woonk = domoticz.devices('Woonkamer')       --94    THP
        local T_Kantoor = domoticz.devices('Kantoor')       --13    TP
        local T_Slaapk = domoticz.devices('Slaapkamer')     --95    THP
        local T_Keuken = domoticz.devices('Keuken')         --96    THP
        local T_Balkon = domoticz.devices('Balkon')         --80    TH
        local T_Hal = domoticz.devices('Hal')               --98    THP
        local L_Kantoor = domoticz.devices('Licht Kantoor') --12
        local L_Keuken = domoticz.devices('Licht Keuken')   --97
        local IDX_T_Wk = 94
        local IDX_T_Kantoor = 13
        local IDX_T_Sk = 95
        local IDX_T_Keuken = 96
        local IDX_T_Balkon = 80
        local IDX_T_Hal = 98
        local IDX_L_Kantoor = 12
        local IDX_L_Keuken = 97
        
         
        if (item.isTimer) then
            domoticz.openURL({url = remoteServer ..
                IDX_T_Wk ..'&nvalue=0&svalue=' ..
                T_Woonk.temperature .. ";" ..
                T_Woonk.humidity .. ";" ..
                T_Woonk.humidityStatus .. ";" ..
                T_Woonk.barometer .. ";" ..
                T_Woonk.forecast,
                callback = callbackString})
            domoticz.openURL({url = remoteServer ..
                IDX_T_Sk ..'&nvalue=0&svalue=' ..
                T_Slaapk.temperature .. ";" ..
                T_Slaapk.humidity .. ";" ..
                T_Slaapk.humidityStatus .. ";" ..
                T_Slaapk.barometer .. ";" ..
                T_Slaapk.forecast,
                callback = callbackString}).afterSec(1)
            domoticz.openURL({url = remoteServer ..
                IDX_T_Keuken ..'&nvalue=0&svalue=' ..
                T_Keuken.temperature .. ";" ..
                T_Keuken.humidity .. ";" ..
                T_Keuken.humidityStatus .. ";" ..
                T_Keuken.barometer .. ";" ..
                T_Keuken.forecast,
                callback = callbackString}).afterSec(2)
            domoticz.openURL({url = remoteServer ..
                IDX_T_Hal ..'&nvalue=0&svalue=' ..
                T_Hal.temperature .. ";" ..
                T_Hal.humidity .. ";" ..
                T_Hal.humidityStatus .. ";" ..
                T_Hal.barometer .. ";" ..
                T_Hal.forecast,
                callback = callbackString}).afterSec(3)
            domoticz.openURL({url = remoteServer ..
                IDX_T_Kantoor ..'&nvalue=0&svalue=' ..
                domoticz.utils.round(T_Kantoor.temperature,2) .. ";" ..
                T_Kantoor.barometer .. ";" ..
                T_Kantoor.forecast,
                callback = callbackString}).afterSec(4)
            domoticz.openURL({url = remoteServer ..
                IDX_T_Balkon ..'&nvalue=0&svalue=' ..
                T_Balkon.temperature .. ";" ..
                T_Balkon.humidity .. ";" ..
                T_Balkon.humidityStatus,
                callback = callbackString}).afterSec(5)
            domoticz.openURL({url = remoteServer ..
                IDX_L_Kantoor ..'&nvalue=0&svalue=' ..
                L_Kantoor.lux,
                callback = callbackString}).afterSec(6)
            domoticz.openURL({url = remoteServer ..
                IDX_L_Keuken ..'&nvalue=0&svalue=' ..
                L_Keuken.lux,
                callback = callbackString}).afterSec(7)
        elseif (item.isHTTPResponse) then
            if (item.json.status == 'OK') then
                domoticz.log('Updated the remote device succesfully.')
                --domoticz.log(item.json)
            else
                domoticz.log('Something went wrong updating the remote device', domoticz.LOG_ERROR)
                domoticz.log(item.json, domoticz.LOG_ERROR)
            end
        else
            domoticz.log('Unknown script trigger.', domoticz.LOG_ERROR)
        end        
        
	end
}
It works for now ...! 8-) 8-)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest