Page 1 of 1
Analog measurement
Posted: Saturday 27 October 2018 9:46
by Knibor
Hi,
I have a question how to establish the following with dzVents.
I have
Switch with IDX=1
Voltage indicator with IDX=2
Voltage indicator with IDX=3
When Switch with IDX=1 is "ON" then copy the measured voltage from IDX=2 to the voltage indicator with IDX=3
Can some help me with this?
Thanks
Re: Analog measurement
Posted: Saturday 27 October 2018 10:49
by waaren
Knibor wrote: Saturday 27 October 2018 9:46
When Switch with IDX=1 is "ON" then copy the measured voltage from IDX=2 to the voltage indicator with IDX=3
Do you want to copy the value from 2 to 3 only when the switch state change from Off to On or do you want to copy from 2 to 3 every x minutes for as long as the switch state is On ?
Re: Analog measurement
Posted: Saturday 27 October 2018 12:42
by Knibor
Hi,
Thanks for you reply, I want copy the value from 2 to 3 every x seconds for as long as the switch state is On ?
And when the Switch is Off the last On value keeps in IDX 3
Re: Analog measurement
Posted: Saturday 27 October 2018 14:31
by waaren
Knibor wrote: Saturday 27 October 2018 12:42
I want copy the value from 2 to 3 every x seconds for as long as the switch state is On ?
And when the Switch is Off the last On value keeps in IDX 3
This script is triggered on any update to the voltage sensor with IDX 2 and copy the voltage value to (virtual) voltage sensor with IDX 3 when Switch is On and values in the voltage sensors are not already equal.
Code: Select all
-- voltageCopy
return {
on = { devices = { 2 }}, -- Master voltage sensor
logging = { level = domoticz.LOG_DEBUG, -- commment these 2 lines when script execute without any issues
marker = "voltageCopy" },
execute = function(dz, item) -- item is the Master voltage sensot
local slaveVoltageSensor = dz.devices(3)
local voltageCopySwitch = dz.devices(1)
if voltageCopySwitch.state == "On" then
if slaveVoltageSensor.voltage ~= item.voltage then
dz.log("Script is triggered by " .. item.name .. "; new voltage (" .. item.voltage .. ") will be copied to " .. slave.name,dz.LOG_DEBUG)
slaveVoltageSensor.updateVoltage(item.voltage) - the actual copy
else
dz.log("Script is triggered by " .. item.name .. "; voltage (" .. item.voltage .. ") will NOT be copied to " .. slave.name .. "(voltages are equal)",dz.LOG_DEBUG)
end
else
dz.log("Script is triggered by " .. item.name .. "; voltage (" .. item.voltage .. ") will NOT be copied to " .. slave.name .. "(control switch is Off)",dz.LOG_DEBUG)
end
end
}
Re: Analog measurement
Posted: Saturday 27 October 2018 16:27
by Knibor
Hi, thanks for the code.
I tried this code with the actual IDX from my Domoticz system, but until now no succes.
Domoticz says there is an Error in line ...slaveVoltageSensor.updateVoltage(item.voltage) - the actual copy
I tried to delete this part. The error was gone but, I don't know should i delete this part? When I delete this part, still no succes.
Here is my actual code
Re: Analog measurement
Posted: Saturday 27 October 2018 19:17
by waaren
Knibor wrote: Saturday 27 October 2018 16:27
Domoticz says there is an Error in line ...slaveVoltageSensor.updateVoltage(item.voltage)
- the actual copy
I tried to delete this part. The error was gone but, I don't know should i delete this part? When I delete this part, still no succes.
the part "- the actual copy" is missing 1 "-"
the line should have been
Code: Select all
slaveVoltageSensor.updateVoltage(item.voltage) -- the actual copy
-- the actual copy is only a comment to explain what is happening in the script.
To be complete I post the corrected script.
Code: Select all
-- voltageCopy
return {
on = { devices = { 2 }}, -- Master voltage sensor
logging = { level = domoticz.LOG_DEBUG, -- commment these 2 lines when script execute without any issues
marker = "voltageCopy" },
execute = function(dz, item) -- item is the Master voltage sensot
local slaveVoltageSensor = dz.devices(3)
local voltageCopySwitch = dz.devices(1)
if voltageCopySwitch.state == "On" then
if slaveVoltageSensor.voltage ~= item.voltage then
dz.log("Script is triggered by " .. item.name .. "; new voltage (" .. item.voltage .. ") will be copied to " .. slave.name,dz.LOG_DEBUG)
slaveVoltageSensor.updateVoltage(item.voltage) -- the actual copy
else
dz.log("Script is triggered by " .. item.name .. "; voltage (" .. item.voltage .. ") will NOT be copied to " .. slave.name .. "(voltages are equal)",dz.LOG_DEBUG)
end
else
dz.log("Script is triggered by " .. item.name .. "; voltage (" .. item.voltage .. ") will NOT be copied to " .. slave.name .. "(control switch is Off)",dz.LOG_DEBUG)
end
end
}
Re: Analog measurement
Posted: Saturday 27 October 2018 20:14
by Knibor
Hi,
I tried this latest code with a fresh installed Domoticz, so only this code and the new IDX
IDX 14 is the master voltage sensor, were I can read now the value 80.
IDX 13 is the slave sensor, and I read now the value "0".
IDX 15 is the voltage Switch and I with it on and off serval times. Also tried when the switch is on change the value off IDX 14 master voltage.
But no copy from IDX 14 to IDX15.
Do I something wrong?
Here is my log
Re: Analog measurement
Posted: Saturday 27 October 2018 20:26
by waaren
Knibor wrote: Saturday 27 October 2018 20:14
Hi,
I tried this latest code with a fresh installed Domoticz, so only this code and the new IDX
IDX 14 is the master voltage sensor, were I can read now the value 80.
IDX 13 is the slave sensor, and I read now the value "0".
IDX 15 is the voltage Switch and I with it on and off serval times. Also tried when the switch is on change the value off IDX 14 master voltage.
But no copy from IDX 14 to IDX15.
Do I something wrong?
Here is my log
As you described it, the copy should go from 14 to 13
Can you show the script how it is now and at least show the log with the debug lines of the script? Preferable in textformat within "[ code]" "[ \code]" tags
Re: Analog measurement
Posted: Saturday 27 October 2018 20:52
by Knibor
Hi, it works now
I don't now why? I only changed the file name from the script from Sample/Hold to SampleHold.
Suddenly it works!
Thank you very much for the support.
I have made a battery cell monitor. It reads the battery voltage value with Espeasy mini D1and send it (wireless) to Domoticz. The Espeasy is connected with a multiplexer and can measure 16 channels.
I send with Domotics a binary code for battery cell 1(switch) to cell 13 with an interval of 15 seconds. So when Cell 1 is measured it will go to this Sample/Hold script.....and so on until to cell 13. Now I can use 13 voltage indicators in Domoticz with the actual value.
Robin