Page 1 of 1

Transfer sensordata from Domoticz to domoticz using dzvents

Posted: Tuesday 16 June 2020 22:22
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

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Posted: Tuesday 16 June 2020 23:33
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
}

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Posted: Wednesday 17 June 2020 7:20
by EddyG
Why not use the 'slave' function of Domoticz?

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Posted: Wednesday 17 June 2020 7:44
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

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Posted: Wednesday 17 June 2020 12:24
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 ...

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Posted: Wednesday 17 June 2020 12:29
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 ...

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Posted: Wednesday 17 June 2020 12:39
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. ;)

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Posted: Wednesday 17 June 2020 15:29
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.

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Posted: Wednesday 17 June 2020 19:54
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 ...

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Posted: Wednesday 17 June 2020 21:17
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.

Re: Transfer sensordata from Domoticz to domoticz using dzvents

Posted: Wednesday 17 June 2020 21:42
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-)